tags:

views:

78

answers:

1

Sometimes it would be useful to name variables like no programmer should name his or her variables. Of course there's some good reason for conventions and limitations on stoopid variable names, but still I'd be nice. Particularly in a language like R that is used frequently to create graphs and some labels with the graphs. Thus, some labels contain variable names.

Is there a way to use something like a+b as a variable name in R? Or is there something like a display name? For example in faceting with ggplot2 such an option would be great.

p_big + facet_grid(x ~ y,scales="free") +labs(x="",y="")

# with x containing a+b, d&c 

thx for any ideas in advance!

+7  A: 

You can use backticks:

R> `a + b` <- 3
R> `a + b`
[1] 3

tmp <- data.frame(1:10, rnorm(10))
names(tmp) <- c("a+b", "c&d")
ggplot(tmp, aes(`a+b`, `c&d`)) + geom_point()

See also ?Quotes.

rcs
Thx a bunch. It's simply hilarious how much little (and big) things I learn everyday @ SO.
ran2