[R] assigning to list element within target environment

Hadley Wickham hadley at rice.edu
Thu Mar 17 13:33:35 CET 2011


On Thu, Mar 17, 2011 at 7:25 AM, Richard D. Morey <r.d.morey at rug.nl> wrote:
> I would like to assign an value to an element of a list contained in an
> environment. The list will contain vectors and matrices. Here's a simple
> example:
>
> # create toy environment
> testEnv = new.env(parent = emptyenv())
>
> # create list that will be in the environment, then assign() it
> x = list(a=1,b=2)
> assign("xList",x,testEnv)
>
> # create new element, to be inserted into xList
> c = 5:7
>
> Now, what I'd like to do is something like this:
>
> assign("xList[[3]]",c,testEnv)

testEnv$x[[3]] <- c

?

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list