[R] write.foreign, SPSS on Mac OS X
jnikelski at alumni.uwaterloo.ca
Wed Jul 13 17:47:09 CEST 2005
Thanks for your help Brian. You are correct in assuming that I am
trying to use write.foreign to export a data frame for use in SPSS,
using the usual format:
>write.foreign(df, dataFile, codeFile, package="SPSS")
Your suggestion that the unprintable characters represent UTF-8 encoded
Unicode left and right double quotes also appears correct. Now, although
the suggested work-around may well help, the foreign package does seem
to be creating a corrupted file. That is, an entirely 8-bit ASCII file
containing embedded UTF-8 double quotes is not valid by any standard --
and is thus unreadable by any editor on any platform. Perhaps I should
look into filing a bug report on this to the foreign package maintainer.
Prof Brian Ripley wrote:
> On Tue, 12 Jul 2005, EJ Nikelski wrote:
>> I have jut installed the foreign package (v 0.8-8) on my OS X
>> machine, and have a bit of a problem writing out a data frame in SPSS
>> format. Specifically, the code file (the .sps format file) seems to
>> write 3 unprintable hex values instead of double quotes. For example, in
>> the following output ...
>> VALUE LABELS
>> 1 ###1###
>> 2 ###2###
>> 3 ###3###
>> ... emacs tells me that the left-sided ### are the hex codes E2 80 9C,
>> on the right we have E2 80 9D. I am supposing that I should be seeing
>> double-quotes here? Interestingly, the data file, which also contains a
>> quoted field, writes out the quotes without any problem. Does anyone
>> have any ideas?
> An idea. Those are left and right double quotes in UTF-8 and since MacOS X
> is usually in a UTF-8 locale they should be printable. However, I
> suspect that SPSS is expecting ASCII double quotation marks.
> You haven't told us what you did, but I guess you used
> write.foreign(package="SPSS"). That calls writeForeignSPSS which
> contains calls to dQuote(), and the latter are wrong if ASCII quotation
> marks are needed.
> A quick workaround is to use a non-UTF-8 locale: how you do that on ypur
> OS depends on how you run R so please ask advice on the R-sig-mac list.
More information about the R-help