Skip to content
Prev 173503 / 398506 Next

Easy "Recall" to get ls(..., all.names=TRUE)?

-----Original Message-----
From: Rolf Turner [mailto:r.turner at auckland.ac.nz] 
Sent: Wednesday, 11 March, 2009 5:09 PM
To: Szumiloski, John
Cc: r-help at r-project.org
Subject: Re: [R] Easy "Recall" to get ls(..., all.names=TRUE)?
On 12/03/2009, at 3:16 AM, Szumiloski, John wrote:

            
Does the following do what you want?

myls <- function (all.names=TRUE,pos=-1,...)
{
xxx <- pmatch(names(list(...)),"envir",nomatch=0)
if(length(xxx) && xxx>0) return(ls(all.names=all.names,pos=pos,...))
eee <- if(pos==-1) parent.frame() else as.environment(pos)
ls(all.names=all.names,envir=eee,...)
}

	cheers,

		Rolf Turner

[snip legalese]




Rolf, as written that doesn't work: myls(3) just returned everything in
the top level workspace, .GlobalEnv, and not (in my case) everything in
package:graphics. However, I switched the order of the first two
arguments, and now it does the right thing in that case.  I will still
need to test it further.  Thanks for the suggestion.  -John
Notice:  This e-mail message, together with any attachme...{{dropped:12}}