Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use own get_namespace function

  • Loading branch information...
commit 79eb4e27a1e1d6ee645bfac2576e4eafd54491db 1 parent cc782b0
@wch wch authored
Showing with 17 additions and 3 deletions.
  1. +2 −2 R/metadata.r
  2. +14 −0 R/namespace-env.r
  3. +1 −1  R/reload.r
View
4 R/metadata.r
@@ -18,7 +18,7 @@
#' unload(devtest("load-hooks"))
#' @export
dev_meta <- function(name) {
- ns <- .Internal(getRegisteredNamespace(as.name(name)))
+ ns <- get_namespace(as.name(name))
if (is.null(ns)) {
stop("Namespace not found for ", name, ". Is it loaded?")
}
@@ -34,7 +34,7 @@ dev_meta <- function(name) {
# Create the devtools metadata environment for a package.
# This should be run when packages are loaded by devtools.
create_dev_meta <- function(name) {
- ns <- .Internal(getRegisteredNamespace(as.name(name)))
+ ns <- get_namespace(as.name(name))
if (!is.null(ns$.__DEVTOOLS__)) {
stop("devtools metadata for package ", name, " already exists.")
View
14 R/namespace-env.r
@@ -184,3 +184,17 @@ unregister_namespace <- function(name = NULL) {
rm(name, ns_registry())
invisible()
}
+
+# This is similar to getNamespace(), except that getNamespace will load
+# the namespace if it's not already loaded. This function will not.
+# In R 2.16, a function called .getNamespace() will have the same effect
+# and this will no longer be necessary.
+get_namespace <- function(name) {
+ # Sometimes we'll be passed something like as.name(name), so make sure
+ # it's a string
+ name <- as.character(name)
+ if (!(name %in% loadedNamespaces()))
+ return(NULL)
+ else
+ return(getNamespace(name))
+}
View
2  R/reload.r
@@ -77,7 +77,7 @@ unload <- function(pkg = ".") {
# to go away.
# loadedNamespaces() and unloadNamespace() often don't work here
# because things can be in a weird state.
- if (!is.null(.Internal(getRegisteredNamespace(pkg$package)))) {
+ if (!is.null(get_namespace(pkg$package))) {
message("unloadNamespace(\"", pkg$package,
"\") not successful. Forcing unload.")
unregister_namespace(pkg$package)
Please sign in to comment.
Something went wrong with that request. Please try again.