Hello everyone, Can someone point me to some resources on managing data in R and/or S-plus? I have started using R more and more often in my work and I really like it. But, managing data is very different in R and S-Plus than in other packages that I am accustomed to. I know that it is an option to use different workspaces for different projects or to store all objects as source and read them in each session. I am looking for an overview of these data management options and tips / suggestions for handling multiple R projects efficiently. I have learned a lot through trial and error, but I am sure there are some better options. I want to avoid doing silly things like overwriting a local object by running a piece of example code that happens to have the same variable name! I looked in R-intro, but the information there is pretty basic. Any ideas? Thanks, Brett Magill magillb at usa.redcross.org Research and Program Development Health, Safety, and Community Services American National Red Cross -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Managing Data
7 messages · Magill, Brett, Frank E Harrell Jr, Göran Broström +2 more
See the section "Operating in S" in http://hesweb1.med.virginia.edu/biostat/s/doc/splus.pdf Frank Harrell On Fri, 8 Feb 2002 11:42:52 -0500
"Magill, Brett" <MagillB at usa.redcross.org> wrote:
Hello everyone, Can someone point me to some resources on managing data in R and/or S-plus? I have started using R more and more often in my work and I really like it. But, managing data is very different in R and S-Plus than in other packages that I am accustomed to. I know that it is an option to use different workspaces for different projects or to store all objects as source and read them in each session. I am looking for an overview of these data management options and tips / suggestions for handling multiple R projects efficiently. I have learned a lot through trial and error, but I am sure there are some better options. I want to avoid doing silly things like overwriting a local object by running a piece of example code that happens to have the same variable name! I looked in R-intro, but the information there is pretty basic. Any ideas? Thanks, Brett Magill magillb at usa.redcross.org Research and Program Development Health, Safety, and Community Services American National Red Cross -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Frank E Harrell Jr Prof. of Biostatistics & Statistics Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I am experimenting with 'termplot':
fit1 = coxph(Surv(time, status) ~ ns(bili, 4) + ns(age, 4), data = pbc) termplot(fit1, data = pbc)
works as advertised, but when I try to use 'terms', I don't get what I want:
termplot(fit1, data = pbc, terms = 2)
presents me with a '?' (because in termplot, in the line 'cn <- parse(text = nmt', nmt is NULL). So, I suppose that I am specifying 'terms' in a way that termplot doesn't like. How should it be done? Thanks, G?ran
G?ran Brostr?m tel: +46 90 786 5223 professor fax: +46 90 786 6614 Department of Statistics http://www.stat.umu.se/egna/gb/ Ume? University SE-90187 Ume?, Sweden e-mail: gb at stat.umu.se -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I find the following behaviour slightly disturbing:
x = 6 ex = function(x = x) x ex()
Error in ex() : recursive default argument reference Can't R distinguish between formal and actual arguments? (Just kidding!) Seriously, what bad things could happen if I was allowed to get the answer 6 here? G?ran
G?ran Brostr?m tel: +46 90 786 5223 professor fax: +46 90 786 6614 Department of Statistics http://www.stat.umu.se/egna/gb/ Ume? University SE-90187 Ume?, Sweden e-mail: gb at stat.umu.se -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
G?ran Brostr?m <gb at stat.umu.se> writes:
I find the following behaviour slightly disturbing:
x = 6 ex = function(x = x) x ex()
Error in ex() : recursive default argument reference Can't R distinguish between formal and actual arguments? (Just kidding!) Seriously, what bad things could happen if I was allowed to get the answer 6 here?
You would lose lazy evaluation. The default value of an argument is evaluated at the time that the argument is first accessed during function evaluation, not at the time of definition of the function. That allows you to define default values of arguments in terms of other values calculated within the function. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
1 day later
Thanks to Doug Bates and Ray Brownrigg, who both referred to 'lazy evaluation' as an argument for not allowing my construct. However, I'm not completely convinced. As I understand it, when a variable pops up (on the 'right hand side') in an expression in a function, R looks for it in the following order: 1. Local (to the function) variable? 2. Formal argument? 3. In the defining environment? The potential problem occurs when the answer to 1. is 'No' and the answer to 2. is 'Yes', and no value was given to x in the call. Then the current procedure obviously is to look at the default, and go thru steps 1.-3. again to find it. (Am I correct?) Then x=x is found, and the 'recursive default ...' is detected. But I mean that when looking for the default among the formal arguments, *the current one must be excluded*, and the search continue to 3., if necessary. What have I overlooked? G?ran
On 9 Feb 2002, Douglas Bates wrote:
G?ran Brostr?m <gb at stat.umu.se> writes:
I find the following behaviour slightly disturbing:
x = 6 ex = function(x = x) x ex()
Error in ex() : recursive default argument reference Can't R distinguish between formal and actual arguments? (Just kidding!) Seriously, what bad things could happen if I was allowed to get the answer 6 here?
You would lose lazy evaluation. The default value of an argument is evaluated at the time that the argument is first accessed during function evaluation, not at the time of definition of the function. That allows you to define default values of arguments in terms of other values calculated within the function. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
G?ran Brostr?m tel: +46 90 786 5223 professor fax: +46 90 786 6614 Department of Statistics http://www.stat.umu.se/egna/gb/ Ume? University SE-90187 Ume?, Sweden e-mail: gb at stat.umu.se -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, Feb 11, 2002 at 02:08:29PM +0100, G?ran Brostr?m wrote:
Thanks to Doug Bates and Ray Brownrigg, who both referred to 'lazy evaluation' as an argument for not allowing my construct. However, I'm not completely convinced. As I understand it, when a variable pops up (on the 'right hand side') in an expression in a function, R looks for it in the following order: 1. Local (to the function) variable? 2. Formal argument? 3. In the defining environment? The potential problem occurs when the answer to 1. is 'No' and the answer to 2. is 'Yes', and no value was given to x in the call. Then the current procedure obviously is to look at the default, and go thru steps 1.-3. again to find it. (Am I correct?) Then x=x is found, and the 'recursive default ...' is detected. But I mean that when looking for the default among the formal arguments, *the current one must be excluded*, and the search continue to 3., if necessary. What have I overlooked? G?ran
A call establishes only a local frame with the defining environment as
its parent. At the start of a call all formal arguments are given
bindings to deferred evaluations, either of the supplied argument
where the deferred evaluation will use the caller's environment, or of
default expressions that will be evaluated in the local environment.
When the value of a variable is requested its binding is looked up in
the environment and a deferred evaluation is carried out if necessary.
If the deferred evaluation needs its value to find its value, you get
an error. [This is simplified a bit but should capture the essence.]
For your example
ex = function(x = x) x
the evaluation of the call ex() is roughly equivalent to
env <- new.env(parent = environment(ex)) # create the call frame
assign("x", delay(x, env), env) # insert binding for
# x with deferred evaluation of
# the default expression
eval(body(ex), env) # evaluate the body in the new env
If you paste this into R you get the same error as when evaluating ex().
Hope that helps.
luke
Luke Tierney University of Minnesota Phone: 612-625-7843 School of Statistics Fax: 612-624-8868 313 Ford Hall, 224 Church St. S.E. email: luke at stat.umn.edu Minneapolis, MN 55455 USA WWW: http://www.stat.umn.edu -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._