On Sun, Jul 5, 2009 at 3:40 PM, hadley wickham<h.wick...@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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to