[R] line breaks in recode

John Fox jfox at mcmaster.ca
Tue Nov 4 13:34:10 CET 2003

Dear Bernd,

As Brian Ripley points out, the problem is that you can't break a quoted 
string over input lines.

It is nevertheless awkward that you have to provide the recode directives 
in one long line. I'll think about alternatives for the next version of the 
car package. One simple possibility would be to allow several strings, so 
that your example could be entered as

datameta$smpid.r <-recode(datameta$smpid,

It would also be nice to figure out a way to do this without using strings. 
The recode dialog in my Rcmdr package, which assembles a call to recode(), 
has a much nicer interface, but it's able to parse the input.

Thanks for the (implicit) suggestion.


At 11:52 AM 11/4/2003 +0100, Bernd Weiss wrote:
>Dear all,
>it seems to be that 'recode' can't handle any line breaks in its code.
>The following command causes no problem:
>datameta$smpid.r <-
>But if I type ...
>datameta$smpid.r <-recode(datameta$smpid,
>         "c(101,25,167,45,75)=25;
>              c(104,51)=51")
>... the result is a syntax error.

John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox

More information about the R-help mailing list