Skip to content

Managing Data

7 messages · Magill, Brett, Frank E Harrell Jr, Göran Broström +2 more

#
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
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:

            

  
    
#
I am experimenting with 'termplot':
works as advertised, but when I try to use 'terms', I don't get what I 
want:
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
#
I find the following behaviour slightly disturbing:
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 <gb at stat.umu.se> writes:
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:

            

  
    
#
On Mon, Feb 11, 2002 at 02:08:29PM +0100, G?ran Brostr?m wrote:
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