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]]
Try this: sapply(ls(pattern = "x|y|z"), get, simplify = F) On Mon, Jan 3, 2011 at 3:25 PM, Eduardo de Oliveira Horta < eduardo.oliveirahorta@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 > > Is this possible? > > Thanks in advance, > > Eduardo Horta > > [[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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
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
> -----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. >
Eduardo, Try this: object.list <- sapply(objects(), function(x) get(x), simplify=F, USE.NAMES=T) Dave From: Eduardo de Oliveira Horta <eduardo.oliveirahorta@gmail.com> To: r-help <r-help@r-project.org> Date: 01/03/2011 11:32 AM Subject: [R] Saving objects inside a list Sent by: r-help-bounces@r-project.org 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@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]]
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@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]]
> Message: 42 > Date: Mon, 3 Jan 2011 18:58:04 -0200 > From: Eduardo de Oliveira Horta<eduardo.oliveirahorta at gmail.com> > To: r-help<r-help at r-project.org> > Subject: Re: [R] Saving objects inside a list > Message-ID: > <AANLkTimBXmR0RUSiWs1GrORhJH=WStOfZqdoc-90zx4q at mail.gmail.com> > Content-Type: text/plain > > sapply(ls(),get) works fine. Thanks. > > ps: the as.list and the eapply suggestions didn't work.Hi Eduardo (and all the best for this new year), are you sure the as.list and eapply solutions didn't work ? On my machine they produce a list but in "reverse order" compared to the result of ls(),...maybe it's the same with you : names(as.list(.GlobalEnv))[6] is the name of the 6th variable FROM THE END of ls(). Regards. Olivier -- Olivier ETERRADOSSI Ma?tre-Assistant animateur du groupe Sensomines (Institut Carnot M.I.N.E.S) ------------------------------------------------------------- CMGD P?le "Mat?riaux Polym?res Avanc?s" axe "Propri?t?s Psycho-Sensorielles des Mat?riaux" ------------------------------------------------------------- Ecole des Mines d'Al?s H?lioparc, 2 av. P. Angot, F-64053 PAU CEDEX 9 tel std: +33 (0)5.59.30.54.25 tel direct: +33 (0)5.59.30.90.35 fax: +33 (0)5.59.30.63.68 http://www.mines-ales.fr e-mail : olivier.eterradossi at mines-ales.fr
Hello, I've contacted the guys from RKWard. Below I paste the answer Thomas Friedrichsmeier gave me. ------- Hi, the problem appears to be our use of "active bindings" (see ?makeActiveBinding). Internally, RKWard replaces all objects inside .GlobalEnv by active bindings. This allows us to find out, when the objects get modified. For almost all purposes, these active bindings behave just like the regular object, but apparently, as.list() copies the accessor functions, instead. I do wonder whether that is the expected behavior of as.list()... Either way, RKWard will probably switch to a different strategy for detecting when objects get modified, in the not-too-distant future. The problem should go away, then. Meanwhile, perhaps you can work around the problem using code like this: oblist <- sapply (ls (all.names=TRUE), function (x) get (x), simplify=FALSE) Regards Thomas On Tue, Jan 4, 2011 at 2:54 PM, William Dunlap <wdunlap@tibco.com> wrote:> Under RKWard, do you get (at the command line) > > environment() > <environment: R_GlobalEnv> > If environment() doesn't evaluate to .GlobalEnv's > value then > as.list(environment()) > may show the B=1000. It may be that RKWard doesn't > use .GlobalEnv in the usual way. > > Bill Dunlap > Spotfire, TIBCO Software > wdunlap tibco.com > > > > -----Original Message----- > > From: r-help-bounces@r-project.org > > [mailto:r-help-bounces@r-project.org] On Behalf Of Eduardo de > > Oliveira Horta > > Sent: Tuesday, January 04, 2011 6:25 AM > > To: r-help@r-project.org > > Subject: Re: [R] Saving objects inside a list > > > > Hello, (and a happy new year for you too!) > > > > Apparently the problem is happening only within my RKWard sessions: > > > B = 1000 > > > oblist = as.list(.GlobalEnv) > > > str(oblist) > > List of 1 > > $ B:function (value) > > > oblist$B > > function (value) > > { > > if (!missing(value)) { > > assign(k, value, envir = .rk.watched.symbols) > > .rk.do.call("ws", k) > > invisible(value) > > } > > else { > > get(k, envir = .rk.watched.symbols) > > } > > } > > <environment: 0x08cc9eec> > > > > Now the same code in a regular Rgui session: > > > B = 1000 > > > oblist = as.list(.GlobalEnv) > > > str(oblist) > > List of 1 > > $ B: num 1000 > > > oblist$B > > [1] 1000 > > > > Problem solved? > > > > Best regards, > > > > Eduardo Horta > > > > On Tue, Jan 4, 2011 at 9:41 AM, Olivier ETERRADOSSI < > > olivier.eterradossi@mines-ales.fr> wrote: > > > > > Message: 42 > > >> Date: Mon, 3 Jan 2011 18:58:04 -0200 > > >> From: Eduardo de Oliveira Horta<eduardo.oliveirahorta@gmail.com> > > >> > > >> To: r-help<r-help@r-project.org> > > >> Subject: Re: [R] Saving objects inside a list > > >> Message-ID: > > >> > > <AANLkTimBXmR0RUSiWs1GrORhJH=WStOfZqdoc-90zx4q@mail.gmail.com> > > >> Content-Type: text/plain > > >> > > >> > > >> sapply(ls(),get) works fine. Thanks. > > >> > > >> ps: the as.list and the eapply suggestions didn't work. > > >> > > > Hi Eduardo (and all the best for this new year), > > > > > > are you sure the as.list and eapply solutions didn't work ? > > On my machine > > > they produce a list but in "reverse order" compared to the result of > > > ls(),...maybe it's the same with you : > > > > > > names(as.list(.GlobalEnv))[6] is the name of the 6th > > variable FROM THE END > > > of ls(). > > > > > > Regards. Olivier > > > > > > -- > > > Olivier ETERRADOSSI > > > Maître-Assistant > > > animateur du groupe Sensomines (Institut Carnot M.I.N.E.S) > > > ------------------------------------------------------------- > > > CMGD > > > Pôle "Matériaux Polymères Avancés" > > > axe "Propriétés Psycho-Sensorielles des Matériaux" > > > ------------------------------------------------------------- > > > Ecole des Mines d'Alès > > > Hélioparc, 2 av. P. Angot, F-64053 PAU CEDEX 9 > > > tel std: +33 (0)5.59.30.54.25 > > > tel direct: +33 (0)5.59.30.90.35 > > > fax: +33 (0)5.59.30.63.68 > > > http://www.mines-ales.fr > > > e-mail : olivier.eterradossi@mines-ales.fr > > > > > > > > > > > > > [[alternative HTML version deleted]] > > > > >[[alternative HTML version deleted]]