From seth at userprimary.net  Fri Feb 22 02:27:32 2008
From: seth at userprimary.net (Seth Falcon)
Date: Thu, 21 Feb 2008 17:27:32 -0800
Subject: [Rd] Suggestion: isLoaded() to test if a package is loaded
	(without loading it)
In-Reply-To: <59d7961d0802211457s42e3ac82r6a2ea73af701ea82@mail.gmail.com>
	(Henrik Bengtsson's message of "Thu\,
	21 Feb 2008 14\:57\:46 -0800")
References: <59d7961d0802211457s42e3ac82r6a2ea73af701ea82@mail.gmail.com>
Message-ID: <m28x1d3hmj.fsf@userprimary.net>

"Henrik Bengtsson" <hb at stat.berkeley.edu> writes:
> Hi,
>
> for 'affxparser' (Bioconductor), we needed a function to test if a
> certain package was loaded or not, but we did not want to load it if
> it wasn't, which is why we couldn't use require().  We came up with
> the following solution:
>
>   isPackageLoaded <- function(package, version=NULL, ...) {
>     s <- search();
>     if (is.null(version)) {
>       s <- sub("_[0-9.-]*", "", s);
>     } else {
>       package <- manglePackageName(package, version);
>     }
>     pattern <- sprintf("package:%s", package);
>     (pattern %in% s);
>   }

This only tests whether or not the given package is attached to the
search path.  You also (I think) want to search loaded namespaces.

But I think such a helper would be useful in general.

+ seth

-- 
Seth Falcon | seth at userprimary.net | blog: http://userprimary.net/user/



[Rd] Suggestion: isLoaded() to test if a package is loaded (without loading it)
Seth Falcon