[R] value of variable in ls()

peter dalgaard pdalgd at gmail.com
Mon Oct 19 17:12:49 CEST 2015


On 19 Oct 2015, at 16:16 , James Toll <james at jtoll.com> wrote:

> 
>> On Oct 18, 2015, at 10:51 AM, Christian Hoffmann <christian at echoffmann.ch> wrote:
>> 
>> How can I do e.g. print("unknown"(ls())) and get the variable values in my current environment?
> 
> From your example, it sounds like what you want is simply this:
> 
> sapply(ls(), get)
> 

Perhaps lapply rather than sapply; I don't think the simplification step of the latter is desirable. Incidentally, both variations are effectively crossing the creek to fetch as.list(GlobalEnv).

If your environment contains large objects, you will get what you asked for, but that might well be more than you expected.

> 
> James
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list