Martin.Schlather@uni-bayreuth.de
2002-Apr-04 12:36 UTC
[Rd] assign, documentation (PR#1434)
Hi, The help for `assign' says In all the assignment operator expressions, `x' can be a name or an expression defining a part of an object to be replaced (e.g., `z[[1]]'). The name does not need to be quoted, though it can be. So I would expect that by a<-1:4 assign("a[1]",2) the first component of a gets the value 2, but the object "a[1]" is created. Could this be clarified in the documentation? Cheers, Martin -- Martin Schlather email: Martin.Schlather@uni-bayreuth.de Abteilung Bodenphysik phone: +49 (0)921 55 2193 Univ. Bayreuth Fax : +49 (0)921 55 2246 D -- 95440 Bayreuth, Germany http://www.geo.uni-bayreuth.de/~martin/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, 4 Apr 2002 Martin.Schlather@uni-bayreuth.de wrote:> The help for `assign' says > > In all the assignment operator expressions, `x' can be a name or > an expression defining a part of an object to be replaced (e.g., > `z[[1]]'). The name does not need to be quoted, though it can be. > > So I would expect that by > a<-1:4 > assign("a[1]",2) > the first component of a gets the value 2, but the object "a[1]" is > created. > Could this be clarified in the documentation?Could you suggest how? You quoted an *expression*, and the page refers to quoting a *name*, so I don't know that I see the crux here. -- 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 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, Apr 04, 2002 at 05:37:18PM +0200, Peter Dalgaard BSA wrote:> ripley@stats.ox.ac.uk writes: > > > On Thu, 4 Apr 2002 Martin.Schlather@uni-bayreuth.de wrote: > > > > > The help for `assign' says > > > > > > In all the assignment operator expressions, `x' can be a name or > > > an expression defining a part of an object to be replaced (e.g., > > > `z[[1]]'). The name does not need to be quoted, though it can be. > > > > > > So I would expect that by > > > a<-1:4 > > > assign("a[1]",2) > > > the first component of a gets the value 2, but the object "a[1]" is > > > created. > > > Could this be clarified in the documentation? > > > > Could you suggest how? You quoted an *expression*, and the page refers to > > quoting a *name*, so I don't know that I see the crux here. > > Actually, it *is* a name that is getting quoted, it just has these weird > bracket characters in it, so it is not "syntactically valid". > > One improvement might be: "the name can be any string of text and may > be quoted, but this is only necessary if it is not a syntactically > valid name." >I think the original point was that he expected that a[1] would be changed not that a new variable named "a[1]" would be created. I don't think your suggestion will help with this. I think that Brian is correct, unless of course you want to spend some amount of time figuring out the logic/parsing requirements. "Assign treats the quoted string as a symbol, it does not parse it in any way", might help. On the otherhand, in some large number of years this is the first person who has had this problem, I'm not sure we should be documenting for less than 1% of the population unless of course, "we are trying to be as accurate as possible without regard to readability" :-), to quote the views of a certain member of R core on documentation.> We might also emphasize that "assignment operator expressions" does > not include assign(), only <-, <<-, and =. (And _ until we finally get > it killed...). On the other hand it is arguably clear enough already, > if read carefully. (For this reason alone, the posters remark is off > base, but he might have asked about "a[1]" <- 2.) > > In assign(), `x' must be a character object. As in > > > a <- "b" > > assign(a,2) > > a > [1] "b" > > b > [1] 2 > > > -- > O__ ---- Peter Dalgaard Blegdamsvej 3 > c/ /'_ --- Dept. of Biostatistics 2200 Cph. N > (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 > ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- +---------------------------------------------------------------------------+ | Robert Gentleman phone : (617) 632-5250 | | Associate Professor fax: (617) 632-2444 | | Department of Biostatistics office: M1B28 | Harvard School of Public Health email: rgentlem@jimmy.dfci.harvard.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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Robert Gentleman <rgentlem@jimmy.harvard.edu> writes:> > > > In all the assignment operator expressions, `x' can be a name or > > > > an expression defining a part of an object to be replaced (e.g., > > > > `z[[1]]'). The name does not need to be quoted, though it can be....> > One improvement might be: "the name can be any string of text and may > > be quoted, but this is only necessary if it is not a syntactically > > valid name." > > > I think the original point was that he expected that a[1] would be > changed not that a new variable named "a[1]" would be created. I > don't think your suggestion will help with this. I think that Brian > is correct, unless of course you want to spend some amount of time > figuring out the logic/parsing requirements. > > "Assign treats the quoted string as a symbol, it does not parse it in > any way", might help. On the otherhand, in some large number of > years this is the first person who has had this problem, I'm not > sure we should be documenting for less than 1% of the population > unless of course, > "we are trying to be as accurate as possible without regard to > readability" :-), to quote the views of a certain member of R core > on documentation.Moi? Only for certain kinds of documentation as you surely know. In other contexts I'd willingly go for reducing precision to improve overall clarity. But I do think accuracy is more important than anything else on help pages. It is the wrong context in which to try to be pedagogical. This really is the place to pick nits, and, e.g., the argument to assign is *not* a quoted string; it is a character vector whose first element becomes the name of the assigned object. The nit I was picking was in fact not relevant for the original question, but would be in the "a[1]" <- 2 case. The improvement is that there are cases where you *must* quote the left hand side, in contrast with what the help page is saying. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._