Could someone explain the thinking behind the backtick notation in r-devel? I think I understand that it can be used to refer to variable names which would otherwise not conform to R syntax; however, assign and as.name already allow you to do this. Is there more to it than that? Is backtick notation supposed to be analogous to backticks in the UNIX shell, the $ sign in perl or some feature in lisp/scheme?
On Thu, 7 Aug 2003, Gabor Grothendieck wrote:> > Could someone explain the thinking behind the backtick notation in > r-devel? > > I think I understand that it can be used to refer to variable names > which would otherwise not conform to R syntax; however, assign and > as.name already allow you to do this. Is there more to it than that?assign and as.name are fairly limited. For example, if you have a list or data frame whose name is syntactically invalid it is quite difficult to access or modify its columns. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlumley@u.washington.edu University of Washington, Seattle
> > assign and as.name are fairly limited. For example, if you have a list or > > data frame whose name is syntactically invalid it is quite difficult to > > access or modify its columns. > > Yes. `weight in kg`[101]<-55 is pretty difficult to do with get() and > assign() and lm(`weight in kg`~I(`height in m`^2)) is tricky too. The > use is sort of similar to the single quotes in shell programming (but > not quite). The choice of the backtick as quoting delimiter was mostly > because that was the only one available....Good point about the difficulty of using assign and get. This leads to additional questions: - is it desirable to make it easy to work with non-synactic names? - if the previous point is yes, then is this use sufficiently important to warrant a new syntactic element, viz. backquote? For example, extending perhaps as.name could be extended so that it can be used on the left hand side of an assignment like this: as.name("height in m2")^2 or as.name("weight in kg")[101]<-55 - how far can this feature be pushed? For example, backtick quoted names might be usable in string literals as in perl: print("variable x is `x` and variable y is `y`") or download.file("http://www.xyz.com?a=`a`&b=`b`") I am not sure what the answers to these questions should be but in order to combat excessive growth of the syntax a new syntax addition usually is made to climb a higher barrier than a feature which does not.