[R] ls() with different defaults: Solution;

Hadley Wickham h.wickham at gmail.com
Tue Mar 12 18:33:42 CET 2013


On Tue, Mar 12, 2013 at 12:59 PM, Szumiloski, John
<john_szumiloski at merck.com> wrote:
> Dear useRs,
>
> Some time ago I queried the list as to an efficient way of building a function which acts as ls() but with a different default for all.names:
>
> http://tolstoy.newcastle.edu.au/R/e6/help/09/03/7588.html
>
> I have struck upon a solution which so far has performed admirably.  In particular, it uses ls() and not its explicit source code, so only has a dependency on its name and the name of its all.names argument.  Here is my solution:
>
> lsall  <-  function(...) {
>
>      thecall <- as.call(c(as.name('ls'), list(...)))
>      newcall <- match.call(definition=ls, call=thecall)
>      if( !('all.names' %in% names(newcall)) ) newcall[['all.names']] <- TRUE
>      eval(newcall, envir=parent.frame())
>
>    }#### end lsall

Why not just do:

lsall  <-  function(..., all.names = TRUE) {
  ls(..., all.names = all.names)
}

?   Then the function practically documents itself.

Hadley

-- 
Chief Scientist, RStudio
http://had.co.nz/



More information about the R-help mailing list