From luke@nokomis.stat.umn.edu  Wed Apr 25 15:48:29 2001
From: luke@nokomis.stat.umn.edu (Luke Tierney)
Date: Wed, 25 Apr 2001 09:48:29 -0500
Subject: [Rd] assigning objects from .C/.Call
In-Reply-To: <x2ae55c3px.fsf@blueberry.kubism.ku.dk>; from p.dalgaard@biostat.ku.dk on Wed, Apr 25, 2001 at 12:50:18AM +0200
References: <Pine.GSO.4.31.0104242021450.16295-100000@auk.stats> <x2ae55c3px.fsf@blueberry.kubism.ku.dk>
Message-ID: <20010425094829.B5007@nokomis.stat.umn.edu>

On Wed, Apr 25, 2001 at 12:50:18AM +0200, Peter Dalgaard BSA wrote:
> Prof Brian D Ripley <ripley@stats.ox.ac.uk> writes:
> 
> > 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?
> 
> At C level, you'd need to duplicate(). In an assign() call,
> duplication takes place if the object is NAMED except if .Alias is
> used. ...I think.

As i understand it if the object is NAMED it is duplicated (.Alias I
think sete NAMED to 0 and to gets into the unnamed branch).  If NAMED
is zero, then defineVar is called and NAMED is set to 1.

We should probably think about making the public version of defineVar
take care of this, but maybe we should go a bit further and move the
responsability for maintaining the copying semantics into defineVar so
it is all in one place--there seem to be about 40 call sites and I'm
not sure they all get this right.

I'll make a note to look at this when I get back to the appropirate
part of the compiler, but if anyone else gets there first, that's
fine.

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@stat.umn.edu
Minneapolis, MN 55455 USA                    WWW:  http://www.stat.umn.edu
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
Luke Tierney