Re: [R] How to print the objects in the memory

From: Prof Brian Ripley <>
Date: Wed 31 Jan 2007 - 09:43:40 GMT

On Wed, 31 Jan 2007, Vladimir Eremeev wrote:

[replying to something else, without any indication or context. That 'something' was about how to print all objects.]

> 1. ? ls.str()
> 2. My favourite "eval(parse(text= ... ))" :)
> sapply(ls(),FUN=function(x)eval(parse(text=x)))


> library(fortune)
> fortune("parse")

If the answer is parse() you should usually rethink the question.

Here the answer is 'get', as ls.str uses via utils:::print.ls_str. You need to be careful to get the correct object of the given name, and using your favourite will not in general do so.

When you have a character string containing the name of a variable, eval( is more direct than parsing (but less direct that get(x) ). And since there is no reason that the results are all suitable for simplifying to a vector, lapply is safer. E.g.

> xx <- pi
> y <- "test it"
> sapply(ls(), function(x) eval(parse(text=x)))

                 xx                  y
"3.14159265358979"          "test it"

is not what is wanted.

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed Jan 31 20:48:55 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 31 Jan 2007 - 10:30:26 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.