[R] no _?

John Fox jfox at mcmaster.ca
Sat Dec 8 14:57:45 CET 2001


Dear Jeff,

At 09:53 PM 12/7/2001 -0800, Jeff D. Hamann wrote:
>I see the uderscore "_" is not allowed in R. This make R a real drag when
>trying to use with SQL packages and c code. Why is the underscore not
>allowed and will it be allowed in a future release?

As has been pointed out, the underscore is used as a synonym for the 
assignment operator, <-, but non-standard names, including names containing 
underscores, can be used -- if this is really necessary -- by quoting them. 
For example:

         > "x_1" <- 1:5
         > eval(as.name("x_1"))
         [1] 1 2 3 4 5

If you're receiving the offending variable names from another application, 
an alternative is to edit the names, as in

         > gsub("_", ".", c("x_1", "x_2"))
         [1] "x.1" "x.2"
         >

I hope that this helps,
  John


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

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list