Try this: x <- 1 z <- as.name ("x") eval (call ("<-", z, call ("attr<-", z, "foo", "bar"))) x [1] 1 attr(,"foo") [1] "bar"
On 15 авг, 06:35, "Abiel Reinhart" <[EMAIL PROTECTED]> wrote: > I would like to use a text string to get a reference to an object whose name > is the text string. I have seen people using get() for this purpose, but as > far as I can tell this returns a copy of the object, not a pointer to the > object. For instance, if I were to write > > x <- get("z") > attr(x, "age") <- "fifty" > > Then x would have the attribute "age" attached to it, but z would not. I > would like z to change when I change x. Does anyone have a suggestion on how > to do this? The context for this question is an application in which object > attributes are listed in an XML file, with each set of attributes having a > key which refers to the name of an object in R. > > Thank you, > > -- > Abiel Reinhart > email: [EMAIL PROTECTED] > cell: 541-514-1115 > > [[alternative HTML version deleted]] > > ______________________________________________ > [EMAIL PROTECTED] mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.