r-lib/backports

Add isNamespaceLoaded added in 3.2.0

Closed this issue · 1 comments

The isNamespaceLoaded() function was only introduced in R 3.2.0 (just checked because we want our package to support any R version since 3.0.0).

Per the documentation of ns-load:

requireNamespace is a wrapper for loadNamespace analogous to require that returns a logical value.

loadedNamespaces returns a character vector of the names of the loaded name spaces.

isNamespaceLoaded(pkg) is equivalent to but more efficient than pkg %in% loadedNamespaces().

So I think it's just:

isNamespaceLoaded <- function(pkg) {
  pkg %in% loadedNamespaces()
}
mllg commented

I missed that one, now in master.