[R] Scoping rules in R
Nicholas Lewin-Koh
kohnicho at comp.nus.edu.sg
Thu Mar 21 09:44:11 CET 2002
Hi,
Thanks for the quick reply,
In the function st.obj is a survival tree object (my own, not rpart). z is
the original data. The first part just gets a vector of node assignments
from the st.obj. The second part where the trouble is, is looping through
the terminal nodes fitting a coxmodel for each node on the data subset,
the correct formula for the node is retrieved from st.obj, and that and
subsetting z seem to be where the scoping problem is.
I hope this is clearer.
Thanks
Nicholas
On Thu, 21 Mar 2002 ripley at stats.ox.ac.uk wrote:
> Could you tell us what you are trying to achieve here? It looks to me as
> if update() would do this sort of thing much more transparently. Since
> tst() could be called from inside a function, you don't want to flout the
> normal scope rules without a very good reason.
>
> On Thu, 21 Mar 2002, Nicholas Lewin-Koh wrote:
>
> > Hi,
> > The following is a small test function that is part of a larger piece of
> > code. If I understand things correctly both z and st.obj$call need to be
> > looked for in .GlobalEnv . How do I write this so it works? And which part
> > of the documentation should I be reading to get a more in depth
> > explanation?
> >
> > Thanks
> > Nicholas
> >
> >
> > tst<- function(st.obj,z){
> > G<-unique(st.obj$mem[,st.obj$depth])
> > Gr<-st.obj$mem[,st.obj$depth]
> >
> > cphlst<-list()
> >
> > for(i in G){
> > assign("form",deparse(substitute(st.obj$cph.call)),env=.GlobalEnv)
> > dat<-z[Gr==i,]
> > call<-paste("coxph(",form ,",data= ",dat,")")
> > cphlst[[j]]<-eval(parse(text=call), sys.parent())
> > }
> > cphlst
> > }
> >
> > CH3
> > |
> > N Nicholas Lewin-Koh
> > / \ Dept of Statistics
> > N----C C==O Program in Ecology and Evolutionary Biology
> > || || | Iowa State University
> > || || | Ames, IA 50011
> > CH C N--CH3 http://www.public.iastate.edu/~nlewin
> > \ / \ / nlewin at iastate.edu
> > N C
> > | || Currently
> > CH3 O Graphics Lab
> > School of Computing
> > National University of Singapore
> > The Real Part of Coffee kohnicho at comp.nus.edu.sg
> >
> >
> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> > Send "info", "help", or "[un]subscribe"
> > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> >
>
> --
> Brian D. Ripley, ripley at stats.ox.ac.uk
> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel: +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272860 (secr)
> Oxford OX1 3TG, UK Fax: +44 1865 272595
>
>
CH3
|
N Nicholas Lewin-Koh
/ \ Dept of Statistics
N----C C==O Program in Ecology and Evolutionary Biology
|| || | Iowa State University
|| || | Ames, IA 50011
CH C N--CH3 http://www.public.iastate.edu/~nlewin
\ / \ / nlewin at iastate.edu
N C
| || Currently
CH3 O Graphics Lab
School of Computing
National University of Singapore
The Real Part of Coffee kohnicho at comp.nus.edu.sg
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list