An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110103/2422fa92/attachment.pl>
Saving objects inside a list
11 messages · Eduardo de Oliveira Horta, Henrique Dallazuanna, Gabor Grothendieck +3 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110103/ec9780df/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110103/8ae95c7a/attachment.pl>
On Mon, Jan 3, 2011 at 12:25 PM, Eduardo de Oliveira Horta
<eduardo.oliveirahorta at gmail.com> wrote:
Hello there, any ideas on how to save all the objects on my workspace inside a list object? For example, say my workspace is as follows ls() [1] "x" "y" "z" and suppose I want to put these objects inside a list object, say object.list <- list() without having to explicitly write down their names as in object.list$x = x object.list$y = y object.list$z = z
Try this: eapply(.GlobalEnv, identity)
Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110103/823a8cec/attachment.pl>
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Eduardo de Oliveira Horta Sent: Monday, January 03, 2011 9:25 AM To: r-help Subject: [R] Saving objects inside a list Hello there, any ideas on how to save all the objects on my workspace inside a list object?
Does as.list(.GlobalEnv) do what you want? Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com
For example, say my workspace is as follows ls() [1] "x" "y" "z" and suppose I want to put these objects inside a list object, say object.list <- list() without having to explicitly write down their names as in object.list$x = x object.list$y = y object.list$z = z Is this possible? Thanks in advance, Eduardo Horta [[alternative HTML version deleted]]
______________________________________________ R-help at 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110103/03287a56/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110103/5b6b2782/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110103/420145f1/attachment.pl>
On Mon, Jan 3, 2011 at 3:58 PM, Eduardo de Oliveira Horta
<eduardo.oliveirahorta at gmail.com> wrote:
sapply(ls(),get) works fine. Thanks. ps: the as.list and the eapply suggestions didn't work.
They work for me. Starting in a fresh session:
x <- 1; f <- function(x) x; DF <- data.frame(a = 1:3) as.list(.GlobalEnv)
$DF a 1 1 2 2 3 3 $f function (x) x $x [1] 1
eapply(.GlobalEnv, identity)
$DF a 1 1 2 2 3 3 $f function (x) x $x [1] 1
Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Eduardo de Oliveira Horta Sent: Monday, January 03, 2011 12:58 PM To: r-help Subject: Re: [R] Saving objects inside a list sapply(ls(),get) works fine. Thanks. ps: the as.list and the eapply suggestions didn't work.
What version of R are you using? In 2.12.0 I get
> x <- 1:7
> y <- function(...)list(...)
> z <- runif(3) # creates .Random.seed also
> str(as.list(.GlobalEnv)) # add all.names=TRUE to get .Random.seed
List of 3
$ z: num [1:3] 0.698 0.475 0.354
$ y:function (...)
..- attr(*, "source")= chr "function(...)list(...)"
$ x: int [1:7] 1 2 3 4 5 6 7
> str(eapply(.GlobalEnv, function(x)x)) # all.names=TRUE ok here also
List of 3
$ z: num [1:3] 0.698 0.475 0.354
$ y:function (...)
..- attr(*, "source")= chr "function(...)list(...)"
h$ x: int [1:7] 1 2 3 4 5 6 7
Use environment() instead of .GlobalEnv if you want to
process the current environment.
In any version of R sapply() can give incorrect results,
as in (in a fresh vanilla R session):
> x <- 1:4
> y <- 11:14
> z <- 21:24
> str(sapply(ls(), get))
int [1:4, 1:3] 1 2 3 4 11 12 13 14 21 22 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:3] "x" "y" "z"
or, in another fresh session
> FUN <- "a string named FUN"
> X <- 17
> sapply(ls(), get)
$FUN
function (x, pos = -1, envir = as.environment(pos), mode = "any",
inherits = TRUE)
.Internal(get(x, envir, mode, inherits))
$X
[1] "FUN" "X"
as.list(envir) and eapply(envir, function(x)x) do
not have problems in those cases.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
On Mon, Jan 3, 2011 at 3:56 PM, Jorge Ivan Velez <jorgeivanvelez at gmail.com>wrote:
Hi Eduardo, Try r <- ls() result <- sapply(r, get) result HTH, Jorge On Mon, Jan 3, 2011 at 12:25 PM, Eduardo de Oliveira Horta <> wrote:
Hello there, any ideas on how to save all the objects on my workspace
inside a list
object?
For example, say my workspace is as follows
ls()
[1] "x" "y" "z"
and suppose I want to put these objects inside a list object, say
object.list <- list()
without having to explicitly write down their names as in
object.list$x = x
object.list$y = y
object.list$z = z
Is this possible?
Thanks in advance,
Eduardo Horta
[[alternative HTML version deleted]]
______________________________________________ R-help at 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 at 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.