Error Reading Portable-file Dictionary
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business memisc Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs
Unrecognized Record Type 7, Subtype 18 Encountered In System File
Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up R read.spss error importing SPSS .por file - “Bad character in time” up vote 7 down vote favorite I'm trying to import the NYPD stop-and-frisk data into R. The data is in SPSS .por files at http://www.nyc.gov/html/nypd/downloads/zip/analysis_and_planning/YYYY.zip where YYYY is a year from 2003 to 2012 Most of the files load fine, but the 2004, 2007, and 2008 files all give me this error: > library(foreign) > mydata= read.spss("2004.por", to.data.frame=TRUE) Error in read.spss("2004.por", to.data.frame = TRUE) : error reading portable-file dictionary In addition: Warning message: In read.spss("2004.por", to.data.frame = TRUE) : Bad character in time Execution halted Any suggestions on how to debug this? I realize that read.spss does not support the latest SPSS versions, but given that most of the files (7 out of 10) import properly I wonder whether it's something more subtle. psppire loads all the files without complaint, but the data looks corrupted, with some fields seemingly combined with others, and binary data in some of the fields. r share|improve this question asked Dec 20 '13 at 6:24 Captain Pedantic 1,361154 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote I had some success using memisc as recommended in Read SPSS file into R. Namely, after installing memisc: > install.packages('memisc') You can read the data rather easily: > library(memisc) > data <- as.data.set(spss.portable.file('2004.por')) While I haven't thoroughly inspected the data, it appears on first glance to be right. share|improve this answer answered Feb 18 '14 at 5:18 icktoofay 83.4k9150181 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged r or ask your own question.
Sign in Pricing Blog Support Search GitHub This repository Watch 23 Star 176 Fork 45 tidyverse/haven Code Issues 6 Pull requests 1 Projects 0 Pulse Graphs New issue Error when importing .por datafile (read.spss works) #35 Closed jlegewie opened this Issue Mar 4, 2015 · 14 comments Projects None yet Labels None yet Milestone No milestone Assignees No one assigned 3 participants jlegewie commented Mar 4, 2015 I am http://stackoverflow.com/questions/20697560/r-read-spss-error-importing-spss-por-file-bad-character-in-time getting this error when I try to open a SPSS por file: Error in df_parse_por(clean_path(path)) : attempt to set index 0/0 in SET_STRING_ELT Below is code that downloads the file. It works with read.spss. library("haven") library("foreign") # download and unzip file to temporary folder url <- "http://www.nyc.gov/html/nypd/downloads/zip/analysis_and_planning/2006_sqf.zip" p1 <- file.path(tempdir(), basename(url)) download.file(url, p1, quiet https://github.com/hadley/haven/issues/35 = TRUE) filename <- unzip(p1, list = TRUE)$Name[1] unzip(p1, files = filename, exdir = tempdir()) # open file p2 <- file.path(tempdir(), filename) DF <- read_por(p2) # Error in df_parse_por(clean_path(path)) : # attempt to set index 0/0 in SET_STRING_ELT DF <- foreign::read.spss(p2, use.value.labels = FALSE, to.data.frame = TRUE) sessionInfo() R version 3.1.1 (2014-07-10) Platform: x86_64-apple-darwin13.4.0 (64-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] foreign_0.8-62 haven_0.1.1.9000 Defaults_1.1-1 loaded via a namespace (and not attached): [1] Rcpp_0.11.4 evanmiller commented Mar 5, 2015 @hadley this file imports OK using plain ReadStat so I assume the problem is in haven. jlegewie commented Mar 5, 2015 Here is a link to another file with the same error http://www.nyc.gov/html/nypd/downloads/zip/analysis_and_planning/2007_sqf.zip. For this file, read.spss also produces an error: error reading portable-file dictionary But memisc::spss.portable.file can read the file. spss.portable.file(p2) %>% as.data.set(stringsAsFactors = FALSE) %>% as.data.frame(stringsAsFactors = FALSE) Probably the same problem but I thought I post considering
[ author ] Jose Iparraguirre D'Elia wrote: > https://stat.ethz.ch/pipermail/r-help/2008-July/168098.html [snip] > >> Thanks Brian, >> >> The error https://bugs.r-project.org/bugzilla/show_bug.cgi?id=14248 message reads as follows: >> >> Error in read.spss("G:/Jose/Life and Times Survey/LT 2007/nilt07w1.por") : >> error reading portable-file dictionary >> > > So it looks like it is not a portable file, or at least one that read.spss error reading > knows about Actually, no. I noticed that it had "8bit ascii" characters inside so on a hunch I sent it through iconv and got a different error message > read.spss("xxx.por", use.value.labels=FALSE) Error in read.spss("xxx.por", use.value.labels = FALSE) : file 'xxx.por' is not in any supported SPSS format error reading portable-file So read.spss() recognizes the format of the original file alright, it's just that something in the file does not match the format that read.spss() expects. It reads at least one .por file, namely the one that ships with the source for the foreign package in the tests directory (pbc.por). It is not unlikely that it can be confused by character set encodings and CR/LF inside value labels, though. -- O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 Previous message: [R] Reading SPSS .por files Next message: [R] manipulate a matrix2 Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] More information about the R-help mailing list
read.spss? Summary: can you update/improve foreign's read.spss? Status: CLOSED NOT REPRODUCIBLE Alias: None Product: R Classification: Unclassified Component: Wishlist (show other bugs) Version: R 2.10.1 Hardware: ix86 (32-bit) Linux Importance: P5 normal Assignee: R-core URL: Depends on: Blocks: Reported: 2010-04-05 23:38 UTC by Paul Johnson Modified: 2010-05-10 18:19 UTC (History) CC List: 1 user (show) ripley See Also: Attachments Add an attachment (proposed patch, testcase, etc.) Note You need to log in before you can comment on or make changes to this bug. Description Paul Johnson 2010-04-05 23:38:56 UTC While using read.spss, I sometimes have import failures because the original document has some characters from unusual character sets. I recently emailed, Martin Elff