[R] RPy and the evil underscore

Tim Churches tchur at optushome.com.au
Sun Feb 25 22:47:58 CET 2007


Alberto Vieira Ferreira Monteiro wrote:
> I seems like I will join two threads :-)

Please address RPy-specific questions to the Rpy mailing list, where
they will be answered swiftly and without annoyance to everyone else on
this general r-help mailing list.

> Ok, RPy was installed (in Fedora Core 4, yum -y install rpy), and it 
> is running. However, I have a doubt, and the (meagre) documentation
> doesn't seem to address it.
>
> In python, when I do this:
> 
>>>> import rpy
>>>> rpy.r.setwd("/mypath")
>>>> rpy.r.source("myfile.r")
> 
> Everything happens as expected. But now, there's
> a problem if I try to use a function in myfile:
> 
>>>> x = my_function(1)
>>>> x = r.my_function(1)
>>>> x = rpy.my_function(1)
>>>> x = rpy.r.my_function(1)
> 
> None of them work: the problem is that the _ is mistreated.
> If the function has "." instead of "_", it works:
> 
>>>> x = rpy.r.my_function(1)
> 
> This is weird: I must write the R soutine with a ".", but then
> rpy translates it to "_"!

Object identifiers cannot begin with an underscore in R, but they can in
Python. To avoid having to confusingly special-case this difference, the
RPy designers elected to translate underscores in Python object names to
dots in R object names.

All this is clearly documented in the RPy manual at
http://rpy.sourceforge.net/rpy/doc/rpy_html/R-objects-look-up.html#R-objects-look-up

Tim C



More information about the R-help mailing list