[R] sibling list element reference during list definition

Gabor Grothendieck ggrothendieck at gmail.com
Sat Nov 12 15:24:32 CET 2005


You can do this:

   L <- list(value = 2)
   L$plusplus <- L$value + 1

or use the proto package which does support this sort of
manipulation:

   library(proto)
   as.list(proto(,{value = 2; plusplus = value+1}))

That creates a proto object with the indicated two components
and then converts it to a list.

On 11/12/05, Paul Roebuck <roebuck at mdanderson.org> wrote:
> Can the value of a list element be referenced from a
> sibling list element during list creation without the use
> of a temporary variable?
>
> The following doesn't work but it's the general idea.
>
> > list(value = 2, plusplus = $value+1)
>
> such that the following would be the output from str()
>
> List of 2
>  $ value   : num 2
>  $ plusplus: num 3
>
> ----------------------------------------------------------
> SIGSIG -- signature too long (core dumped)
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list