Two incredibly useful functions to throw into your .rprofile

February 7, 2012

(This article was first published on Inundata » R, and kindly contributed to R-bloggers)

I’ve neglected this blog for quite some time but I’m getting around to finishing up a bunch of draft posts. But here is a quick one:

Listing objects in your global environment
A simple ls() doesn’t really tell you enough useful information at a glance. Most often I just want to know what I named certain data.frames or functions. This handy little function, called as lsa() will do that for you:

lsa <- function()
    obj_type <- function(x) { class(get(x)) }

Listing all functions in a certain package
This can be called with lsp(). The pattern argument will allow you to quickly find the right function if you vaguely remember the name.

lsp <-function(package, all.names = FALSE, pattern)
  package <- deparse(substitute(package))
      pos = paste("package", package, sep = ":"),
      all.names = all.names,
      pattern = pattern

Be sure to throw them both in a new environment (i.e. not the global one) so they don’t get accidentally removed when you clear your variables.

To leave a comment for the author, please follow the link and comment on their blog: Inundata » R. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)