Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Require packages in depends.

Fixes #161, #178, #192
  • Loading branch information...
commit 1cfcbd3f5c33dd89981384c09f694a81b0c2770f 1 parent 7479c55
@hadley authored
View
1  DESCRIPTION
@@ -82,3 +82,4 @@ Collate:
'check_devtools.r'
'rcpp-attributes.r'
'cran.r'
+ 'load-depends.r'
View
2  NEWS
@@ -5,6 +5,8 @@ NEW FEATURES
* Rcpp attributes are now automatically compiled during build.
+* Packages listed in depends are `require()`d (Fixes #161, #178, #192)
+
MINOR FEATURES
* `check_cran` now downloads packages from cran.rstudio.com.
View
7 R/imports-env.r
@@ -45,13 +45,11 @@ imports_env_name <- function(pkg = ".") {
#' the dependency packages.
#'
#' @keywords internal
-load_imports <- function(pkg = ".", deps = c("depends", "imports")) {
+load_imports <- function(pkg = ".") {
pkg <- as.package(pkg)
# Get data frame of dependency names and versions
- deps <- lapply(pkg[deps], parse_deps)
- deps <- Reduce(rbind, deps)
-
+ deps <- parse_deps(pkg$imports)
if (is.null(deps) || nrow(deps) == 0) return(invisible())
# If we've already loaded imports, don't load again (until load_all
@@ -66,7 +64,6 @@ load_imports <- function(pkg = ".", deps = c("depends", "imports")) {
invisible(deps)
}
-
# Load imported objects
# The code in this function is taken from base::loadNamespace
process_imports <- function(pkg = ".") {
View
12 R/load-depends.r
@@ -0,0 +1,12 @@
+load_depends <- function(pkg = ".") {
+ pkg <- as.package(pkg)
+
+ # Get data frame of dependency names and versions
+ deps <- parse_deps(pkg$depends)
+ if (is.null(deps) || nrow(deps) == 0) return(invisible())
+
+ mapply(check_dep_version, deps$name, deps$version, deps$compare)
+ lapply(deps$name, require, character.only = TRUE)
+
+ invisible(deps)
+}
View
5 R/load.r
@@ -110,7 +110,8 @@ load_all <- function(pkg = ".", reset = FALSE, recompile = FALSE,
out <- list(env = ns_env(pkg))
- # Load dependencies into the imports environment
+ # Load dependencies
+ load_depends(pkg)
load_imports(pkg)
out$data <- load_data(pkg)
@@ -126,7 +127,7 @@ load_all <- function(pkg = ".", reset = FALSE, recompile = FALSE,
# Set up the exports in the namespace metadata (this must happen after
# the objects are loaded)
setup_ns_exports(pkg, export_all)
-
+
# Set up the package environment ------------------------------------
# Create the package environment if needed
if (!is_attached(pkg)) attach_ns(pkg)
View
11 inst/tests/depends/DESCRIPTION
@@ -0,0 +1,11 @@
+Package: dependmissing
+Title: Tools to make developing R code easier
+License: GPL-2
+Description:
+Author: Hadley <h.wickham@gmail.com>
+Maintainer: Hadley <h.wickham@gmail.com>
+Version: 0.1
+Depends:
+ MASS,
+ R
+Collate: a.r b.r
View
0  inst/tests/depend-version/R/a.r → inst/tests/depends/R/a.r
File renamed without changes
View
0  inst/tests/depend-missing/DESCRIPTION → inst/tests/import-missing/DESCRIPTION
File renamed without changes
View
0  inst/tests/depend-missing/R/a.r → inst/tests/import-missing/R/a.r
File renamed without changes
View
0  inst/tests/depend-version/DESCRIPTION → inst/tests/import-version/DESCRIPTION
File renamed without changes
View
0  inst/tests/depend-version/NAMESPACE → inst/tests/import-version/NAMESPACE
File renamed without changes
View
1  inst/tests/import-version/R/a.r
@@ -0,0 +1 @@
+a <- 1
View
0  inst/tests/depend-version/R/b.r → inst/tests/import-version/R/b.r
File renamed without changes
View
14 inst/tests/test-depend.r
@@ -2,8 +2,8 @@ context("Dependencies")
test_that("Warned about dependency versions", {
# Should give a warning about grid version
- expect_warning(load_all("depend-version"), "Need grid >=")
- unload("depend-version")
+ expect_warning(load_all("import-version"), "Need grid >=")
+ unload("import-version")
# TODO: Add check for NOT giving a warning about compiler version
# Not possible with testthat?
@@ -12,12 +12,18 @@ test_that("Warned about dependency versions", {
test_that("Error on missing dependencies", {
# Should give a warning about grid version
- expect_error(load_all("depend-missing"), "missingpackage not available")
+ expect_error(load_all("import-missing"), "missingpackage not available")
# Loading process will be partially done; unload it
- unload("depend-missing")
+ unload("import-missing")
})
+test_that("Packages in depends are required", {
+ load_all("depends")
+ expect_true("package:MASS" %in% search())
+ unload("depends")
+ detach("package:MASS", unload = TRUE)
+})
test_that("Parse dependencies", {
deps <- parse_deps("\nhttr (< 2.1),\nRCurl (>= 3),\nutils (== 2.12.1),\ntools,\nR (>= 2.10),\nmemoise")
View
2  man/load_imports.Rd
@@ -2,7 +2,7 @@
\alias{load_imports}
\title{Load all of the imports for a package}
\usage{
- load_imports(pkg = ".", deps = c("depends", "imports"))
+ load_imports(pkg = ".")
}
\description{
The imported objects are copied to the imports
Please sign in to comment.
Something went wrong with that request. Please try again.