From David James <dj@research.bell-labs.com>  Wed Apr 25 14:37:19 2001
From: David James <dj@research.bell-labs.com> (David James)
Date: Wed, 25 Apr 2001 09:37:19 -0400 (EDT)
Subject: [Rd] assigning objects from .C/.Call
Message-ID: <200104251337.JAA14493@jessie.research.bell-labs.com>

Hi,

On Tue, 24 Apr 2001, Prof Brian D Ripley wrote:

> Date: Tue, 24 Apr 2001 20:24:35 +0100 (BST)
> From: 
> To: David James <dj@research.bell-labs.com>
> cc: <r-devel@stat.math.ethz.ch>
> Subject: Re: [Rd] assigning objects from .C/.Call
> MIME-Version: 1.0
> 
> On Tue, 24 Apr 2001, David James wrote:
> 
> >
> > Hi,
> >
> > In section 4.6.7 of "Writing R Extensions" (Version 1.2.1, 2001-01-15)
> > the C function defineVar() is described as  "... the equivalent
> > of assign(symbol, value, envir = rho, inherits = FALSE) ..."
> >
> > I interpreted the above (wrongly) as meaning that defineVar() makes
> > a copy of its "value" argument into the object whose name is specified
> > in "symbol" in the "rho" environment (that's how assign() works at the
> > R/S level).  However, this is not exactly how defineVar() appears to work.
> > In particular, it appears to assign the object in the environment "rho",
> > but further changes in the C code to the object are reflected in the
> > "assigned" object in rho (i.e., no actual copy of the object is made).
> >
> > I can see that the implemented behavior is quite useful, but it's not
> > exactly equivalent to assign().  Perhaps the documentation should be more
> > explicit and add a sentence to warn users that the data part of the
> > object is shared? (The sentence may need to be more precise, though.)
> 
> I'm happy to do so, but can someone provide the more precise sentence,
> please.  When exactly does R make a copy?

Using Peter Delgaard's suggestion (and John Chambers', privately)
I suggest the following modified paragraph (edited from R-exts.texi):


@code{defineVar}
creates a new binding or changes the value of an existing binding in the
specified environment frame; in this respect, it is analogous to
@code{assign(symbol, value, envir = rho, inherits = FALSE)},
but unlike \code{assign}, @code{defineVar} does not make a
copy of the object (you can assign a copy of the object in the
environment frame @code{rho} using
@code{defineVar(symbol, duplicate(value), rho)}).



> 
> 
> -- 
> Brian D. Ripley,                  ripley@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
> 
> 
-------------------------------------------------------------------
David A. James
Statistics Research, Room 2C-253            Phone:  (908) 582-3082       
Bell Labs, Lucent Technologies              Fax:    (908) 582-3340
Murray Hill, NJ 09794-0636

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] assigning objects from .C/.Call
David James