Skip to content

Commit

Permalink
Simply force all the promises rather than removing them.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimhester committed Dec 23, 2015
1 parent f2f077b commit 200b631
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
4 changes: 4 additions & 0 deletions R/install.r
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ install <- function(pkg = ".", reload = TRUE, quick = FALSE, local = TRUE,
pkg <- as.package(pkg)
check_build_tools(pkg)

if (is_loaded(pkg)) {
eapply(ns_env(pkg), force, all.names = TRUE)
}

if (!quiet) {
message("Installing ", pkg$package)
}
Expand Down
7 changes: 3 additions & 4 deletions R/load.r
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ load_all <- function(pkg = ".", reset = TRUE, recompile = FALSE,

# Reloading devtools is a special case. Normally, objects in the
# namespace become inaccessible if the namespace is unloaded before the
# the object has been accessed. This is kind of a hack - using as.list
# on the namespace accesses each object, making the objects accessible
# later, after the namespace is unloaded.
# object has been accessed. Instead we force the object so they will still be
# accessible.
if (pkg$package == "devtools") {
as.list(ns_env(pkg))
eapply(ns_env(pkg), force, all.names = TRUE)
}

# Check description file is ok
Expand Down
43 changes: 8 additions & 35 deletions R/unload.r
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@
unload <- function(pkg = ".") {
pkg <- as.package(pkg)

ns <- asNamespace(pkg$package)

unregister_S3_methods(ns)
# This is a hack to work around unloading devtools itself. The unloading
# process normally makes other devtools functions inaccessible,
# resulting in "Error in unload(pkg) : internal error -3 in R_decompress1".
# If we simply force them first, then they will remain available for use
# later.
if (pkg$package == "devtools") {
eapply(ns_env(pkg), force, all.names = TRUE)
}

# If the package was loaded with devtools, any s4 classes that were created
# by the package need to be removed in a special way.
Expand Down Expand Up @@ -73,38 +78,6 @@ unload <- function(pkg = ".") {
unload_dll(pkg)
}

unregister_S3_methods <- function(ns) {
S3_methods <- getNamespaceInfo(ns, "S3methods")

unregister <- function(name, class, method) {
# This code was adapted from the .registerS3method internal function of
# base::registerS3methods
# https://github.com/wch/r-source/blob/05b76baa411afd3e9d0f3fc3c09a9a252a0a9100/src/library/base/R/namespace.R#L1398-L1426
env <-
if (!is.na(x <- .knownS3Generics[name])) {
asNamespace(x)
} else {
if(is.null(genfun <- get0(name, envir = ns))) {
stop(sprintf("object '%s' not found while unloading namespace '%s'",
name, getNamespaceName(ns)), call. = FALSE)
}
if(.isMethodsDispatchOn() && methods::is(genfun, "genericFunction")) {
genfun <- genfun@default # nearly always, the S3 generic
}
if (typeof(genfun) == "closure") {
environment(genfun)
} else {
baseenv()
}
}
table <- get(".__S3MethodsTable__.", envir = env, inherits = FALSE)
rm(list = method, envir = table)
}
for (i in seq_len(NROW(S3_methods))) {
unregister(S3_methods[i, 1], S3_methods[i, 2], S3_methods[i, 3])
}
}

# This unloads dlls loaded by either library() or load_all()
unload_dll <- function(pkg = ".") {
pkg <- as.package(pkg)
Expand Down

0 comments on commit 200b631

Please sign in to comment.