[R] Scoping

Goran Brostrom gb at stat.umu.se
Fri Nov 20 18:30:55 CET 1998


I must admit that I don't fully appreciate the scoping rules in R.
For instance:

myfunc <-function(tt, event, x)
   {
     cat(tt, "\n")
     coxph(Surv(tt, event) ~ x)
   }

Running

R> myfunc(c(1:4), rep(1, 4), c(1,0,1,0))

gives as output:

1 2 3 4 
Error: Object "tt" not found

i.e., cat  "sees"  tt, but not  coxph. Why?
How do I call coxph within a function, with arguments
being local or formal parameters? Is it possible to write
R  functions so that the scopning rules will be as in Fortran
or C?

Göran Broström

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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