The basic problem is that "survfit" is using deparse() to try to get the name of the Surv() object so it can generate an R formula. Unfortunately, this object doesn't have a name in R's namespace, so deparse() gets the structure representation instead of the name, and then things fail.

As a consequence, this is one of the cases when you need to explicitly place your objects into R's own namespace, and then ask R's own parser to work on the command string. This code shows how to accomplish this:


from rpy import *
r.library("survival")
set_default_mode(NO_CONVERSION)
d=r.rep(1,41)
t=r.c( r.rep(6,5), r.rep(9,3) , r.rep(12,24), r.rep(15,9) )

## Put the 't' and 'd' objects into R's namespace
r.assign("t",t)
r.assign("d",d)

## Use R's interpreter to execute the necessary code
sf = r("survfit(Surv(t,d))")

## Now we can examine the resulting object:
r.print_(sf)

## or display it
r.plot(sf)


I hope this helps,

-Greg


On Feb 27, 2008, at 6:07AM , Lore Merdrignac wrote:

Thanks for answering.
I had already tested to split the expression but there is still a problem with the function survfit(). Nevertheless this expression works with R, but I have to implement it with python. Indeed, I am trying to create a software for survival analysis using python language...

>>> s=r.Surv(t,d)
>>> ss=r.survfit(s)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
RPy_RException: Erreur dans parse(text = paste(deparse(call[[2]]), 1, sep = "~")) :
  unexpected numeric constant dans :
"structure(c(6L, 6L, 6L, 6L, 6L, 9L, 9L, 9L, 12L, 12L, 12L, 12L, ~1
12L"

and obviously, I get then :

>>> survPlot = r.get("plot.survfit", envir=r.getNamespace("survival"))
>>> survPlot(sf)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
NameError: name 'sf' is not defined

Lore.

> Date: Wed, 27 Feb 2008 11:48:12 +0100
> From: [EMAIL PROTECTED]
> To: rpy-list@lists.sourceforge.net
> Subject: Re: [Rpy] package : survival
>
> 2008/2/27, Lore Merdrignac <[EMAIL PROTECTED]>:
> >
> > Hi,
> > I have already posted a first problem of "NO_CONVERSION" with the package > > SURVIVAL. But I still have a problem by using the function survfit() of the
> > package.
> > Here is the code :
> >
> > >>> from rpy import *
> > >>> r.library("survival")
> > >>> set_default_mode(NO_CONVERSION)
> > >>> d=r.rep(1,41)
> > >>> t=r.c( r.rep(6,5), r.rep(9,3) , r.rep(12,24), r.rep(15,9) )
> > >>> r.plot(r.survfit(r.Surv(t,d)))
> > Traceback (most recent call last):
> > File "<interactive input>", line 1, in ?
> > RPy_RException: Erreur dans parse(text = paste(deparse(call [[2]]), 1, sep =
> > "~")) :
> > unexpected numeric constant dans :
> > "structure(c(6L, 6L, 6L, 6L, 6L, 9L, 9L, 9L, 12L, 12L, 12L, 12L, ~1
> > 12L"
> >
> > Is there anything I am doing wrong ? I really need this function to > > complete my survival analysis... I would really appreciate if anyone could
> > help me.
>
> I guess that an emergency solution is to be doing the whole analysis in R.
>
> Otherwise, you could try splitting up a bit your expression
> r.plot(r.survfit(r.Surv(t,d)))
> to see better were things are going wrong:
> s = r.Surv(t,d)
> sf = r.survfit(s)
> plot(sf)
>
> The following has a chance to work (not tested):
> survPlot = r.get("plot.survfit", envir=r.getNamespace("survival"))
> survPlot(sf)
>
>
> L.
>
> PS: An alternative to the NO_CONVERSION business might be coming in not-so-long.
>
>
> > Thanks.
> >
> > Lore.
> >
> > ________________________________
> > Windows Live Messenger 2008 vient de sortir, découvrez son nouveau design !
> > Téléchargez gratuitement Messenger 2008
> > ---------------------------------------------------------------------- ---
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > _______________________________________________
> > rpy-list mailing list
> > rpy-list@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/rpy-list
> >
> >
>
> ---------------------------------------------------------------------- ---
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list


Windows Live Messenger 2008 vient de sortir, entièrement personnalisable ! Téléchargez gratuitement Messenger 2008 ---------------------------------------------------------------------- ---
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/<mime- attachment.txt>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to