[R] Quoting underscores in variable names

Prof Brian D Ripley ripley at stats.ox.ac.uk
Fri Sep 21 08:06:37 CEST 2001

On 21 Sep 2001, Edward C. Lang wrote:

> (please Cc: me in replies, as I am not on the r-help list)
> Hi,
> I have discovered that underscores are not allowed in variable names,
> although this is not by any means the first instance of such a
> discovery. Short of going through all my other data, and removing
> underscores, is it possible to quote underscores in R? I had something like:
> > plot(g\_code ~ sp\_code, data=genes)
> Error: syntax error

Quoting is by "" in S/R.  But how did you get the names there in the first
place?  data.frame and read.table (for example) check for valid names and
change them (by using a `.').

> genes <- data.frame("g_code"=1:10, "sp_code"=1:10, check.names=F)
> plot("g_code" ~ "sp_code", data=genes)

shows that quoting is not being supported in handling formulae.
(It failed in S as well, at a different point.)

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

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