From uhkeller at web.de  Thu Jun  1 13:18:40 2006
From: uhkeller at web.de (uhkeller at web.de)
Date: Thu,  1 Jun 2006 13:18:40 +0200 (CEST)
Subject: [Rd] write.foreign creates incorrect SPSS syntax files when
	dataframe contains character variables (PR#8926)
Message-ID: <20060601111840.C86E81E71F@slim.kubism.ku.dk>

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)).



[Rd] write.foreign creates incorrect SPSS syntax files when dataframe contains character variables (PR#8926)
uhkeller at web.de