On Mon, 2009-06-15 at 17:22 +0100, Peter wrote:
> On Mon, Jun 15, 2009 at 4:47 PM, Laurent Gautier<lgaut...@gmail.com> wrote:
> >
> > What is already not working in an R session has somewhat limited chances
> > of working with rpy2.
> >
> >> library(MASS)
> >> attach("birthwt")
> > Error in attach("birthwt") : file 'birthwt' not found
> >
> > The R function attach() is working on symbols, not on strings.
> >
> >> attach(get("birthwt"))
> > works, and so would in rpy2
> >
> > r.attach(r["birthwt"])
> > #note: detaching that one is left as an exercise for the reader.
> >
> > L.
> 
> That does help clarify things. In R these appear to be equivalent (the
> first using a string, the second a symbol):
> attach(get("birthwt"))
> attach(birthwt)

Although they are not identical.
(compare the output of search() ).

> Likewise for the library function, you can do either (string or symbol):
> library("MASS")
> library(MASS)

And so does data() for example.

Behind the hood, such functions do something like:

foo <- function(object_name) {
  object_name <- as.character(substitute(object_name))
  ...blahblahblah
}

> So in rpy (or rpy2), we can call the library function with a string
> because R understands that. But, for attach, R does not expect a
> string, just a symbol, hence the failure. I think I have learnt a
> little more about R today :)

There are packages relying heavily on symbols, so making a helper
function can sometimes help overcoming issues.
One example is in the documentation for the development version:
http://rpy.sourceforge.net/rpy2/doc-dev/html/graphics.html#id2
(note: don't stay stuck on to those graphics examples, there is more and
better coming up soon ;-) ).


L.



> Thank you,
> 
> Peter


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to