uhkeller at web.de
2006-Jun-01 11:18 UTC
[Rd] write.foreign creates incorrect SPSS syntax files when dataframe contains character variables (PR#8926)
Full_Name: Ulrich Keller Version: 2.3.0 Patched (2006-04-28 r37936) OS: Windows XP SP2 Submission from: (NULL) (158.64.77.43) write.foreign(x,...,package="SPSS") creates an incorrect SPSS syntax file when x contains character variables. SPSS expects character (string) variables to be defined in a special way in DATA LIST commands: * varname (A#) where # is the width of the variable. write.foreign ignores this. As a result, the contents of the character variables are not read into SPSS at all. For example: <CODE>> x<-data.frame(v1=1,v2=I("some text")) > library(foreign) > write.foreign(x,stdout(),stdout(),package="SPSS")1 "some text" DATA LIST FILE= "1" free / v1 v2 . VARIABLE LABELS v1 "v1" v2 "v2" . EXECUTE. </CODE> The variable definition following DATA LIST is: / v1 v2 . What it should be is: / v1 * v2 (A#) . where # is max(c(max(nchar(v2)), 255)).