[R] What command lists everything in a package?

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Sun Jul 5 18:07:05 CEST 2009


On Sun, Jul 5, 2009 at 3:40 PM, hadley wickham<h.wickham at gmail.com> wrote:
>> 2) Related to the above, how do I tell what packages are currently
>> loaded at any given time so that I don't waste time loading things
>> that are already loaded? search() tells me what's available, but
>> what's loaded? The best I can find so far goes like this:
>
> Loading something a second time takes hardly any time, so why worry about it?

 library() and require() already check to see if the package is
loaded, so any test done before calling library() or require() is
going to be redundant!

 library() uses:

        pkgname <- paste("package", package, sep = ":")
        newpackage <- is.na(match(pkgname, search()))

require() uses:

        loaded <- paste("package", package, sep = ":") %in% search()

Barry




More information about the R-help mailing list