Skip to content
Prev 318592 / 398503 Next

Dealing with parentheses within variable names

On 13-03-01 12:57 PM, Duncan Murdoch wrote:
After taking a closer look, I realized that it is actually behaving as 
designed.  The first input to reformulate is supposed to be a character 
vector, not bits of R language.  For example, we want

reformulate("x*w")

to return

~ x*w

not

~ `x*w`

So you might think your example should have been entered as

reformulate(c("`P/E`", "`% Growth`"), response="`+-`")

However, this doesn't quite work:  it ends up with response having 
double backticks.  The way to get what you want is to use

reformulate(c("`P/E`", "`% Growth`"), response=as.name("+-"))

Definitely not my favourite design for a function, but I think it's not 
a code issue.  Maybe something should be added to the help page, but 
this is such an obscure issue that I'm not sure I could make things clearer.

Duncan Murdoch