Skip to content

Update today broke foreign package (PR#13533)

4 messages · rubin at msu.edu, Brian Ripley, HBaize +1 more

#
Hi,

I'm running R 2.8.1 on Ubuntu, and today I got updates for a couple of 
packages, including foreign (r-cran-foreign, now at version 0.8.32).  
Subsequent to the upgrade, attempts to invoke read.spss produce the 
following error:

Error in inherits(x, "factor") : object "cp" not found

and the call to read.spss fails.  I forced a downgrade to 0.8.26, and 
read.spss works again.

Cheers,
Paul Rubin
#
foregin_0.8-32 was testsd aginst 2.8.1 prior to release, and I've just 
tested it again.

This might be a locale issue (but I also tested in a latin1 and C 
locale), but I think it is specific to some files.

So can we have both the output of sessionInfo() and a file that 
causes the problem (it appears not to be one of the test files in the 
'tests' subdirectory), and I'll investigate further.
On Mon, 16 Feb 2009, rubin at msu.edu wrote:

            

  
    
#
I posted links to five SPSS .sav files in response to a very similar problem
with read.spss(). 
Maybe you can use them to test the function. 

http://www.nabble.com/reading-SPSS-.sav-files-(PR-13509)-td21889920.html 

So can we have both the output of sessionInfo() and a file that 
causes the problem (it appears not to be one of the test files in the 
'tests' subdirectory), and I'll investigate further.
On Mon, 16 Feb 2009, rubin at msu.edu wrote:

  
    
#
Prof Brian Ripley wrote:
I have this with a codepage 1252 file as well. From my reply to Harry
Haupt on R-help (copied here for the sake of the bug repository):

Yes, something in the logic appears to have gotten garbled.

It's in this part of read,spss:

    if (is.character(reencode)) {
        cp <- reencode
        reencode <- TRUE
    }
    else if (codepage <= 500 || codepage >= 2000) {
        attr(rval, "codepage") <- NULL
        reencode <- FALSE
    }
    else if (m <- match(cp, knownCP, 0L))
        cp <- names(knownCP)[m]

if you get to the 2nd "else if" then cp is unset. Possible the attempted
match should be of codepage? But it still looks wrong: Why restrict to
codepages between 500 and 2000 when knownCP contains several values
above 10000???

A workaround is to set reencode="ascii" (or whatever is relevant).