[R] read.spss and encodings

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Thu Feb 1 14:59:51 CET 2007


On Thursday 01 February 2007 14:18, Peter Dalgaard wrote:
> so you should convert it:
> > iconv("Im B\xfcro", from="latin1", to="UTF-8")
>
> [1] "Im Büro"
>
> > iconv("Im B\374ro",from="latin1", to="UTF-8")
>
> [1] "Im Büro"

I see. Thanks!

Any chances of adding something like this to read.spss()?
read.spss <- function([...], encoding=NULL) {
	[...]
	if (!is.null(encoding)) {
		iconv.recursive <- function(x, from) {
			attribs <- attributes(x);
			if (is.character(x)) {
				x <- iconv(x, from=from, to="", sub="")
			} else if (is.list(x)) {
				x <- lapply(x, function(sub) iconv.recursive(sub, from))
			}
			# convert factor levels and all other attributes
			attributes(x) <- lapply(attribs, function(sub) iconv.recursive(sub, from))
			x
		}

		convert.recursive(rval, from=encoding)
	} else {
		rval
	}
}

Now that I've written this iconv.recursive() function once, I'm fine. But I 
guess something like this might be useful to others as well.

Regards
Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : https://stat.ethz.ch/pipermail/r-help/attachments/20070201/f7fb10f4/attachment.bin 


More information about the R-help mailing list