Hi

Beware of shooting in your leg. Instead of poisoning your workspace with 
numerous objects called "obj.n" or something like that you help yourself 
with creating single object of type list. Parts of a list can be accessed 
much more easily than this kind of get construction.

I use R quite a long time but I hardly remember a single event when I used 
such construction; I always used lists.

In your example

lll<-vector("list", 2)
lll[[1]] <- 7:9
lll[[2]] <- 6:2
testf <- function(k) plot(lll[[k]])
testf(1)

Regards
Petr


> Thanks!
> 
> That's exactly it.
> get gets it ;-)
> 
> Berry
> 
> 
> From: michael.weyla...@gmail.com
> Date: Wed, 7 Sep 2011 14:54:48 -0500
> Subject: Re: [R] access objects
> To: berryboessenk...@hotmail.com
> CC: r-help@r-project.org
> 
> The get() function should get you where you need. 
> 
> Michael Weylandt
> 
> On Wed, Sep 7, 2011 at 12:53 PM, Berry Boessenkool 
> <berryboessenk...@hotmail.com> wrote:
> 
> hi,
> 
> say I have consecutively numbered objects obj1, obj2, ... in my R 
workspace.
> 
> I want to acces one of them inside a function, with the number given as 
anargument.
> 
> Where can I find help on how to do that? Somebody must have been trying 
to
> do this before...
> 
> Some keywords to start a search are appreciated as well.
> 
> 
> 
> Here's an example, I hope it clarifies what I'm trying to do:
> 
> 
> 
> obj1 <- 7:9
> 
> obj2 <- 6:2
> 
> testf <- function(k) plot(  noquote(paste("obj", k, sep=""))  )
> 
> testf(1) # should plot obj1
> 
> 
> 
> 
> 
> 
> 
> -------------------------------------
> 
> Berry Boessenkool
> 
> D-14476 Potsdam (OT Golm)
> 
> -------------------------------------
> 
> 
> 
> ______________________________________________
> 
> 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.
> 
> 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.

______________________________________________
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.

Reply via email to