Skip to content

Commit

Permalink
Replace recompile argument with more flexible compile
Browse files Browse the repository at this point in the history
This allows you to optionally disable re-compilation entirely, or force a full recompile.

Needed for r-lib/roxygen2#784
  • Loading branch information
hadley authored and jimhester committed Oct 29, 2018
1 parent 8d2d62f commit 0ef4f58
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# pkgload 1.0.1.9000

* `load_all()` gains a `compile` argument which controls more finely whether to
compile the code or not. The `recompile` argument is now deprecated and will
be removed in a future version of pkgload.

# pkgload 1.0.1

* `unload()` now only removes S4 classes which were generated in the package
Expand Down
29 changes: 20 additions & 9 deletions R/load.r
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
#' [unload()] and is the default. Use `reset = FALSE` may be
#' faster for large code bases, but is a significantly less accurate
#' approximation.
#' @param recompile force a recompile of DLL from source code, if present.
#' This is equivalent to running [pkgbuild::clean_dll()] before
#' `load_all`
#' @param compile If `TRUE` always recompiles the package; if `NA`
#' recompiles if needed (as determined by [pkgbuild::needs_compile()]);
#' if `FALSE`, never recompiles.
#' @param export_all If `TRUE` (the default), export all objects.
#' If `FALSE`, export only the objects that are listed as exports
#' in the NAMESPACE file.
Expand All @@ -75,6 +75,9 @@
#' which more closely mimics the environment within test files.
#' @param helpers if \code{TRUE} loads \pkg{testthat} test helpers.
#' @param quiet if `TRUE` suppresses output from this function.
#' @param recompile DEPRECATED. force a recompile of DLL from source code, if
#' present. This is equivalent to running [pkgbuild::clean_dll()] before
#' `load_all`
#' @keywords programming
#' @examples
#' \dontrun{
Expand All @@ -92,10 +95,10 @@
#' load_all("./", export_all = FALSE)
#' }
#' @export
load_all <- function(path = ".", reset = TRUE, recompile = FALSE,
load_all <- function(path = ".", reset = TRUE, compile = NA,
export_all = TRUE, export_imports = export_all,
helpers = TRUE, attach_testthat = uses_testthat(path),
quiet = FALSE) {
quiet = FALSE, recompile = FALSE) {
path <- pkg_path(path)
package <- pkg_name(path)
description <- pkg_desc(path)
Expand Down Expand Up @@ -148,12 +151,20 @@ load_all <- function(path = ".", reset = TRUE, recompile = FALSE,
unload_dll(package)
}

if (recompile) {
pkgbuild::clean_dll(path)
# Compile dll if requested
if (missing(compile) && !missing(recompile)) {
compile <- if (isTRUE(recompile)) TRUE else NA
}

# Compile dll if it exists
pkgbuild::compile_dll(path, quiet = quiet)
if (isTRUE(compile)) {
pkgbuild::compile_dll(path, force = TRUE, quiet = quiet)
} else if (identical(compile, NA)) {
pkgbuild::compile_dll(path, quiet = quiet)
} else if (identical(compile, FALSE)) {
# don't compile
} else {
stop("`compile` must be a logical vector of length 1", call. = FALSE)
}

# If installed version of package loaded, unload it, again
# (needed for dependencies of pkgbuild)
Expand Down
17 changes: 11 additions & 6 deletions man/load_all.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0ef4f58

Please sign in to comment.