pkgload/0000755000176200001440000000000013365666713011713 5ustar liggesuserspkgload/inst/0000755000176200001440000000000013365662412012660 5ustar liggesuserspkgload/inst/WORDLIST0000644000176200001440000000003513365662412014050 0ustar liggesusersdevtools dir dirs recompiles pkgload/tests/0000755000176200001440000000000013365662743013054 5ustar liggesuserspkgload/tests/testthat.R0000644000176200001440000000021013010373512015004 0ustar liggesuserslibrary(testthat) library(pkgload) # Needed so that install.packages works correctly Sys.setenv("R_TESTS" = "") test_check("pkgload") pkgload/tests/testthat/0000755000176200001440000000000013365666713014715 5ustar liggesuserspkgload/tests/testthat/test-s4-sort.r0000644000176200001440000000200213010373512017335 0ustar liggesuserscontext("s4-sort") suppressMessages(load_all("testS4sort")) classes <- methods::getClasses(ns_env('testS4sort')) test_that("Example classes are not topologically sorted", { ## there are some superclasses of the first class ## later in the list superclasses <- extends(getClass(classes[1]))[-1] expect_true(any(superclasses %in% classes[-1])) }) test_that("topological sorting s4 classes", { sorted_classes <- sort_s4classes(classes, 'testS4sort') for (idx in seq_along(classes)) { ## for each class in the sorted list ## all its superclasses are before superclasses <- extends(getClass(sorted_classes[idx])) expect_true(all(superclasses %in% head(sorted_classes, idx))) } }) test_that("sorting extreme cases", { ## no classes to sort classes <- vector('character', 0) expect_identical(classes, sort_s4classes(classes, 'testS4sort')) ## only one class to sort classes <- "A" expect_identical(classes, sort_s4classes(classes, 'testS4sort')) }) # cleanup unload('testS4sort') pkgload/tests/testthat/testMissingNsObject/0000755000176200001440000000000013141335465020643 5ustar liggesuserspkgload/tests/testthat/testMissingNsObject/NAMESPACE0000644000176200001440000000002313010373512022043 0ustar liggesusersexport(a) export(b)pkgload/tests/testthat/testMissingNsObject/R/0000755000176200001440000000000013010373512021032 5ustar liggesuserspkgload/tests/testthat/testMissingNsObject/R/a.r0000644000176200001440000000000713010373512021432 0ustar liggesusersa <- 1 pkgload/tests/testthat/testMissingNsObject/DESCRIPTION0000644000176200001440000000031513141335465022350 0ustar liggesusersPackage: testMissingNsObject Title: Tools to make developing R code easier. This package lists 'b' as an export in NAMESPACE, but the 'b' object doesn't exist. License: GPL-2 Description: Version: 0.1 pkgload/tests/testthat/testCollateMissing/0000755000176200001440000000000013144323774020522 5ustar liggesuserspkgload/tests/testthat/testCollateMissing/R/0000755000176200001440000000000013010373512020706 5ustar liggesuserspkgload/tests/testthat/testCollateMissing/R/b.r0000644000176200001440000000000613010373512021306 0ustar liggesusersb <- 2pkgload/tests/testthat/testCollateMissing/R/a.r0000644000176200001440000000000613010373512021305 0ustar liggesusersa <- 1pkgload/tests/testthat/testCollateMissing/DESCRIPTION0000644000176200001440000000031613144323774022230 0ustar liggesusersPackage: testCollateMissing Title: Tools to make developing R code easier License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 Collate: b.r pkgload/tests/testthat/testS4union/0000755000176200001440000000000013141335465017141 5ustar liggesuserspkgload/tests/testthat/testS4union/NAMESPACE0000644000176200001440000000011013010373512020336 0ustar liggesusersexportClass(A, B, AB, mle2, mleA, mle2A) importClassesFrom(stats4, mle) pkgload/tests/testthat/testS4union/R/0000755000176200001440000000000013143400207017327 5ustar liggesuserspkgload/tests/testthat/testS4union/R/classes.r0000644000176200001440000000046313143400207021152 0ustar liggesuserssetClass("A") setClass("B") setClassUnion("AB", members = c("A", "B")) setClass("mle2", contains = "mle") setClassUnion("mleA", members = c("mle", "A")) setClassUnion("mle2A", members = c("mle2", "A")) setClassUnion("AOrNull", members = c("A", "NULL")) setClassUnion("BOrNull", members = c("B", "NULL")) pkgload/tests/testthat/testS4union/DESCRIPTION0000644000176200001440000000037313141335465020652 0ustar liggesusersPackage: testS4union Title: Test package for S4 class unions License: GPL-2 Description: Author: Winston Chang Maintainer: Winston Chang Version: 0.1 Collate: 'classes.r' Imports: stats4, methods pkgload/tests/testthat/test-s4-unload.r0000644000176200001440000000546313143400207017645 0ustar liggesuserscontext("s4-unload") # Returns a named vector of this class's superclasses. # Results are sorted so they can be compared easily to a vector. # A contains B == A is a superclass of B get_superclasses <- function(class) { superclasses <- vapply(getClass(class)@contains, slot, "superClass", FUN.VALUE = character(1)) sort(unname(superclasses)) } # Returns a named vector of this class's subclasses # Results are sorted so they can be compared easily to a vector. # A extends B == A is a subclass of B get_subclasses <- function(class) { subclasses <- vapply(getClass(class)@subclasses, slot, "subClass", FUN.VALUE = character(1)) sort(unname(subclasses)) } test_that("loading and reloading s4 classes", { run_tests <- function() { # Check class hierarchy expect_equal(get_superclasses("A"), c("AB", "AOrNull", "mle2A", "mleA")) expect_equal(get_subclasses("AB"), c("A", "B")) expect_equal(get_superclasses("mle2"), c("mle", "mle2A", "mleA")) expect_equal(get_subclasses("mleA"), c("A", "mle", "mle2")) expect_equal(get_subclasses("mle2A"), c("A", "mle2")) expect_equal(get_subclasses("AOrNull"), c(".NULL", "A", "NULL")) expect_equal(get_subclasses("BOrNull"), c(".NULL", "B", "NULL")) # Check that package is registered correctly expect_equal(getClassDef("A")@package, "testS4union") expect_equal(getClassDef("AB")@package, "testS4union") expect_equal(getClassDef("mle2")@package, "testS4union") expect_equal(getClassDef("AOrNull")@package, "testS4union") expect_equal(getClassDef("BOrNull")@package, "testS4union") # Unloading shouldn't result in any errors or warnings expect_warning(unload("testS4union"), NA) # Check that classes are unregistered expect_true(is.null(getClassDef("A"))) expect_true(is.null(getClassDef("B"))) expect_true(is.null(getClassDef("AB"))) expect_true(is.null(getClassDef("AorNULL"))) expect_true(is.null(getClassDef("BorNULL"))) } load_all("testS4union") run_tests() # Load again and repeat tests -------------------------------------------- load_all("testS4union") run_tests() # Install package then load and run tests withr::with_temp_libpaths({ install.packages("testS4union", repos = NULL, type = "source", quiet = TRUE) library("testS4union") load_all("testS4union") run_tests() }) # Loading again shouldn't result in any errors or warnings expect_warning(load_all("testS4union", reset = FALSE), NA) unload("testS4union") unloadNamespace("stats4") # This was imported by testS4union # Check that classes are unregistered # This test on A fails for some bizarre reason - bug in R? But it doesn't # to cause any practical problems. expect_true(is.null(getClassDef("A"))) expect_true(is.null(getClassDef("B"))) expect_true(is.null(getClassDef("AB"))) }) pkgload/tests/testthat/test-load-hooks.r0000644000176200001440000001075313010373512020076 0ustar liggesuserscontext("Load hooks") test_that("hooks called in correct order", { record_use <- function(hook) { function(...) { h <- globalenv()$hooks h$events <- c(h$events, hook) } } reset_events <- function() { assign("hooks", new.env(parent = emptyenv()), envir = globalenv()) h <- globalenv()$hooks h$events <- character() } setHook(packageEvent("testHooks", "attach"), record_use("user_attach")) setHook(packageEvent("testHooks", "detach"), record_use("user_detach")) setHook(packageEvent("testHooks", "onLoad"), record_use("user_load")) setHook(packageEvent("testHooks", "onUnload"), record_use("user_unload")) reset_events() load_all("testHooks") expect_equal(globalenv()$hooks$events, c("pkg_load", "user_load", "pkg_attach", "user_attach") ) reset_events() load_all("testHooks", reset = FALSE) expect_equal(globalenv()$hooks$events, character()) reset_events() unload("testHooks") expect_equal(globalenv()$hooks$events, c("user_detach", "pkg_detach", "user_unload", "pkg_unload") ) rm(list = "hooks", envir = globalenv()) setHook(packageEvent("testHooks", "attach"), NULL, "replace") setHook(packageEvent("testHooks", "detach"), NULL, "replace") setHook(packageEvent("testHooks", "onLoad"), NULL, "replace") setHook(packageEvent("testHooks", "onUnload"), NULL, "replace") }) test_that("onLoad and onAttach", { load_all("testLoadHooks") nsenv <- ns_env("testLoadHooks") pkgenv <- pkg_env("testLoadHooks") # normalizePath is needed so that capitalization differences on # case-insensitive platforms won't cause errors. expect_equal(normalizePath(nsenv$onload_lib), normalizePath(getwd())) expect_equal(normalizePath(nsenv$onattach_lib), normalizePath(getwd())) # a: modified by onLoad in namespace env # b: modified by onAttach in namespace env # c: modified by onAttach in package env # In a normal install+load, b can't be modified by onAttach because # the namespace is locked before onAttach. But it can be modified when # using load_all. expect_equal(nsenv$a, 2) expect_equal(nsenv$b, 2) # This would be 1 in normal install+load expect_equal(nsenv$c, 1) expect_equal(pkgenv$a, 2) expect_equal(pkgenv$b, 1) expect_equal(pkgenv$c, 2) # =================================================================== # Loading again without reset won't change a, b, and c in the # namespace env, and also shouldn't trigger onload or onattach. But # the existing namespace values will be copied over to the package # environment load_all("testLoadHooks", reset = FALSE) # Shouldn't form new environments expect_identical(nsenv, ns_env("testLoadHooks")) expect_identical(pkgenv, pkg_env("testLoadHooks")) # namespace and package env values should be the same expect_equal(nsenv$a, 2) expect_equal(nsenv$b, 2) expect_equal(nsenv$c, 1) expect_equal(pkgenv$a, 2) expect_equal(pkgenv$b, 2) expect_equal(pkgenv$c, 1) # =================================================================== # With reset=TRUE, there should be new package and namespace # environments, and the values should be the same as the first # load_all. load_all("testLoadHooks", reset = TRUE) nsenv2 <- ns_env("testLoadHooks") pkgenv2 <- pkg_env("testLoadHooks") # Should form new environments expect_false(identical(nsenv, nsenv2)) expect_false(identical(pkgenv, pkgenv2)) # Values should be same as first time expect_equal(nsenv2$a, 2) expect_equal(nsenv2$b, 2) expect_equal(nsenv2$c, 1) expect_equal(pkgenv2$a, 2) expect_equal(pkgenv2$b, 1) expect_equal(pkgenv2$c, 2) unload("testLoadHooks") # =================================================================== # Unloading and reloading should create new environments and same # values as first time load_all("testLoadHooks") nsenv3 <- ns_env("testLoadHooks") pkgenv3 <- pkg_env("testLoadHooks") # Should form new environments expect_false(identical(nsenv, nsenv3)) expect_false(identical(pkgenv, pkgenv3)) # Values should be same as first time expect_equal(nsenv3$a, 2) expect_equal(nsenv3$b, 2) expect_equal(nsenv3$c, 1) expect_equal(pkgenv3$a, 2) expect_equal(pkgenv3$b, 1) expect_equal(pkgenv3$c, 2) unload("testLoadHooks") }) test_that("onUnload", { load_all("testLoadHooks") # The onUnload function in testLoadHooks increments this variable .GlobalEnv$.__testLoadHooks__ <- 1 unload("testLoadHooks") expect_equal(.GlobalEnv$.__testLoadHooks__, 2) # Clean up rm(".__testLoadHooks__", envir = .GlobalEnv) }) pkgload/tests/testthat/test-dll.r0000644000176200001440000000715513361365120016620 0ustar liggesuserscontext("Compiled DLLs") test_that("unload() unloads DLLs from packages loaded with library()", { # Make a temp lib directory to install test package into old_libpaths <- .libPaths() tmp_libpath = file.path(tempdir(), "devtools_test") if (!dir.exists(tmp_libpath)) dir.create(tmp_libpath) .libPaths(c(tmp_libpath, .libPaths())) # Reset the libpath on exit on.exit(.libPaths(old_libpaths), add = TRUE) # Install package install.packages(test_path("testDllLoad"), repos = NULL, type = "source", INSTALL_opts = "--no-multiarch", quiet = TRUE) expect_true(require(testDllLoad)) # Check that it's loaded properly, by running a function from the package. # nulltest() calls a C function which returns null. expect_true(is.null(nulltest())) # DLL should be listed in .dynLibs() dynlibs <- vapply(.dynLibs(), `[[`, "name", FUN.VALUE = character(1)) expect_true(any(grepl("testDllLoad", dynlibs))) unload("testDllLoad") # DLL should not be listed in .dynLibs() dynlibs <- vapply(.dynLibs(), `[[`, "name", FUN.VALUE = character(1)) expect_false(any(grepl("testDllLoad", dynlibs))) # Clean out compiled objects pkgbuild::clean_dll("testDllLoad") }) test_that("load_all() compiles and loads DLLs", { pkgbuild::clean_dll("testDllLoad") load_all("testDllLoad", reset = TRUE, quiet = TRUE) # Check that it's loaded properly, by running a function from the package. # nulltest() calls a C function which returns null. expect_true(is.null(nulltest())) # DLL should be listed in .dynLibs() dynlibs <- vapply(.dynLibs(), `[[`, "name", FUN.VALUE = character(1)) expect_true(any(grepl("testDllLoad", dynlibs))) unload("testDllLoad") # DLL should not be listed in .dynLibs() dynlibs <- vapply(.dynLibs(), `[[`, "name", FUN.VALUE = character(1)) expect_false(any(grepl("testDllLoad", dynlibs))) # Loading again, and reloading # Should not re-compile (don't have a proper test for this) load_all("testDllLoad", quiet = TRUE) expect_true(is.null(nulltest())) # load_all when already loaded # Should not re-compile (don't have a proper test for this) load_all("testDllLoad", quiet = TRUE) expect_true(is.null(nulltest())) # Should re-compile (don't have a proper test for this) load_all("testDllLoad", recompile = TRUE, quiet = TRUE) expect_true(is.null(nulltest())) unload("testDllLoad") # Clean out compiled objects pkgbuild::clean_dll("testDllLoad") }) test_that("Specific functions from DLLs listed in NAMESPACE can be called", { load_all("testDllLoad", quiet = TRUE) # nulltest() uses the calling convention: # .Call("null_test", PACKAGE = "testDllLoad") expect_true(is.null(nulltest())) # nulltest2() uses a specific C function listed in NAMESPACE, null_test2 # null_test2 is an object in the packg_env # It uses this calling convention: # .Call(null_test2) expect_true(is.null(nulltest2())) nt2 <- ns_env("testDllLoad")$null_test2 expect_s3_class(nt2, "NativeSymbolInfo") expect_equal(nt2$name, "null_test2") unload("testDllLoad") # Clean out compiled objects pkgbuild::clean_dll("testDllLoad") }) test_that("load_all() can compile and load DLLs linked to Rcpp", { pkgbuild::clean_dll("testDllRcpp") load_all("testDllRcpp", reset = TRUE, quiet = TRUE) # Check that it's loaded properly by calling the hello world function # which returns a list expect_true(is.list(rcpp_hello_world())) # Check whether attribute compilation occurred and that exported # names are available from load_all expect_true(rcpp_test_attributes()) # Unload and clean out compiled objects unload("testDllRcpp") pkgbuild::clean_dll("testDllRcpp") }) pkgload/tests/testthat/test-imports.r0000644000176200001440000000327213261160715017540 0ustar liggesuserscontext("Imports") test_that("Imported objects are copied to package environment", { load_all("testNamespace") # This package imports the whole 'compiler' package, bitops::bitAnd, and # bitops::bitOr. imp_env <- imports_env("testNamespace") # cmpfun is exported from compiler, so it should be in imp_env expect_identical(imp_env$cmpfun, compiler::cmpfun) # cmpSpecial is NOT exported from compiler, so it should not be in imp_env expect_true(exists("cmpSpecial", asNamespace("compiler"))) expect_false(exists("cmpSpecial", imp_env)) # 'bitAnd' is a single object imported specifically from bitops expect_true(exists("bitAnd", imp_env)) # 'bitFlip' is not imported from bitops expect_false(exists("bitFlip", imp_env)) unload("testNamespace") # Suppress warning from compiler for R 3.4 and above suppressWarnings(unload("compiler")) unload("bitops") }) test_that("Imported objects are be re-exported", { load_all("testNamespace", export_imports = FALSE) # bitAnd is imported and re-exported expect_identical(bitAnd, bitops::bitAnd) # bitOr is imported but not re-exported expect_false(exists("bitOr", .GlobalEnv)) unload("testNamespace") unload("compiler") unload("bitops") # Same as previous, but with export_all = FALSE load_all("testNamespace", export_all = FALSE) expect_identical(bitAnd, bitops::bitAnd) expect_false(exists("bitOr", .GlobalEnv)) unload("testNamespace") unload("compiler") unload("bitops") # If exports_imports = TRUE all imports are exported load_all("testNamespace", export_imports = TRUE) expect_true(exists("bitOr", .GlobalEnv)) # This is from the import(compiler) expect_true(exists("compile", .GlobalEnv)) }) pkgload/tests/testthat/testDependMissing/0000755000176200001440000000000013261155170020327 5ustar liggesuserspkgload/tests/testthat/testDependMissing/R/0000755000176200001440000000000013010373512020522 5ustar liggesuserspkgload/tests/testthat/testDependMissing/R/a.r0000644000176200001440000000000713010373512021122 0ustar liggesusersa <- 1 pkgload/tests/testthat/testDependMissing/DESCRIPTION0000644000176200001440000000035413261155170022037 0ustar liggesusersPackage: testDependMissing Title: Tools to make developing R code easier License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 Depends: bitops, R Collate: a.r b.r pkgload/tests/testthat/testData/0000755000176200001440000000000013141335465016453 5ustar liggesuserspkgload/tests/testthat/testData/NAMESPACE0000644000176200001440000000002713010373512017657 0ustar liggesusersexport(sysdata_export) pkgload/tests/testthat/testData/data/0000755000176200001440000000000013010373512017352 5ustar liggesuserspkgload/tests/testthat/testData/data/a.rda0000644000176200001440000000007313010373512020262 0ustar liggesusers r0b```b`bf H020pD b`(+L8pkgload/tests/testthat/testData/data/b.r0000644000176200001440000000000713010373512017753 0ustar liggesusersb <- 2 pkgload/tests/testthat/testData/R/0000755000176200001440000000000013010373512016642 5ustar liggesuserspkgload/tests/testthat/testData/R/sysdata.rda0000644000176200001440000000013013010373512020774 0ustar liggesusers r0b```b`gf`b2Y# '+,NI,IO(/*d8E Lu^~5vpkgload/tests/testthat/testData/DESCRIPTION0000644000176200001440000000026713141335465020166 0ustar liggesusersPackage: testData Title: Tools to make developing R code easier License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 pkgload/tests/testthat/testS4export/0000755000176200001440000000000013141335465017332 5ustar liggesuserspkgload/tests/testthat/testS4export/NAMESPACE0000644000176200001440000000003713010373512020537 0ustar liggesusersexportClasses(class_to_export) pkgload/tests/testthat/testS4export/R/0000755000176200001440000000000013357721432017535 5ustar liggesuserspkgload/tests/testthat/testS4export/R/all.r0000644000176200001440000000007613357721432020473 0ustar liggesuserssetClass("foo") setClass('class_to_export', contains = "foo") pkgload/tests/testthat/testS4export/DESCRIPTION0000644000176200001440000000053613141335465021044 0ustar liggesusersPackage: testS4export Title: reproduce S4 export bug with devtools Version: 0.1 Description: reproduce S4 export bug with devtools Author: Karl Forner Maintainer: Karl Forner Depends: R (>= 2.15) Imports: methods Suggests: testthat (>= 0.7.1.99), License: GPL (>= 2) Collate: all.r pkgload/tests/testthat/test-metadata.r0000644000176200001440000000264613010373512017620 0ustar liggesuserscontext("Metadata") test_that("devtools metadata for load hooks", { # testLoadHooks test package has .onLoad and .onAttach load_all("testLoadHooks") md <- dev_meta("testLoadHooks") expect_true(md$.onLoad) expect_true(md$.onAttach) unload("testLoadHooks") # testNamespace test package doesn't have .onLoad and .onAttach load_all("testNamespace") md <- dev_meta("testNamespace") expect_false(exists("onLoad", envir = md)) expect_false(exists("onAttach", envir = md)) unload("testNamespace") }) test_that("NULL metadata for non-devtools-loaded packages", { expect_true(is.null(dev_meta("stats"))) }) test_that("dev_packages() lists devtools-loaded packages", { expect_false(any(c("testNamespace", "testLoadHooks") %in% dev_packages())) expect_false("testNamespace" %in% dev_packages()) expect_false("testLoadHooks" %in% dev_packages()) load_all("testNamespace") expect_true("testNamespace" %in% dev_packages()) expect_false("testLoadHooks" %in% dev_packages()) load_all("testLoadHooks") expect_true("testNamespace" %in% dev_packages()) expect_true("testLoadHooks" %in% dev_packages()) unload("testNamespace") expect_false("testNamespace" %in% dev_packages()) expect_true("testLoadHooks" %in% dev_packages()) unload("testLoadHooks") expect_false("testNamespace" %in% dev_packages()) expect_false("testLoadHooks" %in% dev_packages()) expect_false("stats" %in% dev_packages()) }) pkgload/tests/testthat/testCollateAbsent/0000755000176200001440000000000013141335465020322 5ustar liggesuserspkgload/tests/testthat/testCollateAbsent/R/0000755000176200001440000000000013010373512020511 5ustar liggesuserspkgload/tests/testthat/testCollateAbsent/R/b.r0000644000176200001440000000000613010373512021111 0ustar liggesusersa <- 2pkgload/tests/testthat/testCollateAbsent/R/a.r0000644000176200001440000000000613010373512021110 0ustar liggesusersa <- 1pkgload/tests/testthat/testCollateAbsent/R/c.r0000644000176200001440000000000613010373512021112 0ustar liggesusersa <- 3pkgload/tests/testthat/testCollateAbsent/DESCRIPTION0000644000176200001440000000030013141335465022021 0ustar liggesusersPackage: testCollateAbsent Title: Tools to make developing R code easier License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 pkgload/tests/testthat/test-examples.R0000644000176200001440000000123713141337161017616 0ustar liggesuserscontext("examples") test_that("default run_example ignores donttest and dontrun ", { env <- run_example(test_path("test-examples.Rd"), quiet = TRUE) expect_equal(env$a, 1) }) test_that("run donttest when requested", { env <- run_example(test_path("test-examples.Rd"), test = TRUE, quiet = TRUE) expect_equal(env$a, 2) }) test_that("run dontrun when requested", { env <- run_example(test_path("test-examples.Rd"), run = TRUE, quiet = TRUE) expect_equal(env$a, 3) }) test_that("can run example package", { load_all(test_path("testHelp")) on.exit(unload(test_path("testHelp"))) env <- dev_example("foofoo", quiet = TRUE) expect_equal(env$a, 101) }) pkgload/tests/testthat/testLoadHelpers/0000755000176200001440000000000013347022214017775 5ustar liggesuserspkgload/tests/testthat/testLoadHelpers/tests/0000755000176200001440000000000013315220651021137 5ustar liggesuserspkgload/tests/testthat/testLoadHelpers/tests/testthat.R0000644000176200001440000000011213272175216023124 0ustar liggesuserslibrary(testthat) library(testLoadHelpers) test_check("testLoadHelpers") pkgload/tests/testthat/testLoadHelpers/tests/testthat/0000755000176200001440000000000013365666713023021 5ustar liggesuserspkgload/tests/testthat/testLoadHelpers/tests/testthat/helpers.R0000644000176200001440000000004713272205644024574 0ustar liggesusersfoo <- 1 head_mtcars <- head(mtcars2) pkgload/tests/testthat/testLoadHelpers/tests/testthat/test-foo.R0000644000176200001440000000012713272175216024672 0ustar liggesuserscontext("test-foo.R") test_that("multiplication works", { expect_equal(2 * 2, 4) }) pkgload/tests/testthat/testLoadHelpers/NAMESPACE0000644000176200001440000000005613272175466021234 0ustar liggesusers# Generated by roxygen2: do not edit by hand pkgload/tests/testthat/testLoadHelpers/data/0000755000176200001440000000000013315220651020706 5ustar liggesuserspkgload/tests/testthat/testLoadHelpers/data/mtcars2.rda0000644000176200001440000000247013272175414022764 0ustar liggesusersBZh91AY&SY %qw?B4L@Y`aKs/`jUF2DhS1O 2zPi ShCMP4=CGBh)G= 46=M=@dMHySGzz56A44d444z 2`&0Lb0h 2Hbh=F4MC@@ {'m;zkz^6){[d`(h[EUB%)K9gt+=C*n:Zw[np Z*0M! 4 &jT 6Q!3!LMZ&N*Bv$3~%I o G;Kq7Sՙ)A'kFe/4%yEzR"!d@0""kAc#R)) aalI&,1U * Q1!7Z=dahB `#T=B:D/XZEJځ `-XT8JɗM ʀmpq$&˒gI`#MS@2b$0|\ k#Ԅ0*JȢ&1Xf$h_F(gP0mZ.Py%{iyz_/Gy7|ELQ{7M P%( 9[k^<T^ps^ݭ~"1 kcp8(D=S L-Q ZZr[ tXɧH#e#hh$*FXJ- d$uE(uYBuQ"KnL+Pu]k5SH_WjS[bIҾq\dJ 1( z؄b-r 1g yB;-Я"7K,-<޵E0mu@}.J8:PlCxu ,ϰ(+LJ$ϬQnz 8~i <B(K.u?2\_= 3DC}n[_yUi(7<5P@3I="ɘ*B5S`Ca UaOKdbrE8P %pkgload/tests/testthat/testLoadHelpers/R/0000755000176200001440000000000013315220651020176 5ustar liggesuserspkgload/tests/testthat/testLoadHelpers/R/a.r0000644000176200001440000000001113272205574020602 0ustar liggesusersbaz <- 1 pkgload/tests/testthat/testLoadHelpers/DESCRIPTION0000644000176200001440000000043213272177020021505 0ustar liggesusersPackage: testLoadHelpers Title: Tools to make developing R code easier License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 Collate: a.r Suggests: testthat RoxygenNote: 6.0.1.9000 Encoding: UTF-8 LazyData: true pkgload/tests/testthat/testCollateOrder/0000755000176200001440000000000013141335711020153 5ustar liggesuserspkgload/tests/testthat/testCollateOrder/NAMESPACE0000644000176200001440000000003113010373512021360 0ustar liggesusersexportPattern("^[^\\.]") pkgload/tests/testthat/testCollateOrder/R/0000755000176200001440000000000013010373512020350 5ustar liggesuserspkgload/tests/testthat/testCollateOrder/R/b.r0000644000176200001440000000000713010373512020751 0ustar liggesusersa <- 2 pkgload/tests/testthat/testCollateOrder/R/a.r0000644000176200001440000000003013010373512020744 0ustar liggesusers#' @include b.r a <- 1 pkgload/tests/testthat/testCollateOrder/DESCRIPTION0000644000176200001440000000030113141335711021653 0ustar liggesusersPackage: testCollateOrder Title: Tools to make developing R code easier License: GPL-2 Description: Author: Geoff Maintainer: Geoff Version: 0.1 pkgload/tests/testthat/test-depend.r0000644000176200001440000000366513261155222017305 0ustar liggesuserscontext("Dependencies") test_that("Warned about dependency versions", { # Should give a warning about grid version expect_warning(load_all("testImportVersion"), "Need grid >=") unload("testImportVersion") # TODO: Add check for NOT giving a warning about compiler version # Not possible with testthat? }) test_that("Error on missing dependencies", { # Should give a warning about missing package expect_error(regexp = "Dependency package[(]s[)] 'missingpackage' not available", expect_warning(regexp = "missingpackage not available", load_all("testImportMissing"))) # Loading process will be partially done; unload it unload("testImportMissing") }) test_that("Packages in depends are required", { load_all("testDependMissing") expect_true("package:bitops" %in% search()) unload("testDependMissing") detach("package:bitops", unload = TRUE) }) test_that("Parse dependencies", { deps <- parse_deps("\nhttr (< 2.1),\nRCurl (>= 3),\nutils (== 2.12.1),\ntools,\nR (>= 2.10),\nmemoise") expect_equal(nrow(deps), 5) expect_false("R" %in% deps$name) expect_equal(deps$compare, c("<", ">=", "==", NA, NA)) expect_equal(deps$version, c("2.1", "3", "2.12.1", NA, NA)) # Invalid version specifications expect_error(parse_deps("\nhttr (< 2.1),\nRCurl (3.0)")) expect_error(parse_deps("\nhttr (< 2.1),\nRCurl ( 3.0)")) expect_error(parse_deps("\nhttr (< 2.1),\nRCurl (==3.0)")) expect_error(parse_deps("\nhttr (< 2.1),\nRCurl (==3.0 )")) expect_error(parse_deps("\nhttr (< 2.1),\nRCurl ( ==3.0)")) # This should be OK (no error) deps <- parse_deps("\nhttr (< 2.1),\nRCurl (== 3.0.1)") expect_equal(deps$compare, c("<", "==")) expect_equal(deps$version, c("2.1", "3.0.1")) }) test_that("Declared dependencies are added to .Depends object", { load_all("testDependsExists") expect_equal(get(".Depends", "package:testDependsExists", inherits = FALSE), "httr") unload("testDependsExists") }) pkgload/tests/testthat/test-load-collate.r0000644000176200001440000000106113241561510020371 0ustar liggesuserscontext("Load: collate") test_that("If collate absent, load in alphabetical order", { load_all("testCollateAbsent") expect_equal(a, 3) unload("testCollateAbsent") }) test_that("Warned about files missing from collate, but they're still loaded", { expect_message(load_all("testCollateMissing"), "a.r") expect_equal(a, 1) expect_equal(b, 2) unload("testCollateMissing") }) test_that("Extra files in collate don't error, but warn", { expect_message(load_all("testCollateExtra"), "b.r") expect_equal(a, 1) unload("testCollateExtra") }) pkgload/tests/testthat/test-shim.r0000644000176200001440000000745713010373512017005 0ustar liggesuserscontext("shim") # Utility functions ----------------------------- # Take file paths and split them into pieces expand_path <- function(path) { strsplit(path, .Platform$file.sep) } # Return the last n elements of vector x last_n <- function(x, n = 1) { len <- length(x) x[(len-n+1):len] } # Tests ----------------------------------------- test_that("system.file returns correct values when used with load_all", { load_all("testShim") shim_ns <- ns_env("testShim") # The devtools::system.file function should return modified values. files <- shim_system.file(c("A.txt", "B.txt", "C.txt", "D.txt"), package = "testShim") files <- expand_path(files) expect_true(all(last_n(files[[1]], 3) == c("testShim", "inst", "A.txt"))) expect_true(all(last_n(files[[2]], 3) == c("testShim", "inst", "B.txt"))) # Note that C.txt wouldn't be returned by base::system.file (see comments # in shim_system.file for explanation) expect_true(all(last_n(files[[3]], 2) == c("testShim", "C.txt"))) # D.txt should be dropped expect_equal(length(files), 3) # If all files are not present, return "" files <- shim_system.file("nonexistent", package = "testShim") expect_equal(files, "") # Test packages loaded the usual way - should just pass through to # base::system.file expect_identical(base::system.file("Meta", "Rd.rds", package = "stats"), shim_system.file("Meta", "Rd.rds", package = "stats")) expect_identical(base::system.file("INDEX", package = "stats"), shim_system.file("INDEX", package = "stats")) expect_identical(base::system.file("nonexistent", package = "stats"), shim_system.file("nonexistent", package = "stats")) unload("testShim") }) test_that("shimmed system.file respects mustWork", { load_all("testShim") find_missing <- function(mustWork) { shim_system.file("missing.txt", package = "testShim", mustWork = mustWork) } expect_equal(find_missing(FALSE), "") expect_error(find_missing(TRUE), "No file found") }) test_that("Shimmed system.file returns correct values when used with load_all", { load_all("testShim") shim_ns <- ns_env("testShim") # Make sure the version of system.file inserted into the namespace's imports # is the same as devtools::system.file expect_identical(get("system.file", envir = shim_ns), shim_system.file) # Another check expect_identical(get_system.file(), shim_system.file) unload("testShim") }) test_that("Replacement system.file returns correct values when installed", { # This set of tests is mostly a sanity check - it doesn't use the special # version of system.file, but it's useful to make sure we know what to look # for in the other tests. # Make a temp lib directory to install test package into old_libpaths <- .libPaths() tmp_libpath = file.path(tempdir(), "devtools_test") if (!dir.exists(tmp_libpath)) dir.create(tmp_libpath) .libPaths(c(tmp_libpath, .libPaths())) install.packages(test_path("testShim"), repos = NULL, type = "source", quiet = TRUE) expect_true(require(testShim)) # The special version of system.file shouldn't exist - this get() will fall # through to the base namespace expect_identical(get("system.file", pos = asNamespace("testShim")), base::system.file) # Test within package testShim files <- get_system.file()(c("A.txt", "B.txt", "C.txt", "D.txt"), package = "testShim") files <- expand_path(files) expect_true(all(last_n(files[[1]], 2) == c("testShim", "A.txt"))) expect_true(all(last_n(files[[2]], 2) == c("testShim", "B.txt"))) expect_equal(length(files), 2) # Third and fourth should be dropped # If all files are not present, return "" files <- get_system.file()("nonexistent", package = "testShim") expect_equal(files, "") detach("package:testShim", unload = TRUE) # Reset the libpath .libPaths(old_libpaths) }) pkgload/tests/testthat/testShim/0000755000176200001440000000000013144323774016505 5ustar liggesuserspkgload/tests/testthat/testShim/A.txt0000644000176200001440000000001413010373512017404 0ustar liggesusersfile /A.txt pkgload/tests/testthat/testShim/inst/0000755000176200001440000000000013010373512017445 5ustar liggesuserspkgload/tests/testthat/testShim/inst/A.txt0000644000176200001440000000002013010373512020356 0ustar liggesusersfile inst/A.txt pkgload/tests/testthat/testShim/inst/B.txt0000644000176200001440000000001713010373512020365 0ustar liggesusersfile inst/B.txtpkgload/tests/testthat/testShim/NAMESPACE0000644000176200001440000000003013010373512017700 0ustar liggesusersexport(get_system.file) pkgload/tests/testthat/testShim/R/0000755000176200001440000000000013010373512016671 5ustar liggesuserspkgload/tests/testthat/testShim/R/a.r0000644000176200001440000000045513010373512017300 0ustar liggesusersa <- 1 # When this package is loaded with load_all, devtools should add a # replacement system.file function. # When the package is loaded with load_all, this returns devtools::system.file # When installed and loaded, this returns base:system.file. get_system.file <- function(...) { system.file } pkgload/tests/testthat/testShim/DESCRIPTION0000644000176200001440000000037213144323774020215 0ustar liggesusersPackage: testShim Title: Tools to make developing R code easier License: GPL-2 Description: This package is for testing the devtools shim system. Author: Hadley Maintainer: Hadley Version: 0.1 Collate: a.r pkgload/tests/testthat/testShim/C.txt0000644000176200001440000000001413010373512017406 0ustar liggesusersfile /C.txt pkgload/tests/testthat/test-data.r0000644000176200001440000000466313010373512016752 0ustar liggesuserscontext("Data") test_that("data available when lazydata not true", { load_all("testData") # a and b are in data/ and shouldn't be available yet # sysdata_export and sysdata_nonexport are in R/sysdata.rda, and should be available expect_false(exists("a")) expect_false(exists("b")) expect_equal(sysdata_export, 3) expect_equal(sysdata_nonexport, 4) # Load the data objects (into the local environment) data(a, envir = environment()) data(b, envir = environment()) expect_equal(a, 1) expect_equal(b, 2) unload("testData") # Objects loaded with data() should still be available expect_equal(a, 1) expect_equal(b, 2) # Objects loaded in sysdata.rda shouldn't be available expect_false(exists("sysdata_export")) expect_false(exists("sysdata_nonexport")) }) test_that("data available when lazydata is true", { load_all("testDataLazy") # a and b are in data/ and should be available because of lazydata # sysdata_export and sysdata_nonexport are in R/sysdata.rda, and should be available expect_equal(a, 1) expect_equal(b, 2) expect_equal(sysdata_export, 3) expect_equal(sysdata_nonexport, 4) unload("testDataLazy") }) test_that("data available when lazydata not true, and export_all is FALSE", { load_all("testData", export_all = FALSE) # a and b are in data/ and shouldn't be available yet # sysdata_export is exported; sysdata_nonexport isn't expect_false(exists("a")) expect_false(exists("b")) expect_equal(sysdata_export, 3) expect_false(exists("sysdata_nonexport")) # Load the data objects (into the local environment) data(a, envir = environment()) data(b, envir = environment()) expect_equal(a, 1) expect_equal(b, 2) # Shouldn't be able to load objects in R/sysdata.rda with data() expect_warning(data(sysdata_export, envir = environment())) expect_false(exists("sysdata_nonexport")) unload("testData") }) test_that("data available when lazydata is true, and export_all is FALSE", { load_all("testDataLazy", export_all = FALSE) # a and b are in data/ and should be available because of lazydata # sysdata_export is exported; sysdata_nonexport isn't expect_equal(a, 1) expect_equal(b, 2) expect_equal(sysdata_export, 3) expect_false(exists("sysdata_nonexport")) # Shouldn't be able to load objects in R/sysdata.rda with data() expect_warning(data(sysdata_export, envir = environment())) expect_false(exists("sysdata_nonexport")) unload("testDataLazy") }) pkgload/tests/testthat/testHooks/0000755000176200001440000000000013144323774016670 5ustar liggesuserspkgload/tests/testthat/testHooks/R/0000755000176200001440000000000013010373512017054 5ustar liggesuserspkgload/tests/testthat/testHooks/R/a.r0000644000176200001440000000041313010373512017455 0ustar liggesusersrecord_use <- function(hook) { function(...) { h <- globalenv()$hooks h$events <- c(h$events, hook) } } .onLoad <- record_use("pkg_load") .onUnload <- record_use("pkg_unload") .onAttach <- record_use("pkg_attach") .onDetach <- record_use("pkg_detach") pkgload/tests/testthat/testHooks/DESCRIPTION0000644000176200001440000000030513144323774020374 0ustar liggesusersPackage: testHooks Title: Tools to make developing R code easier License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 Collate: a.r pkgload/tests/testthat/test-extraction.R0000644000176200001440000000220213365662337020167 0ustar liggesuserscontext("extract_lang") f <- function(x) { a <- 1:10 for (i in seq_along(a)) { print(i) } } test_that("extract_lang issues warning if nothing found", { expect_warning(extract_lang(body(f), comp_lang, quote(j)), "devtools is incompatible") }) test_that("extract_lang and comp_lang finds full statements", { expect_equal(extract_lang(body(f), comp_lang, quote(a <- 1:10)), quote(a <- 1:10)) }) test_that("extract_lang and comp_lang find child calls", { expect_equal(extract_lang(body(f), comp_lang, quote(seq_along(a))), quote(seq_along(a))) }) test_that("extract_lang and comp_lang finds partial statements", { expect_equal(extract_lang(body(f), comp_lang, quote(a <- NULL), 1:2), quote(a <- 1:10)) }) test_that("extract_lang and comp_lang finds partial statements from for conditionals", { expect_equal(extract_lang(body(f), comp_lang, quote(for (i in seq_along(a)) NULL), 1:3), quote(for (i in seq_along(a)) { print(i) })) }) test_that("modify_lang modifies properly", { expect_equal(modify_lang(quote(a <- 1:10), function(x) if (comp_lang(x, quote(a))) quote(b) else x), quote(b <- 1:10)) }) pkgload/tests/testthat/testHelp/0000755000176200001440000000000013141335465016472 5ustar liggesuserspkgload/tests/testthat/testHelp/NAMESPACE0000644000176200001440000000011613102664373017707 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(foofoo) export(testHelp) pkgload/tests/testthat/testHelp/R/0000755000176200001440000000000013102664373016673 5ustar liggesuserspkgload/tests/testthat/testHelp/R/foofoo.r0000644000176200001440000000054013102664373020344 0ustar liggesusers#' Test function for help #' #' The purpose of this function is to test out \code{help} and \code{?} from #' devtools. #' #' @export #' @examples #' a <- 101 foofoo <- function() "You called foofoo." #' testHelp: some title #' Some description "_PACKAGE" #' Function level help for testHelp #' #' @export testHelp <- function() "You called testHelp" pkgload/tests/testthat/testHelp/DESCRIPTION0000644000176200001440000000044313141335465020201 0ustar liggesusersPackage: testHelp Title: Tools to make developing R code easier License: GPL-2 Description: Test package for devtools help. Authors@R: c( person("Hadley", "Wickham", , "hadley@rstudio.com", role = c("aut", "cre")), person("RStudio", role = "cph") ) Version: 0.1 RoxygenNote: 6.0.1 pkgload/tests/testthat/testHelp/man/0000755000176200001440000000000013102664373017245 5ustar liggesuserspkgload/tests/testthat/testHelp/man/testHelp.Rd0000644000176200001440000000034713102664373021330 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/foofoo.r \name{testHelp} \alias{testHelp} \title{Function level help for testHelp} \usage{ testHelp() } \description{ Function level help for testHelp } pkgload/tests/testthat/testHelp/man/foofoo.Rd0000644000176200001440000000044013102664373021021 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/foofoo.r \name{foofoo} \alias{foofoo} \title{Test function for help} \usage{ foofoo() } \description{ The purpose of this function is to test out \code{help} and \code{?} from devtools. } \examples{ a <- 101 } pkgload/tests/testthat/testHelp/man/testHelp-package.Rd0000644000176200001440000000063613102664373022722 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/foofoo.r \docType{package} \name{testHelp-package} \alias{testHelp} \alias{testHelp-package} \title{testHelp: some title Some description} \description{ testHelp: some title Some description } \author{ \strong{Maintainer}: Hadley Wickham \email{hadley@rstudio.com} Other contributors: \itemize{ \item RStudio [copyright holder] } } pkgload/tests/testthat/testS4sort/0000755000176200001440000000000013144323774017003 5ustar liggesuserspkgload/tests/testthat/testS4sort/NAMESPACE0000644000176200001440000000004413010373512020203 0ustar liggesusersexportClass(A, B, C, D, E, F, G, H) pkgload/tests/testthat/testS4sort/R/0000755000176200001440000000000013010373512017167 5ustar liggesuserspkgload/tests/testthat/testS4sort/R/classes.r0000644000176200001440000000060713010373512021012 0ustar liggesusers## Define a graph of classes with complex inheritance pattern ## example taken from wikipedia: ## https://en.wikipedia.org/wiki/Topological_sorting#Examples setClass("A") setClass("B") setClass("C") setClassUnion("D", members = c("A", "B", "C")) setClass("E") setIs("B", "E") setClassUnion("F", members = c("D", "E")) setClass("G") setIs("D", "G") setClassUnion("H", members = c("C", "E")) pkgload/tests/testthat/testS4sort/DESCRIPTION0000644000176200001440000000041313144323774020507 0ustar liggesusersPackage: testS4sort Title: Test package for sorting S4 classes License: GPL (>= 2) Description: Author: Facundo Munoz Maintainer: Facundo Munoz Version: 0.1 Collate: 'classes.r' Imports: methods pkgload/tests/testthat/test-examples.Rd0000644000176200001440000000022413010373512017750 0ustar liggesusers\name{foo} \alias{foo} \title{foo} \usage{ foo() } \description{ } \examples{ a <- 1 \donttest{a <- 2} \dontrun{a <- 3} } \keyword{internal} pkgload/tests/testthat/testLoadDir/0000755000176200001440000000000013141335465017120 5ustar liggesuserspkgload/tests/testthat/testLoadDir/R/0000755000176200001440000000000013010373512017307 5ustar liggesuserspkgload/tests/testthat/testLoadDir/R/a.r0000644000176200001440000000003313010373512017706 0ustar liggesusersmessage("|", getwd(), "|") pkgload/tests/testthat/testLoadDir/DESCRIPTION0000644000176200001440000000030713141335465020626 0ustar liggesusersPackage: testLoadDir Title: Tools to make developing R code easier License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 Collate: a.r pkgload/tests/testthat/testCollateExtra/0000755000176200001440000000000013144323774020174 5ustar liggesuserspkgload/tests/testthat/testCollateExtra/R/0000755000176200001440000000000013010373512020360 5ustar liggesuserspkgload/tests/testthat/testCollateExtra/R/a.r0000644000176200001440000000000613010373512020757 0ustar liggesusersa <- 1pkgload/tests/testthat/testCollateExtra/DESCRIPTION0000644000176200001440000000032013144323774021675 0ustar liggesusersPackage: testCollateExtra Title: Tools to make developing R code easier License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 Collate: a.r b.r pkgload/tests/testthat/testImportMissing/0000755000176200001440000000000013144323774020411 5ustar liggesuserspkgload/tests/testthat/testImportMissing/R/0000755000176200001440000000000013010373512020575 5ustar liggesuserspkgload/tests/testthat/testImportMissing/R/a.r0000644000176200001440000000000713010373512021175 0ustar liggesusersa <- 1 pkgload/tests/testthat/testImportMissing/DESCRIPTION0000644000176200001440000000035513144323774022122 0ustar liggesusersPackage: testImportMissing Title: Tools to make developing R code easier License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 Imports: missingpackage Collate: a.r b.r pkgload/tests/testthat/testDataLazy/0000755000176200001440000000000013141335465017313 5ustar liggesuserspkgload/tests/testthat/testDataLazy/NAMESPACE0000644000176200001440000000002713010373512020517 0ustar liggesusersexport(sysdata_export) pkgload/tests/testthat/testDataLazy/data/0000755000176200001440000000000013010373512020212 5ustar liggesuserspkgload/tests/testthat/testDataLazy/data/a.rda0000644000176200001440000000007313010373512021122 0ustar liggesusers r0b```b`bf H020pD b`(+L8pkgload/tests/testthat/testDataLazy/data/b.r0000644000176200001440000000000713010373512020613 0ustar liggesusersb <- 2 pkgload/tests/testthat/testDataLazy/R/0000755000176200001440000000000013010373512017502 5ustar liggesuserspkgload/tests/testthat/testDataLazy/R/sysdata.rda0000644000176200001440000000013013010373512021634 0ustar liggesusers r0b```b`gf`b2Y# '+,NI,IO(/*d8E Lu^~5vpkgload/tests/testthat/testDataLazy/DESCRIPTION0000644000176200001440000000031213141335465021015 0ustar liggesusersPackage: testDataLazy Title: Tools to make developing R code easier License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 LazyData: true pkgload/tests/testthat/testS4import/0000755000176200001440000000000013141335465017323 5ustar liggesuserspkgload/tests/testthat/testS4import/NAMESPACE0000644000176200001440000000006213010373512020526 0ustar liggesusersimportClassesFrom(testS4export, class_to_export) pkgload/tests/testthat/testS4import/R/0000755000176200001440000000000013010373512017512 5ustar liggesuserspkgload/tests/testthat/testS4import/R/all.r0000644000176200001440000000006113010373512020442 0ustar liggesuserssetClass('derived', contains='class_to_export') pkgload/tests/testthat/testS4import/DESCRIPTION0000644000176200001440000000060213141335465021027 0ustar liggesusersPackage: testS4import Title: reproduce S4 import bug with devtools Version: 0.1 Description: reproduce S4 import bug with devtools. See testS4export Author: Karl Forner Maintainer: Karl Forner Depends: R (>= 2.15) Imports: methods, testS4export Suggests: testthat (>= 0.7.1.99), License: GPL (>= 2) Collate: all.r pkgload/tests/testthat/testDllLoad/0000755000176200001440000000000013141335465017115 5ustar liggesuserspkgload/tests/testthat/testDllLoad/src/0000755000176200001440000000000013357720017017704 5ustar liggesuserspkgload/tests/testthat/testDllLoad/src/null-test.c0000644000176200001440000000020113010373512021756 0ustar liggesusers#include #include SEXP null_test() { return R_NilValue; } SEXP null_test2() { return R_NilValue; } pkgload/tests/testthat/testDllLoad/NAMESPACE0000644000176200001440000000013413010373512020320 0ustar liggesusersuseDynLib(testDllLoad) useDynLib(testDllLoad,null_test2) export(nulltest) export(nulltest2) pkgload/tests/testthat/testDllLoad/R/0000755000176200001440000000000013010373512017304 5ustar liggesuserspkgload/tests/testthat/testDllLoad/R/a.r0000644000176200001440000000020213010373512017701 0ustar liggesusersa <- 1 nulltest <- function() { .Call("null_test", PACKAGE = "testDllLoad") } nulltest2 <- function() { .Call(null_test2) } pkgload/tests/testthat/testDllLoad/DESCRIPTION0000644000176200001440000000031413141335465020621 0ustar liggesusersPackage: testDllLoad Title: Test package for loading and unloading DLLs License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 Collate: a.r pkgload/tests/testthat/testLoadHooks/0000755000176200001440000000000013144323774017470 5ustar liggesuserspkgload/tests/testthat/testLoadHooks/R/0000755000176200001440000000000013010373512017654 5ustar liggesuserspkgload/tests/testthat/testLoadHooks/R/a.r0000644000176200001440000000136113010373512020260 0ustar liggesusersa <- 1 b <- 1 c <- 1 onload_lib <- "" onattach_lib <- "" .onLoad <- function(lib, pkg) { onload_lib <<- lib a <<- a + 1 } .onAttach <- function(lib, pkg) { onattach_lib <<- lib # Attempt to modify b in namespace. This should throw an error # in a real install+load because namespace is locked. But with # load_all, it will work because the namespace doesn't get locked. try(b <<- b + 1, silent = TRUE) # Now modify c in package environment env <- as.environment("package:testLoadHooks") env$c <- env$c + 1 } .onUnload <- function(libpath) { # Increment this variable if it exists in the global env if (exists(".__testLoadHooks__", .GlobalEnv)) { .GlobalEnv$.__testLoadHooks__ <- .GlobalEnv$.__testLoadHooks__ + 1 } } pkgload/tests/testthat/testLoadHooks/DESCRIPTION0000644000176200001440000000031113144323774021171 0ustar liggesusersPackage: testLoadHooks Title: Tools to make developing R code easier License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 Collate: a.r pkgload/tests/testthat/test-namespace.r0000644000176200001440000001056113261154651020000 0ustar liggesuserscontext("Namespace") # Is e an ancestor environment of x? is_ancestor_env <- function(e, x) { if (identical(e, x)) return(TRUE) else if (identical(x, emptyenv())) return(FALSE) else is_ancestor_env(e, parent.env(x)) } # Get parent environment n steps deep parent_env <- function(e, n = 1) { if (n == 0) e else parent_env(parent.env(e), n-1) } test_that("Loaded namespaces have correct version", { load_all("testNamespace") expect_identical(c(version="0.1"), getNamespaceVersion("testNamespace")) unload("testNamespace") }) test_that("Exported objects are visible from global environment", { # a is listed as an export in NAMESPACE, b is not. But with load_all(), # they should both be visible in the global env. load_all("testNamespace") expect_equal(a, 1) expect_equal(b, 2) unload("testNamespace") # With export_all = FALSE, only the listed export should be visible # in the global env. load_all("testNamespace", export_all = FALSE) expect_equal(a, 1) expect_false(exists("b")) unload("testNamespace") }) test_that("Missing exports don't result in error", { expect_warning(load_all("testMissingNsObject")) nsenv <- ns_env("testMissingNsObject") expect_equal(nsenv$a, 1) unload("testMissingNsObject") }) test_that("All objects are loaded into namespace environment", { load_all("testNamespace") nsenv <- ns_env("testNamespace") expect_equal(nsenv$a, 1) expect_equal(nsenv$b, 2) unload("testNamespace") }) test_that("All objects are copied to package environment", { load_all("testNamespace") pkgenv <- pkg_env("testNamespace") expect_equal(pkgenv$a, 1) expect_equal(pkgenv$b, 2) unload("testNamespace") # With export_all = FALSE, only the listed export should be copied load_all("testNamespace", export_all = FALSE) pkgenv <- pkg_env("testNamespace") expect_equal(pkgenv$a, 1) expect_false(exists("b", envir = pkgenv)) unload("testNamespace") }) test_that("Unloading and reloading a package works", { load_all("testNamespace") expect_equal(a, 1) # A load_all() again without unloading shouldn't change things load_all("testNamespace") expect_equal(a, 1) # Unloading should remove objects unload("testNamespace") expect_false(exists('a')) # Loading again should work load_all("testNamespace") expect_equal(a, 1) # Loading with reset should work load_all("testNamespace", reset = TRUE) expect_equal(a, 1) unload("testNamespace") }) test_that("Namespace, imports, and package environments have correct hierarchy", { load_all("testNamespace") pkgenv <- pkg_env("testNamespace") nsenv <- ns_env("testNamespace") impenv <- imports_env("testNamespace") expect_identical(parent_env(nsenv, 1), impenv) expect_identical(parent_env(nsenv, 2), .BaseNamespaceEnv) expect_identical(parent_env(nsenv, 3), .GlobalEnv) # pkgenv should be an ancestor of the global environment expect_true(is_ancestor_env(pkgenv, .GlobalEnv)) unload("testNamespace") }) test_that("unload() removes package environments from search", { load_all("testNamespace") pkgenv <- pkg_env("testNamespace") nsenv <- ns_env("testNamespace") unload("testNamespace") unload("compiler") unload("bitops") # Should report not loaded for package and namespace environments expect_false(is_attached("testNamespace")) expect_false(is_loaded("testNamespace")) # R's asNamespace function should error expect_error(asNamespace("testNamespace")) # pkgenv should NOT be an ancestor of the global environment # This is what makes the objects inaccessible from global env expect_false(is_ancestor_env(pkgenv, .GlobalEnv)) # Another check of same thing expect_false(pkg_env_name("testNamespace") %in% search()) }) test_that("Environments have the correct attributes", { load_all("testNamespace") pkgenv <- pkg_env("testNamespace") impenv <- imports_env("testNamespace") # as.environment finds the same package environment expect_identical(pkgenv, as.environment("package:testNamespace")) # Check name attribute of package environment expect_identical(attr(pkgenv, "name"), "package:testNamespace") # Check path attribute of package environment wd <- normalizePath("testNamespace", winslash = "/") expect_identical(wd, attr(pkgenv, "path")) # Check name attribute of imports environment expect_identical(attr(impenv, "name"), "imports:testNamespace") unload("testNamespace") }) pkgload/tests/testthat/test-s4-export.r0000644000176200001440000000133713357720452017716 0ustar liggesuserscontext("s4-export") test_that("importing an S4 exported by another pkg with export_all = FALSE", { load_all("testS4export", export_all = FALSE) # this used to crash with error: # class "class_to_export" is not exported by 'namespace:testS4export' load_all("testS4import", export_all = FALSE) expect_true(isClassDef(getClass("derived"))) load_all("testS4import", export_all = FALSE) cl <- getClass("derived") expect_true(isClassDef(cl)) expect_is(cl@contains$class_to_export, "SClassExtension") expect_equal(cl@contains$class_to_export@distance, 1) expect_is(cl@contains$foo, "SClassExtension") expect_equal(cl@contains$foo@distance, 2) # cleanup unload('testS4import') unload('testS4export') }) pkgload/tests/testthat/testNamespace/0000755000176200001440000000000013144323774017501 5ustar liggesuserspkgload/tests/testthat/testNamespace/NAMESPACE0000644000176200001440000000013513010373512020702 0ustar liggesusersexport(a) export(bitAnd) import(compiler) importFrom(bitops,bitAnd) importFrom(bitops,bitOr) pkgload/tests/testthat/testNamespace/R/0000755000176200001440000000000013010373512017665 5ustar liggesuserspkgload/tests/testthat/testNamespace/R/b.r0000644000176200001440000000000713010373512020266 0ustar liggesusersb <- 2 pkgload/tests/testthat/testNamespace/R/a.r0000644000176200001440000000000713010373512020265 0ustar liggesusersa <- 1 pkgload/tests/testthat/testNamespace/DESCRIPTION0000644000176200001440000000035713144323774021214 0ustar liggesusersPackage: testNamespace Title: Tools to make developing R code easier License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 Imports: compiler, bitops Collate: a.r b.r pkgload/tests/testthat/testDependsExists/0000755000176200001440000000000013241561510020355 5ustar liggesuserspkgload/tests/testthat/testDependsExists/DESCRIPTION0000644000176200001440000000037713241561510022072 0ustar liggesusersPackage: testDependsExists Title: Packages in Depends are assigned to .Depends object of package environment License: GPL-2 Description: Author: Yiufung Maintainer: Yiufung Version: 0.1 Depends: R, httr pkgload/tests/testthat/test-load.r0000644000176200001440000000110113315221011016732 0ustar liggesuserscontext("Loading") test_that("Package root and subdirectory is working directory when loading", { expect_message(load_all("testLoadDir"), "[|].*/testLoadDir[|]") expect_message(load_all(file.path("testLoadDir", "R")), "[|].*/testLoadDir[|]") }) test_that("helpers are available after load_all", { load_all("testLoadHelpers") # object defined R/ expect_equal(baz, 1) # object defined in a helper expect_equal(foo, 1) # object definde in helper, referencing lazy data object mtcars2 expect_equal(head_mtcars, head(mtcars2)) unload("testLoadHelpers") }) pkgload/tests/testthat/test-help.r0000644000176200001440000000574613315453225017004 0ustar liggesuserscontext("help") test_that("shim_help behaves the same as utils::help for non-devtools-loaded packages", { # stats wasn't loaded with devtools. There are many combinations of calling # with quotes and without; make sure they're the same both ways. Need to index # in using [1] to drop attributes for which there are unimportant differences. expect_identical(shim_help(lm)[1], utils::help(lm)[1]) expect_identical(shim_help(lm, stats)[1], utils::help(lm, stats)[1]) expect_identical(shim_help(lm, 'stats')[1], utils::help(lm, 'stats')[1]) expect_identical(shim_help('lm')[1], utils::help('lm')[1]) expect_identical(shim_help('lm', stats)[1], utils::help('lm', stats)[1]) expect_identical(shim_help('lm', 'stats')[1], utils::help('lm', 'stats')[1]) expect_identical(shim_help(, "stats")[1], utils::help(, "stats")[1]) # Works for :: and ::: as well (#72) expect_identical(shim_help("::")[1], utils::help("::")[1]) expect_identical(shim_help(":::")[1], utils::help(":::")[1]) }) test_that("shim_help behaves the same as utils::help for nonexistent objects", { expect_equal(length(shim_help(foofoo)), 0) expect_equal(length(shim_help("foofoo")), 0) }) test_that("shim_question behaves the same as utils::? for non-devtools-loaded packages", { expect_identical(shim_question(lm)[1], utils::`?`(lm)[1]) expect_identical(shim_question(stats::lm)[1], utils::`?`(stats::lm)[1]) expect_identical(shim_question(lm(123))[1], utils::`?`(lm(123))[1]) expect_identical(shim_question(`lm`)[1], utils::`?`(`lm`)[1]) expect_identical(shim_question('lm')[1], utils::`?`('lm')[1]) }) test_that("shim_question behaves like util::? for searches", { expect_identical(shim_question(?lm), utils::`?`(?lm)) }) test_that("shim_question behaves the same as utils::? for nonexistent objects", { expect_equal(length(shim_question(foofoo)), 0) expect_equal(length(shim_question(`foofoo`)), 0) expect_equal(length(shim_question("foofoo")), 0) # If given a function call with nonexistent function, error expect_error(utils::`?`(foofoo(123))) expect_error(shim_question(foofoo(123))) }) test_that("show_help and shim_question files for devtools-loaded packages", { load_all(test_path('testHelp')) on.exit(unload(test_path('testHelp'))) h1 <- shim_help("foofoo") expect_s3_class(h1, "dev_topic") expect_equal(h1$topic, "foofoo") expect_equal(h1$pkg, "testHelp") expect_identical(shim_help(foofoo), h1) expect_identical(shim_help(foofoo, "testHelp"), h1) expect_identical(shim_question(testHelp::foofoo), h1) pager_fun <- function(files, header, title, delete.file) { expect_equal(title, "testHelp:foofoo.Rd") } withr::with_options( c(pager = pager_fun), print(h1, type = 'text')) }) test_that("dev_help works with package and function help with the same name", { load_all(test_path('testHelp')) on.exit(unload(test_path('testHelp'))) h1 <- dev_help("testHelp") expect_identical(shim_question(testHelp::testHelp), h1) }) pkgload/tests/testthat/test-package.R0000644000176200001440000000053313102156023017362 0ustar liggesuserscontext('package') test_that("it can load from outside of package root", { expect_false('testHooks' %in% loadedNamespaces()) load_all(file.path("testHooks")) expect_true('testHooks' %in% loadedNamespaces()) expect_true(is_dev_package("testHooks")) unload(file.path("testHooks")) expect_false('testHooks' %in% loadedNamespaces()) }) pkgload/tests/testthat/testDllRcpp/0000755000176200001440000000000013141335465017142 5ustar liggesuserspkgload/tests/testthat/testDllRcpp/src/0000755000176200001440000000000013365662743017743 5ustar liggesuserspkgload/tests/testthat/testDllRcpp/src/rcpp_hello_world.cpp0000644000176200001440000000047413140673755024006 0ustar liggesusers#include // [[Rcpp::export]] SEXP rcpp_hello_world() { using namespace Rcpp; CharacterVector x = CharacterVector::create("foo", "bar"); NumericVector y = NumericVector::create(0.0, 1.0); List z = List::create(x, y); return z; } // [[Rcpp::export]] bool rcpp_test_attributes() { return true; } pkgload/tests/testthat/testDllRcpp/src/RcppExports.cpp0000644000176200001440000000215113357720017022725 0ustar liggesusers// Generated by using Rcpp::compileAttributes() -> do not edit by hand // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #include using namespace Rcpp; // rcpp_hello_world SEXP rcpp_hello_world(); RcppExport SEXP _testDllRcpp_rcpp_hello_world() { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = Rcpp::wrap(rcpp_hello_world()); return rcpp_result_gen; END_RCPP } // rcpp_test_attributes bool rcpp_test_attributes(); RcppExport SEXP _testDllRcpp_rcpp_test_attributes() { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = Rcpp::wrap(rcpp_test_attributes()); return rcpp_result_gen; END_RCPP } static const R_CallMethodDef CallEntries[] = { {"_testDllRcpp_rcpp_hello_world", (DL_FUNC) &_testDllRcpp_rcpp_hello_world, 0}, {"_testDllRcpp_rcpp_test_attributes", (DL_FUNC) &_testDllRcpp_rcpp_test_attributes, 0}, {NULL, NULL, 0} }; RcppExport void R_init_testDllRcpp(DllInfo *dll) { R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); R_useDynamicSymbols(dll, FALSE); } pkgload/tests/testthat/testDllRcpp/NAMESPACE0000644000176200001440000000014313140673755020365 0ustar liggesusersuseDynLib(testDllRcpp, .registration = TRUE) export(rcpp_hello_world) export(rcpp_test_attributes) pkgload/tests/testthat/testDllRcpp/R/0000755000176200001440000000000013365662743017355 5ustar liggesuserspkgload/tests/testthat/testDllRcpp/R/RcppExports.R0000644000176200001440000000044513357720017021762 0ustar liggesusers# Generated by using Rcpp::compileAttributes() -> do not edit by hand # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 rcpp_hello_world <- function() { .Call(`_testDllRcpp_rcpp_hello_world`) } rcpp_test_attributes <- function() { .Call(`_testDllRcpp_rcpp_test_attributes`) } pkgload/tests/testthat/testDllRcpp/DESCRIPTION0000644000176200001440000000035713141335465020655 0ustar liggesusersPackage: testDllRcpp Title: Test package for compiling DLLs that link to Rcpp License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 Depends: Rcpp (>= 0.10.0) LinkingTo: Rcpp pkgload/tests/testthat/test-description.r0000644000176200001440000000035113144323774020367 0ustar liggesuserscontext("DESCRIPTION checks") test_that("Parse DESCRIPTION file", { pkg <- pkg_desc("testNamespace") expect_identical(package_version("0.1"), pkg$get_version()) expect_identical("testNamespace", pkg_name("testNamespace")) }) pkgload/tests/testthat/testImportVersion/0000755000176200001440000000000013141335465020422 5ustar liggesuserspkgload/tests/testthat/testImportVersion/NAMESPACE0000644000176200001440000000001213010373512021620 0ustar liggesusersexport(a) pkgload/tests/testthat/testImportVersion/R/0000755000176200001440000000000013010373512020611 5ustar liggesuserspkgload/tests/testthat/testImportVersion/R/b.r0000644000176200001440000000000713010373512021212 0ustar liggesusersb <- 2 pkgload/tests/testthat/testImportVersion/R/a.r0000644000176200001440000000000713010373512021211 0ustar liggesusersa <- 1 pkgload/tests/testthat/testImportVersion/DESCRIPTION0000644000176200001440000000040613141335465022130 0ustar liggesusersPackage: testImportVersion Title: Tools to make developing R code easier License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 Imports: grid (>= 100.0), compiler (>= 2.0-0) Collate: a.r b.rpkgload/src/0000755000176200001440000000000013365662743012501 5ustar liggesuserspkgload/src/unlock.c0000644000176200001440000000156113365662743014143 0ustar liggesusers#include #include #include #include // for NULL extern SEXP unlock_environment_(SEXP); static const R_CallMethodDef CallEntries[] = { {"unlock_environment_", (DL_FUNC) &unlock_environment_, 1}, {NULL, NULL, 0} }; void R_init_pkgload(DllInfo *dll) { R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); R_useDynamicSymbols(dll, FALSE); } /* This is taken from envir.c in the R 2.15.1 source https://github.com/SurajGupta/r-source/blob/master/src/main/envir.c */ #define FRAME_LOCK_MASK (1 << 14) #define FRAME_IS_LOCKED(e) (ENVFLAGS(e) & FRAME_LOCK_MASK) #define UNLOCK_FRAME(e) SET_ENVFLAGS(e, ENVFLAGS(e) & (~FRAME_LOCK_MASK)) extern SEXP R_TrueValue; extern SEXP R_FalseValue; SEXP unlock_environment_(SEXP env) { UNLOCK_FRAME(env); return FRAME_IS_LOCKED(env) == 0 ? R_TrueValue : R_FalseValue; } pkgload/NAMESPACE0000644000176200001440000000117313365662572013133 0ustar liggesusers# Generated by roxygen2: do not edit by hand S3method(print,dev_topic) export(check_dep_version) export(check_suggested) export(dev_example) export(dev_help) export(dev_meta) export(dev_topic_index_reset) export(has_tests) export(imports_env) export(inst) export(is_dev_package) export(load_all) export(load_code) export(load_data) export(load_dll) export(ns_env) export(package_file) export(parse_deps) export(parse_ns_file) export(pkg_desc) export(pkg_env) export(pkg_name) export(pkg_ns) export(pkg_path) export(pkg_version) export(pkgtest) export(run_example) export(unload) import(rlang) useDynLib(pkgload, .registration = TRUE) pkgload/NEWS.md0000644000176200001440000000567213365661332013013 0ustar liggesusers# pkgload 1.0.2 * `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 being unloaded (#75) * `help()` will no longer error when trying to load package level help (#67). * Trailing slashes now removed from all paths, which fixes issues on Windows (#73). * `load_dll()` now fixed in R-devel (#77). * The help shim's now work for `:::` inputs (#72). # pkgload 1.0.0 * `load_all()` now updates imports of dependent packages when a package is reloaded (#59). * `load_all()` now assigns `DESCRIPTION/Depends` to `.Depends` object of package environment. (@yiufung pkgload#61) * `load_all()` now attaches `testthat` if the `attach_testthat` option is `TRUE`. This allows `load_all()` to more closely mimic the testing environment. (#56) * `check_dep_version()` and `check_suggested()` are now exported. * `check_dep_version()` now emits a warning and returns `FALSE` rather than aborting. (#47) * Package imports are now exported when using `load_all()`. This behavior can be disabled by using `load_all(export_imports = FALSE)`. * The `as.package()` and `is.package()` functions have been removed. * `load_code()`, `load_data()`, `load_dll()`, `load_all()`, `parse_ns_file()` all now take an explicit path rather than a path or a `package` object. * `imports_env()`, `ns_env()`, `pkg_env()` and `unload()` now take a package name rather than a path or a `package` object. * `run_example()` now works on R 3.1. * `unload()` now unloads S4 classes for packages loaded with `library()` as well as `load_all()` (#46). * `load_all()` gains a `helpers` option to specify whether or not to source testthat helpers. (@pitakakariki devtools #1202) * `load_all()` now sources the testthat helpers in the namespace environment rather than the package environment (#40). * `load_all()` now sets the `NOT_CRAN` environment variable when it sources testthat helpers. It also sets `DEVTOOLS_LOAD` to "true" so that you can check whether they are run during package loading. * `dev_topic_path()` now only returns the last path found, fixing an error when a package has both a package function level help with the same name. (#21) * New function `is_dev_package()` to determine if a given package has been loaded by `pkgload::load_all()` (#2). * `load_all()` no longer updates the collate directive. Instead this functionality has been moved to `devtools::document()`. * `dev_help()` now optionally takes a character vector of packages to search within. This replaces `find_topic()`. * `dev_topic_index_reset()` is now exported, and allows you to reset the topic index associated with a given package. * Added a `NEWS.md` file to track changes to the package. * Initial release from code spun off from devtools pkgload/R/0000755000176200001440000000000013365662163012107 5ustar liggesuserspkgload/R/inst.r0000644000176200001440000000150413144323774013244 0ustar liggesusers#' Get the installation path of a package #' #' Given the name of a package, this returns a path to the installed #' copy of the package, which can be passed to other devtools functions. #' #' It searches for the package in [.libPaths()]. If multiple #' dirs are found, it will return the first one. #' #' @param name the name of a package. #' #' @examples #' inst("pkgload") #' inst("grid") #' @export inst <- function(name) { # It would be nice to use find.package or system.file, but they # also search in the directory in the 'path' attribute of the # package environment. # Look in the library paths paths <- file.path(.libPaths(), name) paths <- paths[dir.exists(paths)] if (length(paths) > 0) { # If multiple matches, return the first one return(normalizePath(paths[1])) } else { return(NULL) } } pkgload/R/imports-env.r0000644000176200001440000001042113365662010014542 0ustar liggesusers#' Return imports environment for a package #' #' Contains objects imported from other packages. Is the parent of the #' package namespace environment, and is a child of ``, #' which is a child of `R_GlobalEnv`. #' @keywords internal #' @param path TODO: fix doc #' @seealso [ns_env()] for the namespace environment that #' all the objects (exported and not exported). #' @seealso [pkg_env()] for the attached environment that contains #' the exported objects. #' @export imports_env <- function(package) { if (!is_loaded(package)) { stop("Namespace environment must be created before accessing imports environment.") } env <- parent.env(ns_env(package)) if (attr(env, 'name') != imports_env_name(package)) { stop("Imports environment does not have attribute 'name' with value ", imports_env_name(package), ". This probably means that the namespace environment was not created correctly.") } env } # Generate name of package imports environment # Contains exported objects imports_env_name <- function(package) { paste("imports:", package, sep = "") } #' Load all of the imports for a package #' #' The imported objects are copied to the imports environment, and are not #' visible from `R_GlobalEnv`. This will automatically load (but not attach) #' the dependency packages. #' #' @keywords internal load_imports <- function(path = ".") { package <- pkg_name(path) description <- pkg_desc(path) # Get data frame of dependency names and versions deps <- description$get_deps() imports <- deps[deps$type == "Imports", ] if (length(imports) == 0) return(invisible()) # If we've already loaded imports, don't load again (until load_all # is run with reset=TRUE). This is to avoid warnings when running # process_imports() if (length(ls(imports_env(package))) > 0) return(invisible(imports)) res <- mapply(check_dep_version, imports$package, imports$version) abort_for_missing_packages(res, imports$package) process_imports(path) invisible(deps) } abort_for_missing_packages <- function(x, pkgs) { if (any(!x)) { abort( paste0("Dependency package(s) ", paste0("'", pkgs[!x], "'", collapse = ","), " not available.")) } } # Load imported objects # The code in this function is taken and adapted from base::loadNamespace # Setup variables were added and the for loops put in a tryCatch block # https://github.com/wch/r-source/blob/tags/R-3-3-0/src/library/base/R/namespace.R#L397-L427 # This wraps the inner for loop iterations in a tryCatch wrap_inner_loop <- function(x) { inner <- x[[4]] x[[4]] <- call("tryCatch", error = quote(warning), inner) x } load_namespace_for1 <- function() wrap_inner_loop( extract_lang(body(loadNamespace), comp_lang, y = quote(for(i in nsInfo$imports) NULL), idx = 1:3) ) load_namespace_for2 <- function() wrap_inner_loop( extract_lang(body(loadNamespace), comp_lang, y = quote(for(imp in nsInfo$importClasses) NULL), idx = 1:3) ) load_namespace_for3 <- function() wrap_inner_loop( extract_lang(body(loadNamespace), comp_lang, y = quote(for(imp in nsInfo$importMethods) NULL), idx = 1:3) ) onload_assign("process_imports", { process_imports <- function(path = ".") { path <- pkg_path(path) package <- pkg_name(path) desc_path <- package_file("DESCRIPTION", path = path) vI <- ("tools" %:::% ".split_description")(("tools" %:::% ".read_description")(desc_path))$Imports nsInfo <- parse_ns_file(path) ns <- ns_env(package) lib.loc <- NULL !! load_namespace_for1() !! load_namespace_for2() !! load_namespace_for3() } process_imports <- expr_interp(process_imports) fn_env(process_imports) <- rlang::ns_env("pkgload") process_imports }) onload_assign("update_imports", { update_imports <- function(package) { vI <- ("tools" %:::% ".split_dependencies")(utils::packageDescription(package)[["Imports"]]) nsInfo <- parse_ns_file(system.file("NAMESPACE", package = package)) ns <- ns_env(package) lib.loc <- NULL suppressWarnings({ !! load_namespace_for1() !! load_namespace_for2() !! load_namespace_for3() }) } update_imports <- expr_interp(update_imports) fn_env(update_imports) <- rlang::ns_env("pkgload") update_imports }) #' @useDynLib pkgload, .registration = TRUE NULL pkgload/R/shims.r0000644000176200001440000001073413365661555013426 0ustar liggesusers# Insert shim objects into a package's imports environment # # @param pkg A path or package object insert_imports_shims <- function(package) { imp_env <- imports_env(package) imp_env$system.file <- shim_system.file imp_env$library.dynam.unload <- shim_library.dynam.unload } # Create a new environment as the parent of global, with devtools versions of # help, ?, and system.file. insert_global_shims <- function() { # If shims already present, just return if ("devtools_shims" %in% search()) return() e <- new.env() e$help <- shim_help e$`?` <- shim_question e$system.file <- shim_system.file base::attach(e, name = "devtools_shims", warn.conflicts = FALSE) } #' Replacement version of system.file #' #' This function is meant to intercept calls to [base::system.file()], #' so that it behaves well with packages loaded by devtools. It is made #' available when a package is loaded with [load_all()]. #' #' When `system.file` is called from the R console (the global #' environment), this function detects if the target package was loaded with #' [load_all()], and if so, it uses a customized method of searching #' for the file. This is necessary because the directory structure of a source #' package is different from the directory structure of an installed package. #' #' When a package is loaded with `load_all`, this function is also inserted #' into the package's imports environment, so that calls to `system.file` #' from within the package namespace will use this modified version. If this #' function were not inserted into the imports environment, then the package #' would end up calling `base::system.file` instead. #' @inheritParams base::system.file #' #' @usage # system.file(..., package = "base", lib.loc = NULL, mustWork = FALSE) #' @rdname system.file #' @name system.file #' @usage system.file(..., package = "base", lib.loc = NULL, mustWork = FALSE) shim_system.file <- function(..., package = "base", lib.loc = NULL, mustWork = FALSE) { # If package wasn't loaded with devtools, pass through to base::system.file. # If package was loaded with devtools (the package loaded with load_all) # search for files a bit differently. if (!(package %in% dev_packages())) { base::system.file(..., package = package, lib.loc = lib.loc, mustWork = mustWork) } else { pkg_path <- find.package(package) # First look in inst/ files_inst <- file.path(pkg_path, "inst", ...) present_inst <- file.exists(files_inst) # For any files that weren't present in inst/, look in the base path files_top <- file.path(pkg_path, ...) present_top <- file.exists(files_top) # Merge them together. Here are the different possible conditions, and the # desired result. NULL means to drop that element from the result. # # files_inst: /inst/A /inst/B /inst/C /inst/D # present_inst: T T F F # files_top: /A /B /C /D # present_top: T F T F # result: /inst/A /inst/B /C NULL # files <- files_top files[present_inst] <- files_inst[present_inst] # Drop cases where not present in either location files <- files[present_inst | present_top] if (length(files) > 0) { # Make sure backslahses are replaced with slashes on Windows normalizePath(files, winslash = "/") } else { if (mustWork) { stop("No file found", call. = FALSE) } else { "" } } # Note that the behavior isn't exactly the same as base::system.file with an # installed package; in that case, C and D would not be installed and so # would not be found. Some other files (like DESCRIPTION, data/, etc) would # be installed. To fully duplicate R's package-building and installation # behavior would be complicated, so we'll just use this simple method. } } shim_library.dynam.unload <- function(chname, libpath, verbose = getOption("verbose"), file.ext = .Platform$dynlib.ext) { # If package was loaded by devtools, we need to unload the dll ourselves # because libpath works differently from installed packages. if (!is.null(dev_meta(chname))) { try({ unload_dll(pkg_name(libpath)) }) return() } # Should only reach this in the rare case that the devtools-loaded package is # trying to unload a different package's DLL. base::library.dynam.unload(chname, libpath, verbose, file.ext) } pkgload/R/utils.R0000644000176200001440000001117213365661730013373 0ustar liggesusers# Given the name or vector of names, returns a named vector reporting # whether each exists and is a directory. dir.exists <- function(x) { res <- file.exists(x) & file.info(x)$isdir stats::setNames(res, x) } compact <- function(x) { is_empty <- vapply(x, function(x) length(x) == 0, logical(1)) x[!is_empty] } "%||%" <- function(a, b) if (!is.null(a)) a else b "%:::%" <- function(p, f) { get(f, envir = asNamespace(p)) } is_installed <- function(package, version = 0) { installed_version <- tryCatch(utils::packageVersion(package), error = function(e) NA) !is.na(installed_version) && installed_version >= version } #' Check that the version of an suggested package satisfies the requirements #' #' @param package The name of the suggested package #' @param version The version of the package #' @param compare The comparison operator to use to check the version #' @keywords internal #' @export #' @keywords internal check_suggested <- function(package, version = NULL, compare = NA, path = inst("pkgload")) { if (is.null(version)) { if (!is.na(compare)) { stop("Cannot set ", sQuote(compare), " without setting ", sQuote(version), call. = FALSE) } version <- suggests_dep(package, path = path) } if (!is_installed(package) || !check_dep_version(package, version)) { msg <- paste0(sQuote(package), if (is.na(version)) "" else paste0(" >= ", version), " must be installed for this functionality.") if (interactive()) { message(msg, "\nWould you like to install it?") if (utils::menu(c("Yes", "No")) == 1) { utils::install.packages(package) } else { stop(msg, call. = FALSE) } } else { stop(msg, call. = FALSE) } } } suggests_dep <- function(package, path = inst("pkgload")) { desc <- pkg_desc(path)$get_deps() found <- desc[desc$type == "Suggests" & desc$package == package, "version"] if (!length(found)) { stop("'", package, "' is not in Suggests: for '", pkg_name(path), "'", call. = FALSE) } found } all_named <- function (x) { if (length(x) == 0) return(TRUE) !is.null(names(x)) && all(names(x) != "") } make_function <- function (args, body, env = parent.frame()) { args <- as.pairlist(args) stopifnot(all_named(args), is.language(body)) eval(call("function", args, body), env) } comp_lang <- function(x, y, idx = seq_along(y)) { if (is.symbol(x) || is.symbol(y)) { return(identical(x, y)) } if (length(x) < length(idx)) return(FALSE) identical(x[idx], y[idx]) } extract_lang <- function(x, f, ...) { recurse <- function(y) { unlist(compact(lapply(y, extract_lang, f = f, ...)), recursive = FALSE) } # if x matches predicate return it if (isTRUE(f(x, ...))) { return(x) } if (is.call(x)) { res <- recurse(x)[[1]] if (top_level_call <- identical(sys.call()[[1]], as.symbol("extract_lang")) && is.null(res)) { warning("devtools is incompatible with the current version of R. `load_all()` may function incorrectly.") } return(res) } NULL } modify_lang <- function(x, f, ...) { recurse <- function(x) { lapply(x, modify_lang, f = f, ...) } x <- f(x, ...) if (is.call(x)) { as.call(recurse(x)) } else if (is.function(x)) { formals(x) <- modify_lang(formals(x), f, ...) body(x) <- modify_lang(body(x), f, ...) } else { x } } strip_internal_calls <- function(x, package) { if (is.call(x) && identical(x[[1L]], as.name(":::")) && identical(x[[2L]], as.name(package))) { x[[3L]] } else { x } } sort_ci <- function(x) { withr_with_collate("C", x[order(tolower(x), x)]) } dev_packages <- function() { packages <- vapply(loadedNamespaces(), function(x) !is.null(dev_meta(x)), logical(1)) names(packages)[packages] } copy_env <- function(src, dest = new.env(parent = emptyenv()), ignore = NULL) { srclist <- as.list(src, all.names = TRUE) srclist <- srclist[ !(names(srclist) %in% ignore) ] list2env(srclist, envir = dest) dest } copy_env_lazy <- function(src, dest = new.env(parent = emptyenv()), ignore = NULL) { nms <- ls(src, all.names = TRUE) nms <- nms[ !(nms %in% ignore) ] for (nme in nms) { delayed_assign(nme, as.symbol(nme), eval.env = src, assign.env = dest) } dest } # A version of delayedAssign which does _not_ use substitute delayed_assign <- function(x, value, eval.env = parent.frame(1), assign.env = parent.frame(1)) { (get(".Internal", baseenv()))(delayedAssign(x, value, eval.env, assign.env)) } last <- function(x) utils::tail(x, n = 1L) single_quote <- function(x) { encodeString(x, quote = "'") } unlock_environment <- function(x) { .Call(unlock_environment_, x) } pkgload/R/source.r0000644000176200001440000000151013101710644013551 0ustar liggesuserssource_many <- function(files, encoding, envir = parent.frame()) { stopifnot(is.character(files)) stopifnot(is.environment(envir)) oop <- options( keep.source = TRUE, show.error.locations = TRUE, topLevelEnvironment = as.environment(envir)) on.exit(options(oop)) for (file in files) { source_one(file, encoding, envir = envir) } invisible() } source_one <- function(file, encoding, envir = parent.frame()) { stopifnot(file.exists(file)) stopifnot(is.environment(envir)) lines <- read_lines_enc(file, file_encoding = encoding) srcfile <- srcfilecopy(file, lines, file.info(file)[1, "mtime"], isFile = TRUE) exprs <- parse(text = lines, n = -1, srcfile = srcfile) n <- length(exprs) if (n == 0L) return(invisible()) for (i in seq_len(n)) { eval(exprs[i], envir) } invisible() } pkgload/R/file-cache.r0000644000176200001440000000142413010373512014233 0ustar liggesusers# Generate checksums for a vector of file paths. # @keywords internal md5 <- function(paths) { unlist(lapply(paths, tools::md5sum)) } make_cache <- function() { .file_cache <- character() make <- function(paths) { paths <- path.expand(paths) new_hash <- md5(paths) old_hash <- .file_cache[paths] changed <- is.na(old_hash) | new_hash != old_hash .file_cache[paths[changed]] <<- new_hash[changed] paths[changed] } clear <- function() { .file_cache <<- character() } list(make = make, clear = clear) } .cache <- make_cache() # Given vector of paths, return only those paths that have changed since the # last invocation. # @keywords internal changed_files <- .cache$make # Clear file cache. # @keywords internal clear_cache <- .cache$clear pkgload/R/dev-help.r0000644000176200001440000001564013365662163014004 0ustar liggesusers#' In-development help for package loaded with devtools #' #' `dev_help` searches for source documentation provided in #' packages loaded by devtools. To improve performance, the `.Rd` files #' are parsed to create to index once, then cached. Use #' `dev_topic_index_reset` to clear that index. #' #' @param topic name of help to search for. #' @param dev_packages A character vector of package names to search within. #' If `NULL`, defaults to all packages loaded by devtools. #' @param stage at which stage ("build", "install", or "render") should #' `\\Sexpr` macros be executed? This is only important if you're using #' `\\Sexpr` macro's in your Rd files. #' @param type of html to produce: `"html"` or `"text"`. Defaults to #' your default documentation type. #' @export #' @examples #' \dontrun{ #' library("ggplot2") #' help("ggplot") # loads installed documentation for ggplot #' #' load_all("ggplot2") #' dev_help("ggplot") # loads development documentation for ggplot #' } dev_help <- function(topic, dev_packages = NULL, stage = "render", type = getOption("help_type")) { loc <- dev_topic_find(topic, dev_packages) if (is.null(loc$path)) { stop("Could not find development topic '", topic, "'", call. = FALSE) } structure( list( topic = topic, pkg = loc$pkg, path = loc$path, stage = stage, type = type ), class = "dev_topic" ) } #' @export print.dev_topic <- function(x, ...) { message("Rendering development documentation for '", x$topic, "'") type <- match.arg(x$type %||% "text", c("text", "html")) out_path <- paste(tempfile("Rtxt"), type, sep = ".") if (type == "text") { tools::Rd2txt(x$path, out = out_path, package = x$pkg, stages = x$stage) file.show(out_path, title = paste(x$pkg, basename(x$path), sep = ":")) } else if (type == "html") { if (rstudioapi::hasFun("previewRd")) { rstudioapi::callFun("previewRd", x$path) return(invisible()) } tools::Rd2HTML(x$path, out = out_path, package = x$pkg, stages = x$stage, no_links = TRUE) css_path <- file.path(tempdir(), "R.css") if (!file.exists(css_path)) { file.copy(file.path(R.home("doc"), "html", "R.css"), css_path) } utils::browseURL(out_path) } } #' Drop-in replacements for help and ? functions #' #' The `?` and `help` functions are replacements for functions of the #' same name in the utils package. They are made available when a package is #' loaded with [load_all()]. #' #' The `?` function is a replacement for [utils::?()] from the #' utils package. It will search for help in devtools-loaded packages first, #' then in regular packages. #' #' The `help` function is a replacement for [utils::help()] from #' the utils package. If `package` is not specified, it will search for #' help in devtools-loaded packages first, then in regular packages. If #' `package` is specified, then it will search for help in devtools-loaded #' packages or regular packages, as appropriate. #' #' @inheritParams utils::help utils::`?` #' @param topic A name or character string specifying the help topic. #' @param package A name or character string specifying the package in which #' to search for the help topic. If NULL, search all packages. #' @param e1 First argument to pass along to `utils::`?``. #' @param e2 Second argument to pass along to `utils::`?``. #' @param ... Additional arguments to pass to [utils::help()]. #' #' @rdname help #' @name help #' @usage # help(topic, package = NULL, ...) #' #' @examples #' \dontrun{ #' # This would load devtools and look at the help for load_all, if currently #' # in the devtools source directory. #' load_all() #' ?load_all #' help("load_all") #' } #' #' # To see the help pages for utils::help and utils::`?`: #' help("help", "utils") #' help("?", "utils") #' #' \dontrun{ #' # Examples demonstrating the multiple ways of supplying arguments #' # NB: you can't do pkg <- "ggplot2"; help("ggplot2", pkg) #' help(lm) #' help(lm, stats) #' help(lm, 'stats') #' help('lm') #' help('lm', stats) #' help('lm', 'stats') #' help(package = stats) #' help(package = 'stats') #' topic <- "lm" #' help(topic) #' help(topic, stats) #' help(topic, 'stats') #' } shim_help <- function(topic, package = NULL, ...) { # Reproduce help's NSE for topic - try to eval it and see if it's a string topic_name <- substitute(topic) is_char <- FALSE try(is_char <- is.character(topic) && length(topic) == 1L, silent = TRUE) if (is_char) { topic_str <- topic topic_name <- as.name(topic) } else if (missing(topic_name)) { # Leave the vars missing } else if (is.null(topic_name)) { topic_str <- NULL topic_name <- NULL } else { topic_str <- deparse(substitute(topic)) } # help's NSE for package is slightly simpler package_name <- substitute(package) if (is.name(package_name)) { package_str <- as.character(package_name) } else if (is.null(package_name)) { package_str <- NULL } else { package_str <- package package_name <- as.name(package) } use_dev <- (!missing(topic) && !is.null(package_str) && package_str %in% dev_packages()) || (!missing(topic_name) && is.null(package_str) && !is.null(dev_topic_find(topic_str))) if (use_dev) { dev_help(topic_str, package_str) } else { # This is similar to list(), except that one of the args is a missing var, # it will replace it with an empty symbol instead of trying to evaluate it. as_list <- function(..., .env = parent.frame()) { dots <- match.call(expand.dots = FALSE)$`...` lapply(dots, function(var) { is_missing <- eval(substitute(missing(x), list(x = var)), .env) if (is_missing) { quote(expr=) } else { eval(var, .env) } }) } call <- substitute( utils::help(topic, package, ...), as_list(topic = topic_name, package = package_name) ) eval(call) } } #' @usage #' # ?e2 #' # e1?e2 #' #' @rdname help #' @name ? shim_question <- function(e1, e2) { # Get string version of e1, for find_topic e1_expr <- substitute(e1) if (is.name(e1_expr)) { # Called with a bare symbol, like ?foo topic <- as.character(e1_expr) pkg <- NULL } else if (is.call(e1_expr)) { if (identical(e1_expr[[1]], quote(`?`))) { # ??foo topic <- NULL pkg <- NULL } else if (identical(e1_expr[[1]], quote(`::`))) { # ?bar::foo topic <- as.character(e1_expr[[3]]) pkg <- as.character(e1_expr[[2]]) } else { # ?foo(12) topic <- deparse(e1_expr[[1]]) pkg <- NULL } } else if (is.character(e1_expr)) { topic <- e1 pkg <- NULL } else { stop("Unknown input", call. = FALSE) } # Search for the topic in devtools-loaded packages. # If not found, call utils::`?`. if (!is.null(topic) && !is.null(dev_topic_find(topic, pkg))) { dev_help(topic, pkg) } else { eval(as.call(list(utils::`?`, substitute(e1), substitute(e2)))) } } pkgload/R/enc.R0000644000176200001440000000044413101710644012763 0ustar liggesusersread_lines_enc <- function(path, file_encoding = "UTF-8", n = -1L, ok = TRUE, skipNul = FALSE) { con <- file(path, encoding = file_encoding) on.exit(close(con), add = TRUE) lines <- readLines(con, warn = FALSE, n = n, ok = ok, skipNul = skipNul) Encoding(lines) <- "UTF-8" lines } pkgload/R/package.r0000644000176200001440000000361613357653063013673 0ustar liggesusers#' Find file in a package. #' #' It always starts by finding by walking up the path until it finds the #' root directory, i.e. a directory containing `DESCRIPTION`. If it #' cannot find the root directory, or it can't find the specified path, it #' will throw an error. #' #' @param ... Components of the path. #' @param path Place to start search for package directory. #' @export #' @examples #' \dontrun{ #' package_file("figures", "figure_1") #' } package_file <- function(..., path = ".") { file.path(pkg_path(path), ...) } # Mockable variant of interactive interactive <- function() .Primitive("interactive")() #' Is the package currently under development? #' #' Returns `TRUE` or `FALSE` depending on if the package has been loaded by #' **pkgload**. #' #' @param name the name of a package. #' @export is_dev_package <- function(name) name %in% dev_packages() #' Helper functions for working with development packages. #' #' All functions search recursively up the directory tree from the input path #' until they find a DESCRIPTION file. #' @inheritParams load_all #' @name packages NULL #' @describeIn packages Return the normalized package path. #' @export pkg_path <- function(path = ".") { path <- rprojroot_find_root("DESCRIPTION", path) # Strip trailing slashes, which can cause errors on Windows (#73) sub("[/\\]$", "", path) } #' @describeIn packages Return the package name. #' @export pkg_name <- function(path = ".") { desc_desc_get("Package", pkg_path(path))[[1]] } #' @describeIn packages Return the package DESCRIPTION as a [desc::desc()] object. #' @export pkg_desc <- function(path = ".") { desc_desc(pkg_path(path)) } #' @describeIn packages Return the package version. #' @export pkg_version <- function(path = ".") { desc_desc_get_version(pkg_path(path)) } #' @describeIn packages Return the package namespace. #' @export pkg_ns <- function(path = ".") { ns_env(pkg_name(path)) } pkgload/R/load-dll.r0000644000176200001440000000572113347020260013751 0ustar liggesusers#' Load a compiled DLL #' #' @param path Path to a package, or within a package. #' @keywords programming #' @name load_dll #' @usage load_dll(path = ".") #' @export onload_assign("load_dll", { for_loop <- modify_lang( f = function(x) if (comp_lang(x, quote(library.dynam()), 1)) { quote(library.dynam2(path, lib)) } else { x }, extract_lang(body(loadNamespace), comp_lang, y = quote(for (i in seq_along(dynLibs)) NULL), idx = 1:3)) ## The code below taken directly from base::loadNamespace ## https://github.com/wch/r-source/blob/tags/R-3-3-0/src/library/base/R/namespace.R#L466-L485 ## except for the call to library.dynam2, which is a special version of ## library.dynam load_dll <- function(path = ".") { package <- pkg_name(path) env <- ns_env(package) nsInfo <- parse_ns_file(path) dlls <- list() dynLibs <- nsInfo$dynlibs nativeRoutines <- list() !! for_loop addNamespaceDynLibs(env, nsInfo$dynlibs) invisible(dlls) } load_dll <- expr_interp(load_dll) fn_env(load_dll) <- rlang::ns_env("pkgload") load_dll }) # Return a list of currently loaded DLLs from the package loaded_dlls <- function(package) { libs <- .dynLibs() matchidx <- vapply(libs, "[[", character(1), "name") == package libs[matchidx] } # This is a replacement for base::library.dynam, with a slightly different # call interface. The original requires that the name of the package is the # same as the directory name, which isn't always the case when loading with # devtools. This version allows them to be different, and also searches in # the src/ directory for the DLLs, instead of the libs/$R_ARCH/ directory. library.dynam2 <- function(path = ".", lib = "") { path <- pkg_path(path) dllname <- paste(lib, .Platform$dynlib.ext, sep = "") dllfile <- package_file("src", dllname, path = path) if (!file.exists(dllfile)) return(invisible()) # # The loading and registering of the dll is similar to how it's done # # in library.dynam. dllinfo <- dyn.load(dllfile) # Register dll info so it can be unloaded with library.dynam.unload .dynLibs(c(.dynLibs(), list(dllinfo))) return(dllinfo) } # This is taken directly from base::loadNamespace() # https://github.com/wch/r-source/blob/tags/R-3-3-0/src/library/base/R/namespace.R#L270-L273 onload_assign("addNamespaceDynLibs", eval(extract_lang(body(loadNamespace), comp_lang, y = quote(addNamespaceDynLibs <- NULL), idx = 1:2)[[3]])) # This is taken directly from base::loadNamespace # https://github.com/wch/r-source/blob/tags/R-3-3-0/src/library/base/R/namespace.R#L287-L308 # The only change is the line used get the package name onload_assign("assignNativeRoutines", { f <- eval( extract_lang(body(loadNamespace), comp_lang, y = quote(assignNativeRoutines <- NULL), idx = 1:2)[[3]]) body(f) <- as.call(append(after = 1, as.list(body(f)), quote(package <- methods::getPackageName(env)))) f }) pkgload/R/aaa.r0000644000176200001440000000033213103146114012771 0ustar liggesusers#' @import rlang NULL onload_assign <- local({ names <- character() funs <- list() function(name, x) { names[length(names) + 1] <<- name funs[[length(funs) + 1]] <<- substitute(x) } }) pkgload/R/run-loadhooks.r0000644000176200001440000000253713144323774015063 0ustar liggesusers#' Run user and package hooks. #' #' #' @inheritParams ns_env #' @param hook hook name: one of "load", "unload", "attach", or "detach" #' @keywords internal run_pkg_hook <- function(package, hook) { trans <- c( "load" = ".onLoad", "unload" = ".onUnload", "attach" = ".onAttach", "detach" = ".onDetach") hook <- match.arg(hook, names(trans)) f_name <- trans[hook] metadata <- dev_meta(package) if (isTRUE(metadata[[f_name]])) return(FALSE) # Run hook function if defined, and not already run nsenv <- ns_env(package) ns_path <- ns_path(package) if (!exists(f_name, nsenv, inherits = FALSE)) return(FALSE) if (hook %in% c("load", "attach")) { nsenv[[f_name]](dirname(ns_path), package) } else { nsenv[[f_name]](dirname(ns_path)) } metadata[[f_name]] <- TRUE TRUE } #' @rdname run_pkg_hook run_user_hook <- function(package, hook) { nsenv <- ns_env(package) trans <- c( "load" = "onLoad", "unload" = "onUnload", "attach" = "attach", "detach" = "detach") hook <- match.arg(hook, names(trans)) hook_name <- trans[hook] metadata <- dev_meta(package) if (isTRUE(metadata[[hook_name]])) return(FALSE) hooks <- getHook(packageEvent(package, hook_name)) if (length(hooks) == 0) return(FALSE) for(fun in rev(hooks)) try(fun(package)) metadata[[hook_name]] <- TRUE invisible(TRUE) } pkgload/R/remove-s4-class.r0000644000176200001440000001205513357720455015221 0ustar liggesusers# Remove s4 classes created by this package. # This is only necessary if the package was loaded with devtools. If the # package was NOT loaded by devtools, it's not necessary to remove the # classes this way, and attempting to do so will result in errors. remove_s4_classes <- function(package) { nsenv <- ns_env(package) if (is.null(nsenv)) { return() } classes <- methods::getClasses(nsenv, FALSE) classes <- sort_s4classes(classes, package) lapply(classes, remove_s4_class, package) } # Sort S4 classes for hierarchical removal # Derived classes must be removed **after** their parents. # This reduces to a topological sorting on the S4 dependency class # https://en.wikipedia.org/wiki/Topological_sorting sort_s4classes <- function(classes, package) { nsenv <- ns_env(package) sorted_classes <- vector(mode = 'character', length = 0) ## Return the parent class, if any within domestic classes extends_first <- function(x, classes) { ext <- methods::extends(methods::getClass(x, where = nsenv)) parent <- ext[2] classes %in% parent } ## Matrix of classes in columns, extending classes in rows extended_classes <- vapply( classes, extends_first, rep(TRUE, length(classes)), classes ) if (!is.matrix(extended_classes)) extended_classes <- as.matrix(extended_classes) ## Dynamic set of orphan classes (safe to remove) start_idx <- which(apply(extended_classes, 2, sum) == 0) while (length(start_idx) > 0) { ## add node to sorted list (and remove from pending list) i <- start_idx[1] start_idx <- utils::tail(start_idx, -1) sorted_classes <- c(sorted_classes, classes[i]) ## check its derived classes if any for (j in which(extended_classes[i, ])) { extended_classes[i, j] <- FALSE if (sum(extended_classes[, j]) == 0) { start_idx <- c(start_idx, j) } } } if (any(extended_classes)) { ## Graph has a cycle. This should not happen ## Stop or try to continue? idx <- !classes %in% sorted_classes sorted_classes <- c(sorted_classes, classes[idx]) } sorted_classes } # Remove an s4 class from a package loaded by devtools # # For classes loaded with devtools, this is necessary so that R doesn't try to # modify superclasses that don't have references to this class. For example, # suppose you have package pkgA with class A, and pkgB with class B, which # contains A. If pkgB is loaded with load_all(), then class B will have a # reference to class A, and unloading pkgB the normal way, with # unloadNamespace("pkgB"), will result in some errors. They happen because R # will look at B, see that it is a superclass of A, then it will try to modify # A by removing subclass references to B. # # This function sidesteps the problem by modifying B. It finds all the classes # in B@contains which also have references back to B, then modifes B to keep # references to those classes, but remove references to all other classes. # Finally, it removes B. Calling removeClass("B") tells the classes referred to # in B@contains to remove their references back to B. # # It is entirely possible that this code is necessary only because of bugs in # R's S4 implementation. # # @param classname The name of the class. # @param package The package object which contains the class. remove_s4_class <- function(classname, package) { nsenv <- ns_env(package) # Make a copy of the class class <- methods::getClassDef(classname, package = package, inherits = FALSE) # If the class is not defined in this package do not try to remove it if (!identical(class@package, package)) { return() } # Find all the references to classes that (this one contains/extends AND # have backreferences to this class) so that R doesn't try to modify them. keep_idx <- contains_backrefs(classname, package, class@contains) class@contains <- class@contains[keep_idx] # Assign the modified class back into the package methods::assignClassDef(classname, class, where = nsenv, force = TRUE) # Remove the class, ignoring failures due to potentially locked environments. tryCatch(methods::removeClass(classname, where = nsenv), error = function(e) NULL) } # Given a list of SClassExtension objects, this returns a logical vector of the # same length. Each element is TRUE if the corresponding object has a reference # to this class, FALSE otherwise. contains_backrefs <- function(classname, pkgname, contains) { # If class_a in pkg_a has class_b in pkg_b as a subclass, return TRUE, # otherwise FALSE. has_subclass_ref <- function(class_a, pkg_a, class_b, pkg_b) { x <- methods::getClassDef(class_a, package = pkg_a) if (is.null(x)) return(FALSE) subclass_ref <- x@subclasses[[class_b]] if (!is.null(subclass_ref) && subclass_ref@package == pkg_b) { return(TRUE) } FALSE } if (length(contains) == 0) { return() } # Get a named vector of 'contains', where each item's name is the class, # and the value is the package. contain_pkgs <- sapply(contains, "slot", "package") mapply(has_subclass_ref, names(contain_pkgs), contain_pkgs, classname, pkgname) } pkgload/R/package-env.r0000644000176200001440000000620313272150570014443 0ustar liggesusers# Create the package environment where exported objects will be copied to attach_ns <- function(package) { nsenv <- ns_env(package) if (is_attached(package)) { stop("Package ", package, " is already attached.") } # This should be similar to attachNamespace pkgenv <- base::attach(NULL, name = pkg_env_name(package)) attr(pkgenv, "path") <- getNamespaceInfo(nsenv, "path") invisible(pkgenv) } # Invoke namespace load actions. According to the documentation for setLoadActions # these actions should be called at the end of processing of S4 metadata, after # dynamically linking any libraries, the call to .onLoad(), if any, and caching # method and class definitions, but before the namespace is sealed run_ns_load_actions <- function(package) { nsenv <- ns_env(package) actions <- methods::getLoadActions(nsenv) for (action in actions) action(nsenv) } # Copy over the objects from the namespace env to the package env export_ns <- function(package) { nsenv <- ns_env(package) pkgenv <- pkg_env(package) ns_path <- ns_path(nsenv) nsInfo <- parse_ns_file(ns_path) exports <- getNamespaceExports(nsenv) importIntoEnv(pkgenv, exports, nsenv, exports) } export_lazydata <- function(package) { nsenv <- ns_env(package) pkgenv <- pkg_env(package) desc <- pkg_desc(ns_path(package)) # If lazydata is true, manually copy data objects in $lazydata to package # environment lazydata <- desc$get("LazyData") if (!is.na(lazydata) && tolower(lazydata) %in% c("true", "yes")) { copy_env_lazy(src = nsenv$.__NAMESPACE__.$lazydata, dest = pkgenv) } } # Assign `.Depends` from namespace assign_depends <- function(package) { pkgenv <- pkg_env(package) desc <- pkg_desc(ns_path(package)) deps <- desc$get_deps() depends <- unique(deps[deps$type == "Depends" & deps$package != "R",]$package) if (length(depends) > 0L) pkgenv$.Depends <- depends } #' Return package environment #' #' This is an environment like ``. The package #' environment contains the exported objects from a package. It is #' attached, so it is an ancestor of `R_GlobalEnv`. #' #' When a package is loaded the normal way, using [library()], #' this environment contains only the exported objects from the #' namespace. However, when loaded with [load_all()], this #' environment will contain all the objects from the namespace, unless #' `load_all` is used with `export_all=FALSE`. #' #' If the package is not attached, this function returns `NULL`. #' #' @inheritParams ns_env #' @keywords internal #' @seealso [ns_env()] for the namespace environment that #' all the objects (exported and not exported). #' @seealso [imports_env()] for the environment that contains #' imported objects for the package. #' @export pkg_env <- function(package) { name <- pkg_env_name(package) if (!is_attached(package)) return(NULL) as.environment(name) } # Generate name of package environment # Contains exported objects pkg_env_name <- function(package) { paste("package:", package, sep = "") } # Reports whether a package is loaded and attached is_attached <- function(package) { pkg_env_name(package) %in% search() } pkgload/R/namespace-env.r0000644000176200001440000001603713365661517015025 0ustar liggesusers#' Return the namespace environment for a package. #' #' Contains all (exported and non-exported) objects, and is a descendant of #' `R_GlobalEnv`. The hierarchy is ``, #' ``, ``, and then #' `R_GlobalEnv`. #' #' If the package is not loaded, this function returns `NULL`. #' #' @param package package name. #' @keywords internal #' @seealso [pkg_env()] for the attached environment that #' contains the exported objects. #' @seealso [imports_env()] for the environment that contains #' imported objects for the package. #' @export ns_env <- function(package) { if (!is_loaded(package)) return(NULL) asNamespace(package) } ns_path <- function(package) { getNamespaceInfo(asNamespace(package), "path") } # Create the namespace environment for a package create_ns_env <- function(path = ".") { path <- pkg_path(path) package <- pkg_name(path) version <- pkg_version(path) if (is_loaded(package)) { stop("Namespace for ", package, " already exists.") } env <- makeNamespace(package, version) methods::setPackageName(package, env) # Create devtools metadata in namespace create_dev_meta(package) setNamespaceInfo(env, "path", path) setup_ns_imports(path) env } # This is taken directly from base::loadNamespace() # https://github.com/wch/r-source/blob/tags/R-3-3-0/src/library/base/R/namespace.R#L235-L258 onload_assign("makeNamespace", eval( modify_lang( extract_lang(body(loadNamespace), # Find makeNamespace definition comp_lang, y = quote(makeNamespace <- NULL), idx = 1:2)[[3]], # Replace call to .Internal(registerNamespace()) is replaced by a call to # register_namespace function(x) { if (comp_lang(x, quote(.Internal(registerNamespace(name, env))))) { quote(register_namespace(name, env)) } else { x } })) ) # Read the NAMESPACE file and set up the imports metdata. # (which is stored in .__NAMESPACE__.) setup_ns_imports <- function(path = ".") { path <- pkg_path(path) package <- pkg_name(path) nsInfo <- parse_ns_file(path) setNamespaceInfo(package, "imports", nsInfo$imports) } # Read the NAMESPACE file and set up the exports metdata. This must be # run after all the objects are loaded into the namespace because # namespaceExport throw errors if the objects are not present. setup_ns_exports <- function(path = ".", export_all = FALSE, export_imports = export_all) { path <- pkg_path(path) package <- pkg_name(path) nsInfo <- parse_ns_file(path) nsenv <- ns_env(package) if (export_all) { exports <- ls(nsenv, all.names = TRUE) # Make sure to re-export objects that are imported from other packages but # not copied. exports <- union(exports, nsInfo$exports) # if export_imports export all imports as well if (export_imports) { exports <- c(exports, ls(imports_env(package), all.names = TRUE)) } # List of things to ignore is from loadNamespace. There are also a # couple things to ignore from devtools. ignoreidx <- exports %in% c( ".__NAMESPACE__.", ".__S3MethodsTable__.", ".packageName", ".First.lib", ".onLoad", ".onAttach", ".conflicts.OK", ".noGenerics", ".__DEVTOOLS__", ".cache") exports <- exports[!ignoreidx] } else { # This code is from base::loadNamespace exports <- nsInfo$exports for (p in nsInfo$exportPatterns) exports <- c(ls(nsenv, pattern = p, all.names = TRUE), exports) } # Don't try to export objects that are missing from the namespace and imports ns_and_imports <- c(ls(nsenv, all.names = TRUE), ls(imports_env(package), all.names = TRUE)) extra_exports <- setdiff(exports, ns_and_imports) if (length(extra_exports) > 0) { warning("Objects listed as exports, but not present in namespace: ", paste(extra_exports, collapse = ", ")) exports <- intersect(ns_and_imports, exports) } # Add any S4 methods or classes, this needs to be done after checking for # missing exports as S4 methods with generics imported from other packages # are not defined in the namespace. exports <- add_classes_to_exports(ns = nsenv, package = package, exports = exports, nsInfo = nsInfo) # Update the exports metadata for the namespace with base::namespaceExport # It will throw warnings if objects are already listed in the exports # metadata, so catch those warnings and ignore them. suppressWarnings(namespaceExport(nsenv, exports)) invisible() } # Lookup S4 classes for export # # This function uses code from base::loadNamespace. Previously this code was # copied directly, now it is dynamically looked up instead, to prevent drift as # base::loadNamespace changes. onload_assign("add_classes_to_exports", make_function(alist(ns =, package =, exports =, nsInfo =), call("{", extract_lang( f = comp_lang, y = quote(if (.isMethodsDispatchOn() && .hasS4MetaData(ns) && !identical(package, "methods")) NULL), idx = 1:2, modify_lang(body(base::loadNamespace), strip_internal_calls, "methods")), quote(exports)), asNamespace("methods"))) #' Parses the NAMESPACE file for a package #' #' @inheritParams load_all #' @examples #' if (has_tests()) { #' parse_ns_file(pkgtest("testLoadHooks")) #' } #' @keywords internal #' @export parse_ns_file <- function(path = ".") { path <- pkg_path(path) parseNamespaceFile(basename(path), dirname(path), mustExist = FALSE) } # Register the S3 methods for this package register_s3 <- function(path = ".") { path <- pkg_path(path) package <- pkg_name(path) nsInfo <- parse_ns_file(path) # Adapted from loadNamespace registerS3methods(nsInfo$S3methods, package, ns_env(package)) } # Reports whether a package is loaded into a namespace. It may be # attached or not attached. is_loaded <- function(package) { package %in% loadedNamespaces() } # Returns the namespace registry ns_registry <- function() { (get(".Internal", envir = baseenv(), mode = "function"))(getNamespaceRegistry()) } # To avoid a note about getNamespaceRegistry being missing utils::globalVariables("getNamespaceRegistry") # Register a namespace register_namespace <- function(name = NULL, env = NULL) { # Be careful about what we allow if (!is.character(name) || name == "" || length(name) != 1) stop("'name' must be a non-empty character string.") if (!is.environment(env)) stop("'env' must be an environment.") if (name %in% loadedNamespaces()) stop("Namespace ", name, " is already registered.") # Add the environment to the registry nsr <- ns_registry() nsr[[name]] <- env env } # unregister a namespace - should be used only if unloadNamespace() # fails for some reason unregister_namespace <- function(name = NULL) { # Be careful about what we allow if (!is.character(name) || name == "" || length(name) != 1) stop("'name' must be a non-empty character string.") if (!(name %in% loadedNamespaces())) stop(name, " is not a registered namespace.") # Remove the item from the registry do.call(rm, args = list(name, envir = ns_registry())) invisible() } pkgload/R/load-depends.r0000644000176200001440000000076613145330631014626 0ustar liggesusersload_depends <- function(path = ".") { path <- pkg_path(path) description <- pkg_desc(path) # Get data frame of dependency names and versions deps <- description$get_deps() depends <- deps[deps$type == "Depends" & deps$package != "R", ] if (length(depends) == 0) return(invisible()) res <- mapply(check_dep_version, depends$package, depends$version) abort_for_missing_packages(res, depends$package) lapply(depends$package, require, character.only = TRUE) invisible(depends) } pkgload/R/load-code.r0000644000176200001440000000322613173371243014115 0ustar liggesusers#' Load R code. #' #' Load all R code in the `R` directory. The first time the code is #' loaded, `.onLoad` will be run if it exists. #' #' @inheritParams load_all #' @keywords programming #' @export load_code <- function(path = ".") { path <- pkg_path(path) package <- pkg_name(path) encoding <- pkg_desc(path)$get("Encoding") # Set encoding to ASCII if it is not explicitly defined if (is.na(encoding)) { encoding <- "ASCII" } env <- ns_env(package) r_files <- find_code(path) paths <- changed_files(r_files) if (length(paths) == 0L) return() success <- FALSE cleanup <- function() { if (success) return() clear_cache() unload(package) } on.exit(cleanup()) withr_with_dir(path, source_many(paths, encoding, env)) success <- TRUE invisible(r_files) } # Find all R files in given directory. find_code <- function(path = ".") { path_r <- package_file("R", path = path) r_files <- withr_with_collate( "C", tools::list_files_with_type(path_r, "code", full.names = TRUE) ) collate <- pkg_desc(path)$get_collate() if (length(collate) > 0) { # `r_files` have full paths, so add the package path to the collated files as # well. collate <- file.path(path_r, collate) missing <- setdiff(collate, r_files) files <- function(x) paste(basename(x), collapse = ", ") if (length(missing) > 0) { message("Skipping missing files: ", files(missing)) } collate <- setdiff(collate, missing) extra <- setdiff(r_files, collate) if (length(extra) > 0) { message("Adding files missing in collate: ", files(extra)) } r_files <- union(collate, r_files) } r_files } pkgload/R/dev-example.r0000644000176200001440000000331313145330631014465 0ustar liggesusers#' Run a examples for an in-development function. #' #' `dev_example` is a replacement for `example`. `run_example` #' is a low-level function that takes a path to an Rd file. #' #' @inheritParams run_examples #' @param topic Name or topic (or name of Rd) file to run examples for #' @param quiet If `TRUE`, does not echo code to console. #' @export #' @family example functions #' @examples #' \dontrun{ #' # Runs installed example: #' library("ggplot2") #' example("ggplot") #' #' # Runs develoment example: #' dev_example("ggplot") #' } dev_example <- function(topic, quiet = FALSE) { topic <- dev_help(topic) load_all(topic$pkg, quiet = quiet) run_example(topic$path, quiet = quiet) } #' @rdname dev_example #' @export #' @param path Path to `.Rd` file #' @param test if `TRUE`, code in \code{\\donttest{}} will be commented #' out. If `FALSE`, code in \code{\\testonly{}} will be commented out. This #' parameter is only used in R 3.2 and greater. #' @param run if `TRUE`, code in \code{\\dontrun{}} will be commented #' out. #' @param env Environment in which code will be run. run_example <- function(path, test = FALSE, run = FALSE, env = new.env(parent = globalenv()), quiet = FALSE) { if (!file.exists(path)) { stop("'", path, "' does not exist", call. = FALSE) } tmp <- tempfile(fileext = ".R") if (getRversion() < "3.2") { # R 3.1 and earlier did not have commentDonttest tools::Rd2ex(path, out = tmp, commentDontrun = !run) } else { tools::Rd2ex(path, out = tmp, commentDontrun = !run, commentDonttest = !test) } if (file.exists(tmp)) { source(tmp, echo = !quiet, local = env, max.deparse.length = Inf) } invisible(env) } pkgload/R/dev-meta.r0000644000176200001440000000204713144323774013774 0ustar liggesusers#' Return devtools metadata environment #' #' If the package was not loaded with devtools, returns `NULL`. #' #' @param name The name of a loaded package #' @keywords internal #' @examples #' dev_meta("stats") # NULL #' #' if (has_tests()) { #' # Load the test package in directory "testLoadHooks" #' load_all(pkgtest("testLoadHooks")) #' #' # Get metdata for the package #' x <- dev_meta("testLoadHooks") #' as.list(x) #' #' # Clean up. #' unload("testLoadHooks") #' } #' @export dev_meta <- function(name) { ns <- .getNamespace(name) if (is.null(ns)) { stop("Namespace not found for ", name, ". Is it loaded?") } if (is.null(ns$.__DEVTOOLS__)) { return(NULL) } ns$.__DEVTOOLS__ } # Create the devtools metadata environment for a package. # This should be run when packages are loaded by devtools. create_dev_meta <- function(name) { ns <- .getNamespace(name) if (!is.null(ns$.__DEVTOOLS__)) { stop("devtools metadata for package ", name, " already exists.") } ns$.__DEVTOOLS__ <- new.env(parent = ns) ns$.__DEVTOOLS__ } pkgload/R/unload.r0000644000176200001440000001010013357714001013532 0ustar liggesusers#' Unload a package #' #' This function attempts to cleanly unload a package, including unloading #' its namespace, deleting S4 class definitions and unloading any loaded #' DLLs. Unfortunately S4 classes are not really designed to be cleanly #' unloaded, and so we have to manually modify the class dependency graph in #' order for it to work - this works on the cases for which we have tested #' but there may be others. Similarly, automated DLL unloading is best tested #' for simple scenarios (particularly with `useDynLib(pkgname)` and may #' fail in other cases. If you do encounter a failure, please file a bug report #' at \url{http://github.com/r-lib/pkgload/issues}. #' #' @inheritParams ns_env #' @param quiet if `TRUE` suppresses output from this function. #' #' @examples #' \dontrun{ #' # Unload package that is in current directory #' unload() #' #' # Unload package that is in ./ggplot2/ #' unload(pkg_name("ggplot2/")) #' #' library(ggplot2) #' # unload the ggplot2 package directly by name #' unload("ggplot2") #' } #' @export unload <- function(package = pkg_name(), quiet = FALSE) { if (package == "compiler") { # Disable JIT compilation as it could interfere with the compiler # unloading. Also, if the JIT was kept enabled, it would cause the # compiler package to be loaded again soon, anyway. Note if we # restored the JIT level after the unloading, the call to # enableJIT itself would load the compiler again. oldEnable <- compiler::enableJIT(0) if (oldEnable != 0) { warning("JIT automatically disabled when unloading the compiler.") } } # 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 (package == "pkgload") { eapply(ns_env(package), force, all.names = TRUE) } # S4 classes that were created by the package need to be removed in a special way. remove_s4_classes(package) if (package %in% loadedNamespaces()) { # unloadNamespace will throw an error if it has trouble unloading. # This can happen when there's another package that depends on the # namespace. # unloadNamespace will also detach the package if it's attached. # # unloadNamespace calls onUnload hook and .onUnload try(unloadNamespace(package), silent = TRUE) } else { stop("Package ", package, " not found in loaded packages or namespaces") } # Sometimes the namespace won't unload with detach(), like when there's # another package that depends on it. If it's still around, force it # to go away. # loadedNamespaces() and unloadNamespace() often don't work here # because things can be in a weird state. if (!is.null(.getNamespace(package))) { if (!quiet) { message("unloadNamespace(\"", package, "\") not successful, probably because another loaded package depends on it. ", "Forcing unload. If you encounter problems, please restart R.") } unregister_namespace(package) } # Clear so that loading the package again will re-read all files clear_cache() # Do this after detach, so that packages that have an .onUnload function # which unloads DLLs (like MASS) won't try to unload the DLL twice. unload_dll(package) } # This unloads dlls loaded by either library() or load_all() unload_dll <- function(package) { # Always run garbage collector to force any deleted external pointers to # finalise gc() # Special case for devtools - don't unload DLL because we need to be able # to access nsreg() in the DLL in order to run makeNamespace. This means # that changes to compiled code in devtools can't be reloaded with # load_all -- it requires a reinstallation. if (package == "pkgload") { return(invisible()) } pkglibs <- loaded_dlls(package) for (lib in pkglibs) { dyn.unload(lib[["path"]]) } # Remove the unloaded dlls from .dynLibs() libs <- .dynLibs() .dynLibs(libs[!(libs %in% pkglibs)]) invisible() } pkgload/R/load-data.r0000644000176200001440000000227113144323774014117 0ustar liggesusers#' Load data. #' #' Loads all `.RData` files in the data subdirectory. #' #' @inheritParams load_all #' @keywords programming #' @export load_data <- function(path = ".") { # Note that this simulates normal R package loading by placing the data sets # in the .__NAMESPACE__.$lazydata environment, but unlike with proper lazy # loading via lazyLoad(), we'll need to manually copy these objects over to # the package environment later. path <- pkg_path(path) nsenv <- ns_env(pkg_name(path)) lazydata_env <- nsenv$.__NAMESPACE__.$lazydata objs <- character() sysdata <- package_file("R", "sysdata.rda", path = path) if (file.exists(sysdata)) { objs <- c(objs, load(sysdata, envir = nsenv)) } path_data <- package_file("data", path = path) if (file.exists(path_data)) { paths <- dir(path_data, "\\.[rR][dD]a(ta)?$", full.names = TRUE) paths <- changed_files(paths) objs <- c(objs, unlist(lapply(paths, load, envir = lazydata_env))) paths <- dir(path_data, "\\.[rR]$", full.names = TRUE) paths <- changed_files(paths) objs <- c(objs, unlist(lapply(paths, sys.source, envir = lazydata_env, chdir = TRUE, keep.source = TRUE))) } invisible(objs) } pkgload/R/zzz.r0000644000176200001440000000210213357717774013134 0ustar liggesusers.onLoad <- function(libname, pkgname) { # These withr functions are used in load_all() so need to exist in the # devtools namespace so the withr namespace is not prematurely loaded by `::` # during a load_all() call env <- asNamespace(pkgname) assign("withr_with_dir", withr::with_dir, envir = env) assign("withr_with_collate", withr::with_collate, envir = env) assign("withr_with_envvar", withr::with_envvar, envir = env) assign("desc_desc", desc::desc, envir = env) assign("desc_desc_get", desc::desc_get, envir = env) assign("desc_desc_get_version", desc::desc_get_version, envir = env) assign("rprojroot_find_root", rprojroot::find_root, envir = env) if (is_installed("testthat")) { assign("testthat_source_test_helpers", testthat::source_test_helpers, envir = env) } else { assign("testthat_source_test_helpers", function(...) TRUE, envir = env) } nms <- environment(onload_assign)$names funs <- environment(onload_assign)$funs for (i in seq_along(nms)) { assign(nms[[i]], eval(funs[[i]], envir = env), envir = env) } invisible() } pkgload/R/package-deps.r0000644000176200001440000000475013315220037014605 0ustar liggesusers#' Parse package dependency strings. #' #' @param string to parse. Should look like `"R (>= 3.0), ggplot2"` etc. #' @return list of two character vectors: `name` package names, #' and `version` package versions. If version is not specified, #' it will be stored as NA. #' @keywords internal #' @export #' @examples #' parse_deps("httr (< 2.1),\nRCurl (>= 3)") #' # only package dependencies are returned #' parse_deps("utils (== 2.12.1),\ntools,\nR (>= 2.10),\nmemoise") parse_deps <- function(string) { if (is.null(string)) return() stopifnot(is.character(string), length(string) == 1) if (grepl("^\\s*$", string)) return() pieces <- strsplit(string, "[[:space:]]*,[[:space:]]*")[[1]] # Get the names names <- gsub("\\s*\\(.*?\\)", "", pieces) names <- gsub("^\\s+|\\s+$", "", names) # Get the versions and comparison operators versions_str <- pieces have_version <- grepl("\\(.*\\)", versions_str) versions_str[!have_version] <- NA compare <- sub(".*\\((\\S+)\\s+.*\\)", "\\1", versions_str) versions <- sub(".*\\(\\S+\\s+(.*)\\)", "\\1", versions_str) # Check that non-NA comparison operators are valid compare_nna <- compare[!is.na(compare)] compare_valid <- compare_nna %in% c(">", ">=", "==", "<=", "<") if(!all(compare_valid)) { stop("Invalid comparison operator in dependency: ", paste(compare_nna[!compare_valid], collapse = ", ")) } deps <- data.frame(name = names, compare = compare, version = versions, stringsAsFactors = FALSE) # Remove R dependency deps[names != "R", ] } #' Check that the version of an imported package satisfies the requirements #' #' @param dep_name The name of the package with objects to import #' @param dep_ver The version of the package, this includes the specified #' comparison operator. #' @export #' @keywords internal check_dep_version <- function(dep_name, dep_ver = "*") { if (dep_name == "R") { return(TRUE) } if (!requireNamespace(dep_name, quietly = TRUE)) { warning("Dependency package '", dep_name, "' not available.") return(FALSE) } if (dep_ver == "*") { return(TRUE) } pieces <- strsplit(dep_ver, "[[:space:]]+")[[1]] dep_compare <- pieces[[1]] dep_ver <- pieces[[2]] compare <- match.fun(dep_compare) if (!compare( as.numeric_version(getNamespaceVersion(dep_name)), as.numeric_version(dep_ver))) { warning("Need ", dep_name, " ", dep_compare, " ", dep_ver, " but loaded version is ", getNamespaceVersion(dep_name)) } return(TRUE) } pkgload/R/load.r0000644000176200001440000002276013365661707013223 0ustar liggesusers#' Load complete package. #' #' `load_all` loads a package. It roughly simulates what happens #' when a package is installed and loaded with [library()]. #' #' Currently `load_all`: #' #' \itemize{ #' \item Loads all data files in `data/`. See [load_data()] #' for more details. #' #' \item Sources all R files in the R directory, storing results in #' environment that behaves like a regular package namespace. See #' below and [load_code()] for more details. #' #' \item Compiles any C, C++, or Fortran code in the `src/` directory #' and connects the generated DLL into R. See [compile_dll()] #' for more details. #' #' \item Runs `.onAttach()`, `.onLoad()` and `.onUnload()` #' functions at the correct times. #' #' \item If you use \pkg{testthat}, will load all test helpers so #' you can access them interactively. devtools sets the #' \code{DEVTOOLS_LOAD} environment variable to \code{"true"} to #' let you check whether the helpers are run during package loading. #' #' } #' #' @section Namespaces: #' The namespace environment ``, is a child of #' the imports environment, which has the name attribute #' `imports:pkgname`. It is in turn is a child of #' ``, which is a child of the global environment. #' (There is also a copy of the base namespace that is a child of the empty #' environment.) #' #' The package environment `` is an ancestor of the #' global environment. Normally when loading a package, the objects #' listed as exports in the NAMESPACE file are copied from the namespace #' to the package environment. However, `load_all` by default will #' copy all objects (not just the ones listed as exports) to the package #' environment. This is useful during development because it makes all #' objects easy to access. #' #' To export only the objects listed as exports, use #' `export_all=FALSE`. This more closely simulates behavior when #' loading an installed package with [library()], and can be #' useful for checking for missing exports. #' #' @section Shim files: #' `load_all` also inserts shim functions into the imports environment #' of the loaded package. It presently adds a replacement version of #' `system.file` which returns different paths from #' `base::system.file`. This is needed because installed and uninstalled #' package sources have different directory structures. Note that this is not #' a perfect replacement for `base::system.file`. #' #' @param path Path to a package, or within a package. #' @param reset clear package environment and reset file cache before loading #' any pieces of the package. This is equivalent to running #' [unload()] and is the default. Use `reset = FALSE` may be #' faster for large code bases, but is a significantly less accurate #' approximation. #' @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. #' @param export_imports If `TRUE` (the default), export all objects that are #' imported by the package. If `FALSE` export only objects defined in the #' package. #' @param attach_testthat If `TRUE`, attach \pkg{testthat} to the search path, #' 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{ #' # Load the package in the current directory #' load_all("./") #' #' # Running again loads changed files #' load_all("./") #' #' # With reset=TRUE, unload and reload the package for a clean start #' load_all("./", TRUE) #' #' # With export_all=FALSE, only objects listed as exports in NAMESPACE #' # are exported #' load_all("./", export_all = FALSE) #' } #' @export load_all <- function(path = ".", reset = TRUE, compile = NA, export_all = TRUE, export_imports = export_all, helpers = TRUE, attach_testthat = uses_testthat(path), quiet = FALSE, recompile = FALSE) { path <- pkg_path(path) package <- pkg_name(path) description <- pkg_desc(path) if (!quiet) message("Loading ", package) if (package == "compiler") { # Disable JIT while loading the compiler package to avoid interference # (otherwise the compiler package would be loaded as a side effect of # JIT compilation and it would be locked before we can insert shims into # it). oldEnabled <- compiler::enableJIT(0) on.exit(compiler::enableJIT(oldEnabled), TRUE) } # Forcing all of the promises for the loaded namespace now will avoid lazy-load # errors when the new package is loaded overtop the old one. # # Reloading devtools is a special case. Normally, objects in the # namespace become inaccessible if the namespace is unloaded before the # object has been accessed. Instead we force the object so they will still be # accessible. if (is_loaded(package)) { eapply(ns_env(package), force, all.names = TRUE) } # Check description file is ok check <- ("tools" %:::% ".check_package_description")( package_file("DESCRIPTION", path = path)) if (length(check) > 0) { msg <- utils::capture.output(("tools" %:::% "print.check_package_description")(check)) message("Invalid DESCRIPTION:\n", paste(msg, collapse = "\n")) } ## The unload() has to come before unload_dll(), for packages with ## compiled code, becauase they might crash of objects still use the ## DLL's memory. if (reset) { clear_cache() if (is_loaded(package)) unload(package, quiet = quiet) } if (is_loaded(package) && is.null(dev_meta(package))) { # If installed version of package loaded, unload it # (and also the DLLs) unload(package, quiet = quiet) } else { # Unload only DLLs unload_dll(package) } # Compile dll if requested if (missing(compile) && !missing(recompile)) { compile <- if (isTRUE(recompile)) TRUE else NA } 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) if (is_loaded(package) && is.null(dev_meta(package))) { unload(package, quiet = quiet) } # Set up the namespace environment ---------------------------------- # This mimics the procedure in loadNamespace if (!is_loaded(package)) create_ns_env(path) out <- list(env = ns_env(package)) # Load dependencies load_depends(path) load_imports(path) # Add shim objects to imports environment insert_imports_shims(package) out$data <- load_data(path) out$code <- load_code(path) register_s3(path) out$dll <- load_dll(path) # attach testthat to the search path if (isTRUE(attach_testthat) && package != "testthat") { ("base" %:::% "library")("testthat") } # Run namespace load hooks run_pkg_hook(package, "load") run_ns_load_actions(package) run_user_hook(package, "load") # Set up the package environment ------------------------------------ # Create the package environment if needed if (!is_attached(package)) attach_ns(package) # Copy over lazy data objects from the namespace environment export_lazydata(package) # Source test helpers into package environment if (uses_testthat(path) && helpers) { withr_with_envvar(c(NOT_CRAN = "true", DEVTOOLS_LOAD = "true"), testthat_source_test_helpers(find_test_dir(path), env = ns_env(package)) ) } # Set up the exports in the namespace metadata (this must happen after # the objects are loaded) setup_ns_exports(path, export_all, export_imports) # Copy over objects from the namespace environment export_ns(package) # Assign .Depends, if any, to package environment from namespace assign_depends(package) # Run hooks run_pkg_hook(package, "attach") run_user_hook(package, "attach") # Replace help and ? in utils package environment insert_global_shims() # Propagate new definitions to namespace imports of loaded packages. propagate_ns(package) invisible(out) } uses_testthat <- function(path = ".") { paths <- c( package_file("inst", "tests", path = path), package_file("tests", "testthat", path = path) ) any(dir.exists(paths)) } find_test_dir <- function(path) { testthat <- package_file("tests", "testthat", path = path) if (dir.exists(testthat)) return(testthat) inst <- package_file("inst", "tests", path = path) if (dir.exists(inst)) return(inst) stop("No testthat directories found in ", path, call. = FALSE) } propagate_ns <- function(package) { for (ns in loadedNamespaces()) { imports <- getNamespaceImports(ns) if (package %in% names(imports)) { env <- ns_env(ns) lapply(ls(env, all.names = TRUE), unlockBinding, env) imp <- imports_env(ns) lapply(ls(imp, all.names = TRUE), unlockBinding, imp) unlock_environment(env) unlock_environment(imp) update_imports(ns) lockEnvironment(env) lockEnvironment(imp) } } } pkgload/R/dev-topic.r0000644000176200001440000000536513315452721014165 0ustar liggesusers# Tools for indexing package documentation by alias, and for finding # the rd file for a given topic (alias). rd_files <- function(path) { path <- pkg_path(path) path_man <- package_file("man", path = path) files <- dir(path_man, pattern = "\\.[Rr]d$", full.names = TRUE) names(files) <- basename(files) sort_ci(files) } dev_topic_find <- function(topic, dev_packages = NULL) { topic <- dev_topic_parse(topic, dev_packages) path <- NULL pkg <- NULL for (pkg_name in topic$pkg_names) { path <- dev_topic_path(topic$topic, path = ns_path(pkg_name)) if (!is.null(path)) { return(list( path = path, pkg = pkg_name )) } } NULL } dev_topic_parse <- function(topic, dev_packages = NULL) { stopifnot(is.character(topic), length(topic) == 1) pieces <- strsplit(topic, ":::?")[[1]] if (length(pieces) == 1) { if (is.null(dev_packages)) { pkgs <- dev_packages() } else { pkgs <- dev_packages } } else { pkgs <- pieces[1] topic <- pieces[2] } list( topic = topic, pkg_names = pkgs ) } dev_topic_path <- function(topic, path = ".") { path <- pkg_path(path) # First see if a man file of that name exists man <- package_file("man", topic, path = path) if (file.exists(man)) return(man) # Next, look in index index <- dev_topic_index(path) if (topic %in% names(index)) return(package_file("man", last(index[[topic]]), path = path)) # Finally, try adding .Rd to name man_rd <- package_file("man", paste0(topic, ".Rd"), path = path) if (file.exists(man_rd)) return(man_rd) NULL } # Cache ------------------------------------------------------------------- dev_topic_indices <- new.env(parent = emptyenv()) dev_topic_index <- function(path = ".") { path <- pkg_path(path) package <- pkg_name(path) if (!exists(pkg_name(path), dev_topic_indices)) { dev_topic_indices[[package]] <- build_topic_index(path) } dev_topic_indices[[package]] } #' @export #' @rdname dev_help #' @param pkg_name Name of package. dev_topic_index_reset <- function(pkg_name) { if (exists(pkg_name, dev_topic_indices)) { rm(list = pkg_name, envir = dev_topic_indices) } invisible(TRUE) } # Topic index ------------------------------------------------------------- build_topic_index <- function(path = ".") { path <- pkg_path(path) rds <- rd_files(path) aliases <- function(path) { parsed <- tools::parse_Rd(path) tags <- vapply(parsed, function(x) attr(x, "Rd_tag")[[1]], character(1)) unlist(parsed[tags == "\\alias"]) } invert(lapply(rds, aliases)) } invert <- function(L) { if (length(L) == 0) return(L) t1 <- unlist(L) names(t1) <- rep(names(L), lapply(L, length)) tapply(names(t1), t1, c) } pkgload/R/has_tests.R0000644000176200001440000000123313365661742014230 0ustar liggesusers#' Was devtools installed with tests? #' #' @keywords internal #' @export has_tests <- function() { system.file("tests", package = "pkgload") != "" } #' Return the path to one of the packages in the devtools test dir #' #' devtools comes with some simple packages for testing. This function #' returns the path to them. #' #' @param package Name of the test package. #' @keywords internal #' @examples #' if (has_tests()) { #' pkgtest("testData") #' } #' @export pkgtest <- function(package) { stopifnot(has_tests()) path <- system.file(package = "pkgload", "tests", "testthat", package) if (path == "") stop(package, " not found", call. = FALSE) path } pkgload/README.md0000644000176200001440000000167613347020260013161 0ustar liggesusers# pkgload [![Travis-CI Build Status](https://travis-ci.org/r-lib/pkgload.svg?branch=master)](https://travis-ci.org/r-lib/pkgload) [![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/r-lib/pkgload?branch=master&svg=true)](https://ci.appveyor.com/project/r-lib/pkgload) [![codecov](https://codecov.io/gh/r-lib/pkgload/branch/master/graph/badge.svg)](https://codecov.io/gh/r-lib/pkgload) The goal of pkgload is to simulate the process of installing and loading a package, without actually doing the complete process, and hence making package iteration much faster. This was previously part of devtools (it was in fact the original motivation) but has been moved into its own package as part of the devtools [conscious uncoupling](https://github.com/r-lib/devtools#conscious-uncoupling). ## Usage In most cases you will not use pkgload directly, and instead you'll call it via `devtools::load_all()`. ``` r devtools::load_all() ``` pkgload/MD50000644000176200001440000002422113365666713012224 0ustar liggesusersb22ff1284d86b1be5372448940584073 *DESCRIPTION f1e3af4c299a60e1bf82c2ae33cc6296 *NAMESPACE daab3a7e1141f53280ea38a4ce454f02 *NEWS.md a9cebe46e41ae836bd6d65f9aa5393b6 *R/aaa.r 6ac20568873a918484dde36432f8ee60 *R/dev-example.r 48364c93899bc11572946a3fa1d279ab *R/dev-help.r cf2ddbdbdc3b6cb28adc699ce8e6c94a *R/dev-meta.r 6b24851d498304f91668411e26343245 *R/dev-topic.r ce8cd86bf8ce6af5800835dc5dd519a6 *R/enc.R ec20041c1e398e82c95c105a8ea8b542 *R/file-cache.r bdae5e091eaa6a85cd10591e26455d55 *R/has_tests.R f8f24fa5298cb72761587e2743559482 *R/imports-env.r 3828ece4f7f3d42bb62e7c5e117ea995 *R/inst.r afcf57e222f0c06009b5c450d59ed6c1 *R/load-code.r 39dc14e21ff57b1e6e32508f8f2b51b0 *R/load-data.r f896448493c8bca7dc16691c2d70e145 *R/load-depends.r 8838d07fb49f605d3608f38b092971fc *R/load-dll.r 0d0b876ede0ae5f55e61d6ed78255d75 *R/load.r f5486f08f7ba8c1f4b7a041a7a0d028f *R/namespace-env.r 894cd36b6b4bbea8ae8eac69a6e77eef *R/package-deps.r e8750f9b35d889cbdaa90408af13a3ad *R/package-env.r 7f2ce4388865870a75b8898bbab9324b *R/package.r c8d97095ed556c0c24a0524d59525942 *R/remove-s4-class.r b8fabf24e0ce1b1392568750622ff174 *R/run-loadhooks.r e22c2cf232af8f07bb480ea70d71f9d3 *R/shims.r f20ca6ada867484a0bd51e163d56f4a4 *R/source.r 524c4469740eb88b44d62618a6632768 *R/unload.r b35d02ee25f6f448a9e28cad5e5ea2b1 *R/utils.R af841b78a178ae4fd669326962aa0bdc *R/zzz.r 21c8a799336e5226c0ccccb9400d6f37 *README.md 04a4c539154069ec2326a98e04179aa1 *inst/WORDLIST b4f4e747e4036f6155784fd7ebc44f33 *man/check_dep_version.Rd 7ea4a165edbb09fde0ac6b1cb0168f48 *man/check_suggested.Rd 53f880e9d56c03fcb7f101ec85f54ef5 *man/dev_example.Rd 3301186d35c895c9110bc09eba202dbb *man/dev_help.Rd f00c77ba9f4a4eb759d9cddc317a5f1d *man/dev_meta.Rd 5f213ad75ab776275a30b7331a2f7517 *man/has_tests.Rd 7250dea5810b5785406674a49610254a *man/help.Rd 57958a7b3f37d83fe4c562bbf1e324bd *man/imports_env.Rd 2a7be3e73a89e6d254f6733c7076cb8b *man/inst.Rd 24c1d6c3190a88154d2e843d86ce18ac *man/is_dev_package.Rd 7d21e31ff1fb0ba699c8c09f67bc7950 *man/load_all.Rd 645d99b9ab2065a57b5ed382bb4fca83 *man/load_code.Rd cd41c163b83e1b1c2a235a60c3637695 *man/load_data.Rd b1adb0b029bbc2fad19fcd6eff7dd50b *man/load_dll.Rd 72fc1338153b7acee96a954a93e855ed *man/load_imports.Rd 7d6e8f73eddfae625f57ac686d03b7e5 *man/ns_env.Rd 76342a70136bbc1e1b63ad14cefed751 *man/package_file.Rd 6be08f7737a94400dd927ea1021a3a6c *man/packages.Rd e2b3a08c6efcd3deaef4d973fb2c13ce *man/parse_deps.Rd 341612f64731b62bc1b46b1dd6dcfc56 *man/parse_ns_file.Rd 53a7264d6e224823618250bc27acd815 *man/pkg_env.Rd d05d8f1c775815e9c2ad35ae8b4296ca *man/pkgtest.Rd a60b1512c7039cadaa60ddc946159946 *man/run_pkg_hook.Rd cd4d6c60cf75df1cf7a9fb2b3a3d8f7d *man/system.file.Rd 652d890bf17a3434f6055663487b9fc5 *man/unload.Rd e419dd223725848f4532894e9e5c3ba4 *src/unlock.c aeb5c0b6598ae3ce23b27208e6ceef19 *tests/testthat.R e83b9ae744fd434d5cf94a8f36c8f8e6 *tests/testthat/test-data.r adc3f71d06f3d6268039450bcb385333 *tests/testthat/test-depend.r 40403f91cb91f333774b1e483da7a2e0 *tests/testthat/test-description.r 2c610323ca46c0f0d134a736d48e31b8 *tests/testthat/test-dll.r 0e582e8334794e02109ef64e894e8d65 *tests/testthat/test-examples.R 68b8dab49b36ee11bf2f30de68827d80 *tests/testthat/test-examples.Rd 469b92b819e6e37888724b07c8d75f49 *tests/testthat/test-extraction.R 232c9c177ee0ae53d119113d02f8f28d *tests/testthat/test-help.r 9a1a7781345216b466f2e241daf89b2a *tests/testthat/test-imports.r 4b21c6b2d6c019e75e7ed98751b6b640 *tests/testthat/test-load-collate.r fb9ff788bb966363a891efd5e1fd8a71 *tests/testthat/test-load-hooks.r cac6f0633d2e1504e6dc7822d46d67a1 *tests/testthat/test-load.r 2229534d8dc55e86910105826ce02656 *tests/testthat/test-metadata.r 4cc889f93542e9bcf7843e72b636ccf1 *tests/testthat/test-namespace.r 795f9cdcf7dec52b149ce0c864b5fb1c *tests/testthat/test-package.R ccd0d821b2d99c6a432c560cdd0730da *tests/testthat/test-s4-export.r 9a1c23da0f0015f81f0ddeade1bb58d8 *tests/testthat/test-s4-sort.r 8e99e849ceba7137f304c82825c60ca0 *tests/testthat/test-s4-unload.r 3b344e76514a994775359b0b3750a3f6 *tests/testthat/test-shim.r 190573569db1b89f8a95a78b7a88a7c2 *tests/testthat/testCollateAbsent/DESCRIPTION 870a24794b577e7883169d2d0fa5cbc8 *tests/testthat/testCollateAbsent/R/a.r 0bce505aa6c5dc80635131e13597ae39 *tests/testthat/testCollateAbsent/R/b.r 9428933359013ba999fe5a1b9990022e *tests/testthat/testCollateAbsent/R/c.r a9d0f4eebceb98d9fffa3c14c56af663 *tests/testthat/testCollateExtra/DESCRIPTION 870a24794b577e7883169d2d0fa5cbc8 *tests/testthat/testCollateExtra/R/a.r e08c7a7b525b3028e34c92e8e93b9829 *tests/testthat/testCollateMissing/DESCRIPTION 870a24794b577e7883169d2d0fa5cbc8 *tests/testthat/testCollateMissing/R/a.r d119cb97e3acb0ddacf52c658960de8c *tests/testthat/testCollateMissing/R/b.r d050ad69653ed61d8a36ac8be8ebb59e *tests/testthat/testCollateOrder/DESCRIPTION 012592abf4b40a8d741b299df2ded05a *tests/testthat/testCollateOrder/NAMESPACE c8f75318162ecbd0c54038d1ef899ccb *tests/testthat/testCollateOrder/R/a.r 5dc6a5b47f4272a583e1a76ce68ae884 *tests/testthat/testCollateOrder/R/b.r cec09efd7fb2195e51c58be69e08fc28 *tests/testthat/testData/DESCRIPTION f9ea5333e6efd9c51fc46fe34164c341 *tests/testthat/testData/NAMESPACE d2a5cf8248b95340f49aabf60c1dee3f *tests/testthat/testData/R/sysdata.rda e03377f1cb29a3f1861e89fdb0604ad8 *tests/testthat/testData/data/a.rda aa6661f9ad2794e7d2c6d8a36023e78b *tests/testthat/testData/data/b.r cb7beacf5fecc82dc47093f30438a556 *tests/testthat/testDataLazy/DESCRIPTION f9ea5333e6efd9c51fc46fe34164c341 *tests/testthat/testDataLazy/NAMESPACE d2a5cf8248b95340f49aabf60c1dee3f *tests/testthat/testDataLazy/R/sysdata.rda e03377f1cb29a3f1861e89fdb0604ad8 *tests/testthat/testDataLazy/data/a.rda aa6661f9ad2794e7d2c6d8a36023e78b *tests/testthat/testDataLazy/data/b.r f48f2d7c5a051344beb8f2573e6cfb9a *tests/testthat/testDependMissing/DESCRIPTION 26813d0f7f8e272af05102662163c53b *tests/testthat/testDependMissing/R/a.r 0ad666081152c8e08f6f08a4a3726627 *tests/testthat/testDependsExists/DESCRIPTION dd195332a76b238203e61dc91f7cbe45 *tests/testthat/testDllLoad/DESCRIPTION 44de50ca195021dfec7b25689a9e8249 *tests/testthat/testDllLoad/NAMESPACE 1088899aa7d116bc6360163784e95ada *tests/testthat/testDllLoad/R/a.r 68c4f21a77f2f7cc331e49d03918a326 *tests/testthat/testDllLoad/src/null-test.c 7dad3921f220256ae4f0f1100767257b *tests/testthat/testDllRcpp/DESCRIPTION 029ade657ecf41cfeabeba27c10f35e7 *tests/testthat/testDllRcpp/NAMESPACE 6c1c2c0de9fc0036209d9ae52af0b4c7 *tests/testthat/testDllRcpp/R/RcppExports.R 6a302d3644bcf956a1c0d73224f2a184 *tests/testthat/testDllRcpp/src/RcppExports.cpp cdae79fe661bbb694dd79074547735b9 *tests/testthat/testDllRcpp/src/rcpp_hello_world.cpp 1ff255921b6b11864580451a5ed503b7 *tests/testthat/testHelp/DESCRIPTION dd91abab623dce54fcdc938af19ec008 *tests/testthat/testHelp/NAMESPACE a036467ccc9ed0fd3ec59585072ac863 *tests/testthat/testHelp/R/foofoo.r d72f199234418eb348b7aa2a76d665e3 *tests/testthat/testHelp/man/foofoo.Rd efec94ac198b7dff257466964248bb43 *tests/testthat/testHelp/man/testHelp-package.Rd 36983a265f6825008e4ca9c2b621f36f *tests/testthat/testHelp/man/testHelp.Rd 7bc1ed66c8a6ecfad94558f22d04fa54 *tests/testthat/testHooks/DESCRIPTION 5f10eb4bf9f2ee689fc932f60cc4a002 *tests/testthat/testHooks/R/a.r 69025f60f7052c8cd2774f074165ca02 *tests/testthat/testImportMissing/DESCRIPTION 26813d0f7f8e272af05102662163c53b *tests/testthat/testImportMissing/R/a.r 70f90352135085de8bc1f52b475cfd12 *tests/testthat/testImportVersion/DESCRIPTION 85601cb90b291bb14a88bc9e7349b653 *tests/testthat/testImportVersion/NAMESPACE 26813d0f7f8e272af05102662163c53b *tests/testthat/testImportVersion/R/a.r aa6661f9ad2794e7d2c6d8a36023e78b *tests/testthat/testImportVersion/R/b.r f5aa586562104703d2de8955d6b3b0e6 *tests/testthat/testLoadDir/DESCRIPTION 4ee0e944b871a30086d8ea8a9c227d4e *tests/testthat/testLoadDir/R/a.r e85d608e3478bd981ee081526b97e810 *tests/testthat/testLoadHelpers/DESCRIPTION dc21c19f0d6968ee25d441b2cf46017d *tests/testthat/testLoadHelpers/NAMESPACE ab9a8cfc24169f2062b7d3592bf96296 *tests/testthat/testLoadHelpers/R/a.r 214b2dd63d0e3e4d584e273d663616e2 *tests/testthat/testLoadHelpers/data/mtcars2.rda 819590dc157ecfe7cd9f191a1a2dce95 *tests/testthat/testLoadHelpers/tests/testthat.R eb6db5be8e1c7c528885de1e576aec17 *tests/testthat/testLoadHelpers/tests/testthat/helpers.R 73eb241b4e98ff44a42adf96e42f7543 *tests/testthat/testLoadHelpers/tests/testthat/test-foo.R ef5ca0c4a515d28c78e3f3bf187d2bad *tests/testthat/testLoadHooks/DESCRIPTION 700c3057dba39073ff2db2421ee90563 *tests/testthat/testLoadHooks/R/a.r 1494bf61f7e5b6e5a36a6df0faf2c486 *tests/testthat/testMissingNsObject/DESCRIPTION 9fb09fba835e687b843b78452bbeb820 *tests/testthat/testMissingNsObject/NAMESPACE 26813d0f7f8e272af05102662163c53b *tests/testthat/testMissingNsObject/R/a.r a6cc28f2792b0cf78aab540afe43e1f3 *tests/testthat/testNamespace/DESCRIPTION f4cc9c3507eb406de70a6a7c6ca63d8e *tests/testthat/testNamespace/NAMESPACE 26813d0f7f8e272af05102662163c53b *tests/testthat/testNamespace/R/a.r aa6661f9ad2794e7d2c6d8a36023e78b *tests/testthat/testNamespace/R/b.r a7e2f077bd7e448a798f153c7c153e94 *tests/testthat/testS4export/DESCRIPTION 2b3de241ad146080f3815429df0666b6 *tests/testthat/testS4export/NAMESPACE 9cdf6a778c52445fa46aae63fe4c7ac2 *tests/testthat/testS4export/R/all.r e4786dbff584b1b4d65b4460c02b0b87 *tests/testthat/testS4import/DESCRIPTION da89f1bf6b87610e418958974b95bb42 *tests/testthat/testS4import/NAMESPACE a0c94dee500c22e01d242a233d5f1039 *tests/testthat/testS4import/R/all.r 42b6d01401e9238fc97d18c2d33cd63b *tests/testthat/testS4sort/DESCRIPTION 77889dc631765bb10f12bdbdfa8542af *tests/testthat/testS4sort/NAMESPACE 43b55f669c6979ed4ed2f6080d9a63ae *tests/testthat/testS4sort/R/classes.r bfc904e6fb6910b903755139720af809 *tests/testthat/testS4union/DESCRIPTION 85f7ace341a0219ec4ae73022413b740 *tests/testthat/testS4union/NAMESPACE 4d30ff3208d42456afc2401585f97b1c *tests/testthat/testS4union/R/classes.r 583f3e7f7449571e9921cefb3ddc39cf *tests/testthat/testShim/A.txt 2aaa7783c966d1455430681fe9f46c7b *tests/testthat/testShim/C.txt d79dbc16cb00ebf4fc5783d3b830c278 *tests/testthat/testShim/DESCRIPTION 14451c613ae2c737269d0062f36eeb26 *tests/testthat/testShim/NAMESPACE 8960211fe22ff697115cc52c5f6616b6 *tests/testthat/testShim/R/a.r 119151c832b23525b2818019573bb463 *tests/testthat/testShim/inst/A.txt 490d1b2eb66ba6d4011ada175d264a41 *tests/testthat/testShim/inst/B.txt pkgload/DESCRIPTION0000644000176200001440000000234713365666713013427 0ustar liggesusersPackage: pkgload Title: Simulate Package Installation and Attach Version: 1.0.2 Authors@R: c( person("Hadley", "Wickham", role = "aut"), person("Jim", "Hester", , "james.hester@rstudio.com", role = c("aut", "cre")), person("Winston", "Chang", role = "aut"), person("RStudio", role = "cph"), person("R Core team", role = "ctb", comment = "Some namespace and vignette code extracted from base R") ) Description: Simulates the process of installing a package and then attaching it. This is a key part of the 'devtools' package as it allows you to rapidly iterate while developing a package. License: GPL-3 URL: https://github.com/r-lib/pkgload BugReports: https://github.com/r-lib/pkgload/issues Imports: desc, methods, pkgbuild, rlang, rprojroot, rstudioapi, utils, withr Suggests: bitops, covr, Rcpp, testthat Encoding: UTF-8 LazyData: true RoxygenNote: 6.1.0 NeedsCompilation: yes Packaged: 2018-10-29 19:56:19 UTC; jhester Author: Hadley Wickham [aut], Jim Hester [aut, cre], Winston Chang [aut], RStudio [cph], R Core team [ctb] (Some namespace and vignette code extracted from base R) Maintainer: Jim Hester Repository: CRAN Date/Publication: 2018-10-29 20:30:03 UTC pkgload/man/0000755000176200001440000000000013365662122012454 5ustar liggesuserspkgload/man/inst.Rd0000644000176200001440000000106213144323774013721 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/inst.r \name{inst} \alias{inst} \title{Get the installation path of a package} \usage{ inst(name) } \arguments{ \item{name}{the name of a package.} } \description{ Given the name of a package, this returns a path to the installed copy of the package, which can be passed to other devtools functions. } \details{ It searches for the package in \code{\link[=.libPaths]{.libPaths()}}. If multiple dirs are found, it will return the first one. } \examples{ inst("pkgload") inst("grid") } pkgload/man/pkgtest.Rd0000644000176200001440000000071313365661760014434 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/has_tests.R \name{pkgtest} \alias{pkgtest} \title{Return the path to one of the packages in the devtools test dir} \usage{ pkgtest(package) } \arguments{ \item{package}{Name of the test package.} } \description{ devtools comes with some simple packages for testing. This function returns the path to them. } \examples{ if (has_tests()) { pkgtest("testData") } } \keyword{internal} pkgload/man/load_all.Rd0000644000176200001440000001076413365661760014531 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/load.r \name{load_all} \alias{load_all} \title{Load complete package.} \usage{ load_all(path = ".", reset = TRUE, compile = NA, export_all = TRUE, export_imports = export_all, helpers = TRUE, attach_testthat = uses_testthat(path), quiet = FALSE, recompile = FALSE) } \arguments{ \item{path}{Path to a package, or within a package.} \item{reset}{clear package environment and reset file cache before loading any pieces of the package. This is equivalent to running \code{\link[=unload]{unload()}} and is the default. Use \code{reset = FALSE} may be faster for large code bases, but is a significantly less accurate approximation.} \item{compile}{If \code{TRUE} always recompiles the package; if \code{NA} recompiles if needed (as determined by \code{\link[pkgbuild:needs_compile]{pkgbuild::needs_compile()}}); if \code{FALSE}, never recompiles.} \item{export_all}{If \code{TRUE} (the default), export all objects. If \code{FALSE}, export only the objects that are listed as exports in the NAMESPACE file.} \item{export_imports}{If \code{TRUE} (the default), export all objects that are imported by the package. If \code{FALSE} export only objects defined in the package.} \item{helpers}{if \code{TRUE} loads \pkg{testthat} test helpers.} \item{attach_testthat}{If \code{TRUE}, attach \pkg{testthat} to the search path, which more closely mimics the environment within test files.} \item{quiet}{if \code{TRUE} suppresses output from this function.} \item{recompile}{DEPRECATED. force a recompile of DLL from source code, if present. This is equivalent to running \code{\link[pkgbuild:clean_dll]{pkgbuild::clean_dll()}} before \code{load_all}} } \description{ \code{load_all} loads a package. It roughly simulates what happens when a package is installed and loaded with \code{\link[=library]{library()}}. } \details{ Currently \code{load_all}: \itemize{ \item Loads all data files in \code{data/}. See \code{\link[=load_data]{load_data()}} for more details. \item Sources all R files in the R directory, storing results in environment that behaves like a regular package namespace. See below and \code{\link[=load_code]{load_code()}} for more details. \item Compiles any C, C++, or Fortran code in the \code{src/} directory and connects the generated DLL into R. See \code{\link[=compile_dll]{compile_dll()}} for more details. \item Runs \code{.onAttach()}, \code{.onLoad()} and \code{.onUnload()} functions at the correct times. \item If you use \pkg{testthat}, will load all test helpers so you can access them interactively. devtools sets the \code{DEVTOOLS_LOAD} environment variable to \code{"true"} to let you check whether the helpers are run during package loading. } } \section{Namespaces}{ The namespace environment \code{}, is a child of the imports environment, which has the name attribute \code{imports:pkgname}. It is in turn is a child of \code{}, which is a child of the global environment. (There is also a copy of the base namespace that is a child of the empty environment.) The package environment \code{} is an ancestor of the global environment. Normally when loading a package, the objects listed as exports in the NAMESPACE file are copied from the namespace to the package environment. However, \code{load_all} by default will copy all objects (not just the ones listed as exports) to the package environment. This is useful during development because it makes all objects easy to access. To export only the objects listed as exports, use \code{export_all=FALSE}. This more closely simulates behavior when loading an installed package with \code{\link[=library]{library()}}, and can be useful for checking for missing exports. } \section{Shim files}{ \code{load_all} also inserts shim functions into the imports environment of the loaded package. It presently adds a replacement version of \code{system.file} which returns different paths from \code{base::system.file}. This is needed because installed and uninstalled package sources have different directory structures. Note that this is not a perfect replacement for \code{base::system.file}. } \examples{ \dontrun{ # Load the package in the current directory load_all("./") # Running again loads changed files load_all("./") # With reset=TRUE, unload and reload the package for a clean start load_all("./", TRUE) # With export_all=FALSE, only objects listed as exports in NAMESPACE # are exported load_all("./", export_all = FALSE) } } \keyword{programming} pkgload/man/ns_env.Rd0000644000176200001440000000143113365661523014236 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/namespace-env.r \name{ns_env} \alias{ns_env} \title{Return the namespace environment for a package.} \usage{ ns_env(package) } \arguments{ \item{package}{package name.} } \description{ Contains all (exported and non-exported) objects, and is a descendant of \code{R_GlobalEnv}. The hierarchy is \code{}, \code{}, \code{}, and then \code{R_GlobalEnv}. } \details{ If the package is not loaded, this function returns \code{NULL}. } \seealso{ \code{\link[=pkg_env]{pkg_env()}} for the attached environment that contains the exported objects. \code{\link[=imports_env]{imports_env()}} for the environment that contains imported objects for the package. } \keyword{internal} pkgload/man/parse_ns_file.Rd0000644000176200001440000000066513144323774015565 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/namespace-env.r \name{parse_ns_file} \alias{parse_ns_file} \title{Parses the NAMESPACE file for a package} \usage{ parse_ns_file(path = ".") } \arguments{ \item{path}{Path to a package, or within a package.} } \description{ Parses the NAMESPACE file for a package } \examples{ if (has_tests()) { parse_ns_file(pkgtest("testLoadHooks")) } } \keyword{internal} pkgload/man/system.file.Rd0000644000176200001440000000347413365661760015224 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/shims.r \name{system.file} \alias{system.file} \alias{shim_system.file} \title{Replacement version of system.file} \usage{ # system.file(..., package = "base", lib.loc = NULL, mustWork = FALSE) } \arguments{ \item{...}{character vectors, specifying subdirectory and file(s) within some package. The default, none, returns the root of the package. Wildcards are not supported.} \item{package}{a character string with the name of a single package. An error occurs if more than one package name is given.} \item{lib.loc}{a character vector with path names of \R libraries. See \sQuote{Details} for the meaning of the default value of \code{NULL}.} \item{mustWork}{logical. If \code{TRUE}, an error is given if there are no matching files.} } \description{ This function is meant to intercept calls to \code{\link[base:system.file]{base::system.file()}}, so that it behaves well with packages loaded by devtools. It is made available when a package is loaded with \code{\link[=load_all]{load_all()}}. } \details{ When \code{system.file} is called from the R console (the global environment), this function detects if the target package was loaded with \code{\link[=load_all]{load_all()}}, and if so, it uses a customized method of searching for the file. This is necessary because the directory structure of a source package is different from the directory structure of an installed package. When a package is loaded with \code{load_all}, this function is also inserted into the package's imports environment, so that calls to \code{system.file} from within the package namespace will use this modified version. If this function were not inserted into the imports environment, then the package would end up calling \code{base::system.file} instead. } pkgload/man/load_dll.Rd0000644000176200001440000000046213144323774014521 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/load-dll.r \name{load_dll} \alias{load_dll} \title{Load a compiled DLL} \usage{ load_dll(path = ".") } \arguments{ \item{path}{Path to a package, or within a package.} } \description{ Load a compiled DLL } \keyword{programming} pkgload/man/load_data.Rd0000644000176200001440000000052113144323774014653 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/load-data.r \name{load_data} \alias{load_data} \title{Load data.} \usage{ load_data(path = ".") } \arguments{ \item{path}{Path to a package, or within a package.} } \description{ Loads all \code{.RData} files in the data subdirectory. } \keyword{programming} pkgload/man/dev_help.Rd0000644000176200001440000000245613365662217014545 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/dev-help.r, R/dev-topic.r \name{dev_help} \alias{dev_help} \alias{dev_topic_index_reset} \title{In-development help for package loaded with devtools} \usage{ dev_help(topic, dev_packages = NULL, stage = "render", type = getOption("help_type")) dev_topic_index_reset(pkg_name) } \arguments{ \item{topic}{name of help to search for.} \item{dev_packages}{A character vector of package names to search within. If \code{NULL}, defaults to all packages loaded by devtools.} \item{stage}{at which stage ("build", "install", or "render") should \code{\\Sexpr} macros be executed? This is only important if you're using \code{\\Sexpr} macro's in your Rd files.} \item{type}{of html to produce: \code{"html"} or \code{"text"}. Defaults to your default documentation type.} \item{pkg_name}{Name of package.} } \description{ \code{dev_help} searches for source documentation provided in packages loaded by devtools. To improve performance, the \code{.Rd} files are parsed to create to index once, then cached. Use \code{dev_topic_index_reset} to clear that index. } \examples{ \dontrun{ library("ggplot2") help("ggplot") # loads installed documentation for ggplot load_all("ggplot2") dev_help("ggplot") # loads development documentation for ggplot } } pkgload/man/run_pkg_hook.Rd0000644000176200001440000000067013144323774015435 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/run-loadhooks.r \name{run_pkg_hook} \alias{run_pkg_hook} \alias{run_user_hook} \title{Run user and package hooks.} \usage{ run_pkg_hook(package, hook) run_user_hook(package, hook) } \arguments{ \item{package}{package name.} \item{hook}{hook name: one of "load", "unload", "attach", or "detach"} } \description{ Run user and package hooks. } \keyword{internal} pkgload/man/dev_example.Rd0000644000176200001440000000223113365656651015244 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/dev-example.r \name{dev_example} \alias{dev_example} \alias{run_example} \title{Run a examples for an in-development function.} \usage{ dev_example(topic, quiet = FALSE) run_example(path, test = FALSE, run = FALSE, env = new.env(parent = globalenv()), quiet = FALSE) } \arguments{ \item{topic}{Name or topic (or name of Rd) file to run examples for} \item{quiet}{If \code{TRUE}, does not echo code to console.} \item{path}{Path to \code{.Rd} file} \item{test}{if \code{TRUE}, code in \code{\\donttest{}} will be commented out. If \code{FALSE}, code in \code{\\testonly{}} will be commented out. This parameter is only used in R 3.2 and greater.} \item{run}{if \code{TRUE}, code in \code{\\dontrun{}} will be commented out.} \item{env}{Environment in which code will be run.} } \description{ \code{dev_example} is a replacement for \code{example}. \code{run_example} is a low-level function that takes a path to an Rd file. } \examples{ \dontrun{ # Runs installed example: library("ggplot2") example("ggplot") # Runs develoment example: dev_example("ggplot") } } \concept{example functions} pkgload/man/unload.Rd0000644000176200001440000000224313241561654014227 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/unload.r \name{unload} \alias{unload} \title{Unload a package} \usage{ unload(package = pkg_name(), quiet = FALSE) } \arguments{ \item{package}{package name.} \item{quiet}{if \code{TRUE} suppresses output from this function.} } \description{ This function attempts to cleanly unload a package, including unloading its namespace, deleting S4 class definitions and unloading any loaded DLLs. Unfortunately S4 classes are not really designed to be cleanly unloaded, and so we have to manually modify the class dependency graph in order for it to work - this works on the cases for which we have tested but there may be others. Similarly, automated DLL unloading is best tested for simple scenarios (particularly with \code{useDynLib(pkgname)} and may fail in other cases. If you do encounter a failure, please file a bug report at \url{http://github.com/r-lib/pkgload/issues}. } \examples{ \dontrun{ # Unload package that is in current directory unload() # Unload package that is in ./ggplot2/ unload(pkg_name("ggplot2/")) library(ggplot2) # unload the ggplot2 package directly by name unload("ggplot2") } } pkgload/man/is_dev_package.Rd0000644000176200001440000000057713102156023015663 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/package.r \name{is_dev_package} \alias{is_dev_package} \title{Is the package currently under development?} \usage{ is_dev_package(name) } \arguments{ \item{name}{the name of a package.} } \description{ Returns \code{TRUE} or \code{FALSE} depending on if the package has been loaded by \strong{pkgload}. } pkgload/man/dev_meta.Rd0000644000176200001440000000113713144323774014533 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/dev-meta.r \name{dev_meta} \alias{dev_meta} \title{Return devtools metadata environment} \usage{ dev_meta(name) } \arguments{ \item{name}{The name of a loaded package} } \description{ If the package was not loaded with devtools, returns \code{NULL}. } \examples{ dev_meta("stats") # NULL if (has_tests()) { # Load the test package in directory "testLoadHooks" load_all(pkgtest("testLoadHooks")) # Get metdata for the package x <- dev_meta("testLoadHooks") as.list(x) # Clean up. unload("testLoadHooks") } } \keyword{internal} pkgload/man/load_code.Rd0000644000176200001440000000062213144323774014656 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/load-code.r \name{load_code} \alias{load_code} \title{Load R code.} \usage{ load_code(path = ".") } \arguments{ \item{path}{Path to a package, or within a package.} } \description{ Load all R code in the \code{R} directory. The first time the code is loaded, \code{.onLoad} will be run if it exists. } \keyword{programming} pkgload/man/help.Rd0000644000176200001440000000405613315225420013667 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/dev-help.r \name{help} \alias{help} \alias{shim_help} \alias{?} \alias{shim_question} \title{Drop-in replacements for help and ? functions} \usage{ # help(topic, package = NULL, ...) # ?e2 # e1?e2 } \arguments{ \item{topic}{A name or character string specifying the help topic.} \item{package}{A name or character string specifying the package in which to search for the help topic. If NULL, search all packages.} \item{...}{Additional arguments to pass to \code{\link[utils:help]{utils::help()}}.} \item{e1}{First argument to pass along to \code{utils::}?``.} \item{e2}{Second argument to pass along to \code{utils::}?``.} } \description{ The \code{?} and \code{help} functions are replacements for functions of the same name in the utils package. They are made available when a package is loaded with \code{\link[=load_all]{load_all()}}. } \details{ The \code{?} function is a replacement for \code{\link[utils:?]{utils::?()}} from the utils package. It will search for help in devtools-loaded packages first, then in regular packages. The \code{help} function is a replacement for \code{\link[utils:help]{utils::help()}} from the utils package. If \code{package} is not specified, it will search for help in devtools-loaded packages first, then in regular packages. If \code{package} is specified, then it will search for help in devtools-loaded packages or regular packages, as appropriate. } \examples{ \dontrun{ # This would load devtools and look at the help for load_all, if currently # in the devtools source directory. load_all() ?load_all help("load_all") } # To see the help pages for utils::help and utils::`?`: help("help", "utils") help("?", "utils") \dontrun{ # Examples demonstrating the multiple ways of supplying arguments # NB: you can't do pkg <- "ggplot2"; help("ggplot2", pkg) help(lm) help(lm, stats) help(lm, 'stats') help('lm') help('lm', stats) help('lm', 'stats') help(package = stats) help(package = 'stats') topic <- "lm" help(topic) help(topic, stats) help(topic, 'stats') } } pkgload/man/load_imports.Rd0000644000176200001440000000065113365662113015441 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/imports-env.r \name{load_imports} \alias{load_imports} \title{Load all of the imports for a package} \usage{ load_imports(path = ".") } \description{ The imported objects are copied to the imports environment, and are not visible from \code{R_GlobalEnv}. This will automatically load (but not attach) the dependency packages. } \keyword{internal} pkgload/man/packages.Rd0000644000176200001440000000165513144323774014532 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/package.r \name{packages} \alias{packages} \alias{pkg_path} \alias{pkg_name} \alias{pkg_desc} \alias{pkg_version} \alias{pkg_ns} \title{Helper functions for working with development packages.} \usage{ pkg_path(path = ".") pkg_name(path = ".") pkg_desc(path = ".") pkg_version(path = ".") pkg_ns(path = ".") } \arguments{ \item{path}{Path to a package, or within a package.} } \description{ All functions search recursively up the directory tree from the input path until they find a DESCRIPTION file. } \section{Functions}{ \itemize{ \item \code{pkg_path}: Return the normalized package path. \item \code{pkg_name}: Return the package name. \item \code{pkg_desc}: Return the package DESCRIPTION as a \code{\link[desc:desc]{desc::desc()}} object. \item \code{pkg_version}: Return the package version. \item \code{pkg_ns}: Return the package namespace. }} pkgload/man/check_suggested.Rd0000644000176200001440000000112013241561510016054 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils.R \name{check_suggested} \alias{check_suggested} \title{Check that the version of an suggested package satisfies the requirements} \usage{ check_suggested(package, version = NULL, compare = NA, path = inst("pkgload")) } \arguments{ \item{package}{The name of the suggested package} \item{version}{The version of the package} \item{compare}{The comparison operator to use to check the version} } \description{ Check that the version of an suggested package satisfies the requirements } \keyword{internal} pkgload/man/parse_deps.Rd0000644000176200001440000000125313061562260015064 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/package-deps.r \name{parse_deps} \alias{parse_deps} \title{Parse package dependency strings.} \usage{ parse_deps(string) } \arguments{ \item{string}{to parse. Should look like \code{"R (>= 3.0), ggplot2"} etc.} } \value{ list of two character vectors: \code{name} package names, and \code{version} package versions. If version is not specified, it will be stored as NA. } \description{ Parse package dependency strings. } \examples{ parse_deps("httr (< 2.1),\\nRCurl (>= 3)") # only package dependencies are returned parse_deps("utils (== 2.12.1),\\ntools,\\nR (>= 2.10),\\nmemoise") } \keyword{internal} pkgload/man/pkg_env.Rd0000644000176200001440000000211713144323774014377 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/package-env.r \name{pkg_env} \alias{pkg_env} \title{Return package environment} \usage{ pkg_env(package) } \arguments{ \item{package}{package name.} } \description{ This is an environment like \code{}. The package environment contains the exported objects from a package. It is attached, so it is an ancestor of \code{R_GlobalEnv}. } \details{ When a package is loaded the normal way, using \code{\link[=library]{library()}}, this environment contains only the exported objects from the namespace. However, when loaded with \code{\link[=load_all]{load_all()}}, this environment will contain all the objects from the namespace, unless \code{load_all} is used with \code{export_all=FALSE}. If the package is not attached, this function returns \code{NULL}. } \seealso{ \code{\link[=ns_env]{ns_env()}} for the namespace environment that all the objects (exported and not exported). \code{\link[=imports_env]{imports_env()}} for the environment that contains imported objects for the package. } \keyword{internal} pkgload/man/has_tests.Rd0000644000176200001440000000040413061562260014731 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/has_tests.R \name{has_tests} \alias{has_tests} \title{Was devtools installed with tests?} \usage{ has_tests() } \description{ Was devtools installed with tests? } \keyword{internal} pkgload/man/imports_env.Rd0000644000176200001440000000126513315225420015303 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/imports-env.r \name{imports_env} \alias{imports_env} \title{Return imports environment for a package} \usage{ imports_env(package) } \arguments{ \item{path}{TODO: fix doc} } \description{ Contains objects imported from other packages. Is the parent of the package namespace environment, and is a child of \code{}, which is a child of \code{R_GlobalEnv}. } \seealso{ \code{\link[=ns_env]{ns_env()}} for the namespace environment that all the objects (exported and not exported). \code{\link[=pkg_env]{pkg_env()}} for the attached environment that contains the exported objects. } \keyword{internal} pkgload/man/check_dep_version.Rd0000644000176200001440000000105613145330631016410 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/package-deps.r \name{check_dep_version} \alias{check_dep_version} \title{Check that the version of an imported package satisfies the requirements} \usage{ check_dep_version(dep_name, dep_ver = "*") } \arguments{ \item{dep_name}{The name of the package with objects to import} \item{dep_ver}{The version of the package, this includes the specified comparison operator.} } \description{ Check that the version of an imported package satisfies the requirements } \keyword{internal} pkgload/man/package_file.Rd0000644000176200001440000000115413143401046015324 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/package.r \name{package_file} \alias{package_file} \title{Find file in a package.} \usage{ package_file(..., path = ".") } \arguments{ \item{...}{Components of the path.} \item{path}{Place to start search for package directory.} } \description{ It always starts by finding by walking up the path until it finds the root directory, i.e. a directory containing \code{DESCRIPTION}. If it cannot find the root directory, or it can't find the specified path, it will throw an error. } \examples{ \dontrun{ package_file("figures", "figure_1") } }