[R] Functions starting with underscores

Philippe Grosjean phgrosjean at sciviews.org
Mon Jun 5 08:10:55 CEST 2006


It is not allowed to start a variable name with an underscore. So, you 
must use "`" to call this non-conventional name:

 > '_foo' <- function(x) 1
 > attr('_foo', 'bar') <- 'pow'
Error: target of assignment expands to non-language object
 > attr(`_foo`, 'bar') <- 'pow'
 > '_foo'
[1] "_foo"
 > `_foo`
function(x) 1
attr(,"bar")
[1] "pow"
 >

Best,

Philippe Grosjean


Joseph Wang wrote:
> I'm having problems with functions starting with underscores
> 
> '_foo' <- function(x) {1}
> 
> seems to work
> 
> but I can't assign an attribute to this function
> 
> attr('_foo', 'bar') <- 'pow'
> 
> Any way of doing this?  This is for a C++ -> R wrapping system so I'd like to 
> keep the C++ names which start with underscores.
> 
> (please cc: responses to me personally)
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 
>



More information about the R-help mailing list