pkgload/0000755000176200001440000000000014151432552011675 5ustar liggesuserspkgload/NAMESPACE0000644000176200001440000000112214117650427013115 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) pkgload/README.md0000644000176200001440000000155014151367411013156 0ustar liggesusers# pkgload [![R-CMD-check](https://github.com/r-lib/pkgload/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/pkgload/actions) [![Codecov test coverage](https://codecov.io/gh/r-lib/pkgload/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/pkgload?branch=main) 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/man/0000755000176200001440000000000014151367411012451 5ustar liggesuserspkgload/man/dev_help.Rd0000644000176200001440000000247213750505224014533 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 \verb{\\\\Sexpr} macros be executed? This is only important if you're using \verb{\\\\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/package_file.Rd0000644000176200001440000000115413206753363015340 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") } } pkgload/man/load_data.Rd0000644000176200001440000000052113750540726014654 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/run_pkg_hook.Rd0000644000176200001440000000067013206753363015435 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/load_dll.Rd0000644000176200001440000000046213206753363014521 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/imports_env.Rd0000644000176200001440000000126513750505224015311 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 \verb{}, 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/load_imports.Rd0000644000176200001440000000065113652577143015450 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/system.file.Rd0000644000176200001440000000347713750505224015215 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{ shim_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/has_tests.Rd0000644000176200001440000000040413206753363014740 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/dev_example.Rd0000644000176200001440000000274714015406141015234 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, run_donttest = FALSE, run_dontrun = FALSE, env = new.env(parent = globalenv()), quiet = FALSE, macros = NULL, run, test ) } \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{run_donttest}{if \code{TRUE}, do run \verb{\donttest} sections in the Rd files. out.} \item{run_dontrun}{if \code{TRUE}, do run \verb{\dontrun} sections in the Rd files.} \item{env}{Environment in which code will be run.} \item{macros}{Custom macros to use to parse the \code{.Rd} file. See the \code{macros} argument of \code{\link[tools:parse_Rd]{tools::parse_Rd()}}. If \code{NULL}, then the \code{\link[tools:Rd2HTML]{tools::Rd2ex()}} (and \code{\link[tools:parse_Rd]{tools::parse_Rd()}}) default is used.} \item{run, test}{Deprecated, see \code{run_dontrun} and \code{run_donttest} above.} } \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/check_suggested.Rd0000644000176200001440000000111413750505224016064 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 used to check the version} } \description{ Check that the version of an suggested package satisfies the requirements } \keyword{internal} pkgload/man/inst.Rd0000644000176200001440000000106213206753363013721 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/is_dev_package.Rd0000644000176200001440000000057713206753363015702 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/unload.Rd0000644000176200001440000000224414044442422014221 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{https://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/load_code.Rd0000644000176200001440000000062213206753363014656 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/packages.Rd0000644000176200001440000000165513206753363014532 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/load_all.Rd0000644000176200001440000001206614151367411014514 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, warn_conflicts = TRUE ) } \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 largely equivalent to running \code{\link[=unload]{unload()}}, however the old namespaces are not completely removed and no \code{.onUnload()} hooks are called. 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}} \item{warn_conflicts}{If \code{TRUE}, issues a warning if a function in the global environment masks a function in the package. This can happen when you accidentally source a \code{.R} file, rather than using \code{load_all()}, or if you define a function directly in the R console. This is frustrating to debug, as it feels like the changes you make to the package source aren't having the expected effect.} } \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 \verb{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 \verb{src/} directory and connects the generated DLL into R. See \code{pkgload::compile_dll()} for more details. \item Loads any compiled translations in \code{inst/po}. \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 \verb{}, is a child of the imports environment, which has the name attribute \code{imports:pkgname}. It is in turn is a child of \verb{}, 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 \verb{} 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/help.Rd0000644000176200001440000000406514015406141013666 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 \verb{utils::}?``.} \item{e2}{Second argument to pass along to \verb{utils::}?``.} } \description{ The \verb{?} 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 \verb{?} function is a replacement for \code{\link[utils:Question]{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/check_dep_version.Rd0000644000176200001440000000105613206753363016421 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/dev_meta.Rd0000644000176200001440000000113713206753363014533 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/parse_deps.Rd0000644000176200001440000000124713750505224015071 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/ns_env.Rd0000644000176200001440000000143113750505224014227 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 \verb{}, \verb{}, \verb{}, 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/pkg_env.Rd0000644000176200001440000000211713750505224014372 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 \verb{}. 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/parse_ns_file.Rd0000644000176200001440000000066513206753363015565 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/pkgtest.Rd0000644000176200001440000000071313652577143014434 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/DESCRIPTION0000644000176200001440000000243714151432552013411 0ustar liggesusersPackage: pkgload Title: Simulate Package Installation and Attach Version: 1.2.4 Authors@R: c( person("Hadley", "Wickham", role = "aut"), person("Winston", "Chang", role = "aut"), person("Jim", "Hester", role = "aut"), person("Lionel", "Henry", , "lionel@rstudio.com", role = c("aut", "cre")), 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: cli, crayon, desc, methods, rlang, rprojroot, rstudioapi, utils, withr Suggests: bitops, covr, pkgbuild, Rcpp, testthat Encoding: UTF-8 RoxygenNote: 7.1.2 NeedsCompilation: no Packaged: 2021-11-30 09:32:04 UTC; lionel Author: Hadley Wickham [aut], Winston Chang [aut], Jim Hester [aut], Lionel Henry [aut, cre], RStudio [cph], R Core team [ctb] (Some namespace and vignette code extracted from base R) Maintainer: Lionel Henry Repository: CRAN Date/Publication: 2021-11-30 14:30:02 UTC pkgload/tests/0000755000176200001440000000000014151367624013046 5ustar liggesuserspkgload/tests/testthat/0000755000176200001440000000000014151432552014677 5ustar liggesuserspkgload/tests/testthat/testLoadHooks/0000755000176200001440000000000014024302057017455 5ustar liggesuserspkgload/tests/testthat/testLoadHooks/DESCRIPTION0000644000176200001440000000031113206753363021171 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/testLoadHooks/R/0000755000176200001440000000000014024307517017664 5ustar liggesuserspkgload/tests/testthat/testLoadHooks/R/a.r0000644000176200001440000000136113046675565020306 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/testImportMissing/0000755000176200001440000000000014024300155020373 5ustar liggesuserspkgload/tests/testthat/testImportMissing/DESCRIPTION0000644000176200001440000000035513206753363022122 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/testImportMissing/R/0000755000176200001440000000000014024277455020614 5ustar liggesuserspkgload/tests/testthat/testImportMissing/R/a.r0000644000176200001440000000000713046675565021223 0ustar liggesusersa <- 1 pkgload/tests/testthat/test-imports.r0000644000176200001440000000327213375234477017555 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/test-examples.Rd0000644000176200001440000000022413046675565017776 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/test-examples.R0000644000176200001440000000216613750505224017623 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"), run_donttest = TRUE, quiet = TRUE) expect_equal(env$a, 2) }) test_that("run dontrun when requested", { env <- run_example(test_path("test-examples.Rd"), run_dontrun = 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) }) test_that("can use system macros", { load_all(test_path("testHelp")) on.exit(unload(test_path("testHelp"))) expect_silent( run_example( test_path("testHelp", "man", "testSysMacro.Rd"), quiet = TRUE ) ) }) test_that("can use extra Rd macros", { macros <- load_rd_macros("testHelp") expect_silent( run_example( test_path("testHelp", "man", "testCustomMacro.Rd"), quiet = TRUE, macros = macros ) ) }) pkgload/tests/testthat/test-namespace.r0000644000176200001440000001056113375234477020013 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-depend.r0000644000176200001440000000366513375234477017325 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/testDependsExists/0000755000176200001440000000000014024320725020356 5ustar liggesuserspkgload/tests/testthat/testDependsExists/DESCRIPTION0000644000176200001440000000037713243331266022077 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-help.r0000644000176200001440000000606013652577143017004 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]) expect_identical(shim_question(base::min)[1], utils::`?`(base::min)[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/testS4sort/0000755000176200001440000000000014024302473016772 5ustar liggesuserspkgload/tests/testthat/testS4sort/NAMESPACE0000644000176200001440000000004413046675565020231 0ustar liggesusersexportClass(A, B, C, D, E, F, G, H) pkgload/tests/testthat/testS4sort/DESCRIPTION0000644000176200001440000000041313206753363020507 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/testS4sort/R/0000755000176200001440000000000014024305733017175 5ustar liggesuserspkgload/tests/testthat/testS4sort/R/classes.r0000644000176200001440000000060713046675565021040 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/test-shim.r0000644000176200001440000000745713046675565017033 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/test-load.r0000644000176200001440000000662514122050221016752 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)) # object defined in helper using explicitly qualified package name expect_equal(helper_baz, baz) unload("testLoadHelpers") }) test_that("warn_if_conflicts warns for conflicts and both objects are functions", { e1 <- new.env(parent = emptyenv()) e2 <- new.env(parent = emptyenv()) e1$foo <- function() "foo" e2$bar <- function() "bar" # no warning if no conflicts expect_warning(warn_if_conflicts("pkg", e1, e2), NA) e2$foo <- function() "foo2" # warning for a conflict withr::with_options(c(crayon.enabled = FALSE), expect_warning( warn_if_conflicts("pkg", e1, e2), "foo().*masks.*pkg::foo()" ) ) }) test_that("warn_if_conflicts does not warn for conflicts when one of the objects is not a function", { e1 <- new.env(parent = emptyenv()) e2 <- new.env(parent = emptyenv()) e1$foo <- function() "foo" e2$foo <- "foo" expect_warning(warn_if_conflicts("pkg", e1, e2), NA) }) test_that("unloading or reloading forces bindings", { forced <- FALSE withCallingHandlers( forced = function(...) forced <<- TRUE, { # Allow running test interactively on.exit(unload("testLoadLazy")) load_all("testLoadLazy") expect_false(forced) load_all("testLoadLazy") expect_true(forced) } ) }) test_that("reloading a package unloads deleted S3 methods", { x <- structure(list(), class = "pkgload_foobar") load_all("testS3removed") expect_equal(as.character(x), "registered") # Hold a reference to the generic in the currently loaded namespace stale_generic <- testS3removed::my_generic load_all("testS3removed2") expect_equal(as.character(x), character()) # Still works because we don't unregister methods for the package # being unloaded (r-lib/vctrs#1341) expect_equal(stale_generic(x), "registered") }) test_that("reloading a package reloads foreign methods (#163)", { x <- structure(list(), class = "foreign_foobar") load_all("testS3removed") registerS3method( "my_generic", "foreign_foobar", function(...) "OK", envir = ns_env("testS3removed") ) expect_equal(my_generic(x), "OK") load_all("testS3removed") expect_equal(my_generic(x), "OK") }) test_that("reloading a package reloads own methods", { x <- structure(list(), class = "pkgload_foobar") load_all("testS3removed") ns <- ns_env("testS3removed") method <- function(...) "Not OK" environment(method) <- ns registerS3method( "my_generic", "pkgload_foobar", method, envir = ns ) # `registerS3method()` doesn't seem to overwrite methods on older # versions of R < 3.5.0. if (is_installed("base", "3.5.0")) { expect_equal(my_generic(x), "Not OK") } load_all("testS3removed") expect_equal(my_generic(x), "registered") }) test_that("load_all() errors when no DESCRIPTION found", { withr::with_tempdir({ expect_error(load_all(), class = "pkgload_no_desc") }) }) pkgload/tests/testthat/testDataLazy/0000755000176200001440000000000014024405505017305 5ustar liggesuserspkgload/tests/testthat/testDataLazy/NAMESPACE0000644000176200001440000000002713046675565020545 0ustar liggesusersexport(sysdata_export) pkgload/tests/testthat/testDataLazy/data/0000755000176200001440000000000014024324120020207 5ustar liggesuserspkgload/tests/testthat/testDataLazy/data/b.r0000644000176200001440000000000713046675565020641 0ustar liggesusersb <- 2 pkgload/tests/testthat/testDataLazy/data/a.rda0000644000176200001440000000007313046675565021150 0ustar liggesusers‹ r‰0âŠàb```b`âbf “… H02°0p‚èD ÁbØ`€(+ýL8pkgload/tests/testthat/testDataLazy/DESCRIPTION0000644000176200001440000000031213046675565021031 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/testDataLazy/R/0000755000176200001440000000000014024302255017504 5ustar liggesuserspkgload/tests/testthat/testDataLazy/R/sysdata.rda0000644000176200001440000000013013046675565021662 0ustar liggesusers‹ r‰0âŠàb```b`âgf`b2Y˜€# 'æ+®,NI,IŒO­(È/*‰€d8 Eµ Lu^~š˜†5µÝvpkgload/tests/testthat/testS4import/0000755000176200001440000000000014024307730017316 5ustar liggesuserspkgload/tests/testthat/testS4import/NAMESPACE0000644000176200001440000000006213046675565020554 0ustar liggesusersimportClassesFrom(testS4export, class_to_export) pkgload/tests/testthat/testS4import/DESCRIPTION0000644000176200001440000000060213046675565021043 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/testS4import/R/0000755000176200001440000000000014024306240017512 5ustar liggesuserspkgload/tests/testthat/testS4import/R/all.r0000644000176200001440000000006113046675565020470 0ustar liggesuserssetClass('derived', contains='class_to_export') pkgload/tests/testthat/testLoadDir/0000755000176200001440000000000014024300017017102 5ustar liggesuserspkgload/tests/testthat/testLoadDir/DESCRIPTION0000644000176200001440000000030713046675565020642 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/testLoadDir/R/0000755000176200001440000000000014024303732017312 5ustar liggesuserspkgload/tests/testthat/testLoadDir/R/a.r0000644000176200001440000000003313046675565017734 0ustar liggesusersmessage("|", getwd(), "|") pkgload/tests/testthat/testS3removed/0000755000176200001440000000000014151367624017455 5ustar liggesuserspkgload/tests/testthat/testS3removed/NAMESPACE0000644000176200001440000000021314027110750020654 0ustar liggesusers# Generated by roxygen2: do not edit by hand S3method(as.character,pkgload_foobar) S3method(my_generic,pkgload_foobar) export(my_generic) pkgload/tests/testthat/testS3removed/DESCRIPTION0000644000176200001440000000032014015406141021141 0ustar liggesusersPackage: testS3removed Title: Test package with S3 method removed (before) License: MIT Author: Lionel Henry Maintainer: Lionel Henry Version: 1.0 RoxygenNote: 7.1.1 pkgload/tests/testthat/testS3removed/R/0000755000176200001440000000000014027110750017642 5ustar liggesuserspkgload/tests/testthat/testS3removed/R/S3.r0000644000176200001440000000033114027110750020307 0ustar liggesusers#' @export as.character.pkgload_foobar <- function(x, ...) { "registered" } #' @export my_generic <- function(x) { UseMethod("my_generic") } #' @export my_generic.pkgload_foobar <- function(x) { "registered" } pkgload/tests/testthat/test-s4-export.r0000644000176200001440000000133713375234477017725 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/testMissingNsObject/0000755000176200001440000000000014024306643020640 5ustar liggesuserspkgload/tests/testthat/testMissingNsObject/NAMESPACE0000644000176200001440000000002313046675565022071 0ustar liggesusersexport(a) export(b)pkgload/tests/testthat/testMissingNsObject/DESCRIPTION0000644000176200001440000000031513046675565022364 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/testMissingNsObject/R/0000755000176200001440000000000014024310177021036 5ustar liggesuserspkgload/tests/testthat/testMissingNsObject/R/a.r0000644000176200001440000000000713046675565021460 0ustar liggesusersa <- 1 pkgload/tests/testthat/test-extraction.R0000644000176200001440000000220113750505224020153 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)), "pkgload 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/testS4union/0000755000176200001440000000000014151367624017145 5ustar liggesuserspkgload/tests/testthat/testS4union/NAMESPACE0000644000176200001440000000011013046675565020364 0ustar liggesusersexportClass(A, B, AB, mle2, mleA, mle2A) importClassesFrom(stats4, mle) pkgload/tests/testthat/testS4union/DESCRIPTION0000644000176200001440000000037313046675565020666 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/testS4union/R/0000755000176200001440000000000014024300155017327 5ustar liggesuserspkgload/tests/testthat/testS4union/R/classes.r0000644000176200001440000000046313206753363021170 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/test-package.R0000644000176200001440000000053313206753363017401 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/testImportVersion/0000755000176200001440000000000014024321361020411 5ustar liggesuserspkgload/tests/testthat/testImportVersion/NAMESPACE0000644000176200001440000000001213046675565021646 0ustar liggesusersexport(a) pkgload/tests/testthat/testImportVersion/DESCRIPTION0000644000176200001440000000040613046675565022144 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/tests/testthat/testImportVersion/R/0000755000176200001440000000000014024305433020614 5ustar liggesuserspkgload/tests/testthat/testImportVersion/R/a.r0000644000176200001440000000000713046675565021237 0ustar liggesusersa <- 1 pkgload/tests/testthat/testImportVersion/R/b.r0000644000176200001440000000000713046675565021240 0ustar liggesusersb <- 2 pkgload/tests/testthat/testDllLoad/0000755000176200001440000000000014024307371017111 5ustar liggesuserspkgload/tests/testthat/testDllLoad/NAMESPACE0000644000176200001440000000013413046675565020346 0ustar liggesusersuseDynLib(testDllLoad) useDynLib(testDllLoad,null_test2) export(nulltest) export(nulltest2) pkgload/tests/testthat/testDllLoad/DESCRIPTION0000644000176200001440000000031413046675565020635 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/testDllLoad/src/0000755000176200001440000000000014117662225017705 5ustar liggesuserspkgload/tests/testthat/testDllLoad/src/null-test.c0000644000176200001440000000020113046675565022004 0ustar liggesusers#include #include SEXP null_test() { return R_NilValue; } SEXP null_test2() { return R_NilValue; } pkgload/tests/testthat/testDllLoad/R/0000755000176200001440000000000014024304036017305 5ustar liggesuserspkgload/tests/testthat/testDllLoad/R/a.r0000644000176200001440000000020213046675565017727 0ustar liggesusersa <- 1 nulltest <- function() { .Call("null_test", PACKAGE = "testDllLoad") } nulltest2 <- function() { .Call(null_test2) } pkgload/tests/testthat/testDependMissing/0000755000176200001440000000000014024321040020314 5ustar liggesuserspkgload/tests/testthat/testDependMissing/DESCRIPTION0000644000176200001440000000035413375234477022055 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/testDependMissing/R/0000755000176200001440000000000014024321247020526 5ustar liggesuserspkgload/tests/testthat/testDependMissing/R/a.r0000644000176200001440000000000713046675565021150 0ustar liggesusersa <- 1 pkgload/tests/testthat/testHooks/0000755000176200001440000000000014024323660016660 5ustar liggesuserspkgload/tests/testthat/testHooks/DESCRIPTION0000644000176200001440000000030513206753363020374 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/testHooks/R/0000755000176200001440000000000014024306252017057 5ustar liggesuserspkgload/tests/testthat/testHooks/R/a.r0000644000176200001440000000041313046675565017503 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/test-s4-unload.r0000644000176200001440000000546313752551715017666 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/testCollateExtra/0000755000176200001440000000000014024310467020165 5ustar liggesuserspkgload/tests/testthat/testCollateExtra/DESCRIPTION0000644000176200001440000000032013206753363021675 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/testCollateExtra/R/0000755000176200001440000000000014024414502020361 5ustar liggesuserspkgload/tests/testthat/testCollateExtra/R/a.r0000644000176200001440000000000613046675565021005 0ustar liggesusersa <- 1pkgload/tests/testthat/test-dll.r0000644000176200001440000000715513752472747016642 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-po.R0000644000176200001440000000032614151367411016417 0ustar liggesuserstest_that("translation domain correctly loaded", { load_all(test_path("testTranslations")) withr::defer(unload("testTranslations")) withr::local_envvar(LANGUAGE = "fr") expect_equal(hello(), "Bonjour") }) pkgload/tests/testthat/testDllRcpp/0000755000176200001440000000000014024324563017140 5ustar liggesuserspkgload/tests/testthat/testDllRcpp/NAMESPACE0000644000176200001440000000014313206753363020362 0ustar liggesusersuseDynLib(testDllRcpp, .registration = TRUE) export(rcpp_hello_world) export(rcpp_test_attributes) pkgload/tests/testthat/testDllRcpp/DESCRIPTION0000644000176200001440000000035713206753363020660 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/testDllRcpp/src/0000755000176200001440000000000014151367624017735 5ustar liggesuserspkgload/tests/testthat/testDllRcpp/src/rcpp_hello_world.cpp0000644000176200001440000000047413206753363024003 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.cpp0000644000176200001440000000241114117662225022725 0ustar liggesusers// Generated by using Rcpp::compileAttributes() -> do not edit by hand // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #include using namespace Rcpp; #ifdef RCPP_USE_GLOBAL_ROSTREAM Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); #endif // 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/R/0000755000176200001440000000000014151367624017347 5ustar liggesuserspkgload/tests/testthat/testDllRcpp/R/RcppExports.R0000644000176200001440000000044514117662225021763 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/test-s4-sort.r0000644000176200001440000000200213046675565017363 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/testLoadLazy/0000755000176200001440000000000014151367624017325 5ustar liggesuserspkgload/tests/testthat/testLoadLazy/NAMESPACE0000644000176200001440000000007214015406141020526 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(bar) pkgload/tests/testthat/testLoadLazy/DESCRIPTION0000644000176200001440000000026214015406141021016 0ustar liggesusersPackage: testLoadLazy Title: Test package with delayed bindings License: MIT Author: Lionel Henry Maintainer: Lionel Henry Version: 1.0 pkgload/tests/testthat/testLoadLazy/R/0000755000176200001440000000000014024401424017510 5ustar liggesuserspkgload/tests/testthat/testLoadLazy/R/bindings.r0000644000176200001440000000016114015406141021467 0ustar liggesusers delayedAssign("foo", rlang::signal("", "forced")) #' @export delayedAssign("bar", rlang::signal("", "forced")) pkgload/tests/testthat/testTranslations/0000755000176200001440000000000014151367411020261 5ustar liggesuserspkgload/tests/testthat/testTranslations/DESCRIPTION0000644000176200001440000000027714151367411021775 0ustar liggesusersPackage: testTranslations Title: Tools to make developing R code easier License: GPL-2 Description: Author: Hadley Maintainer: Hadley Version: 0.1 pkgload/tests/testthat/testTranslations/R/0000755000176200001440000000000014151367411020462 5ustar liggesuserspkgload/tests/testthat/testTranslations/R/hello.r0000644000176200001440000000011214151367411021742 0ustar liggesusershello <- function() { gettext("Hello", domain = "R-testTranslations") } pkgload/tests/testthat/testTranslations/inst/0000755000176200001440000000000014151367411021236 5ustar liggesuserspkgload/tests/testthat/testTranslations/inst/po/0000755000176200001440000000000014151367411021654 5ustar liggesuserspkgload/tests/testthat/testTranslations/inst/po/fr/0000755000176200001440000000000014151367411022263 5ustar liggesuserspkgload/tests/testthat/testTranslations/inst/po/fr/LC_MESSAGES/0000755000176200001440000000000014151367411024050 5ustar liggesuserspkgload/tests/testthat/testTranslations/inst/po/fr/LC_MESSAGES/R-testTranslations.mo0000644000176200001440000000062614151367411030171 0ustar liggesusersÞ•,<PQ6WŽHelloProject-Id-Version: R 4.0.5 Report-Msgid-Bugs-To: bugs.r-project.org PO-Revision-Date: 2021-10-28 15:02 Last-Translator: Automatically generated Language-Team: none MIME-Version: 1.0 Content-Type: text/plain; charset=ASCII Content-Transfer-Encoding: 8bit Language: fr Plural-Forms: nplurals=2; plural=(n > 1); Bonjourpkgload/tests/testthat/testTranslations/po/0000755000176200001440000000000014151367411020677 5ustar liggesuserspkgload/tests/testthat/testTranslations/po/R-testTranslations.pot0000644000176200001440000000061514151367411025205 0ustar liggesusersmsgid "" msgstr "" "Project-Id-Version: R 4.0.5\n" "Report-Msgid-Bugs-To: bugs.r-project.org\n" "POT-Creation-Date: 2021-10-28 15:02\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" msgid "Hello" msgstr "" pkgload/tests/testthat/testTranslations/po/R-fr.po0000644000176200001440000000067114151367411022051 0ustar liggesusersmsgid "" msgstr "" "Project-Id-Version: R 4.0.5\n" "Report-Msgid-Bugs-To: bugs.r-project.org\n" "POT-Creation-Date: 2021-10-28 15:02\n" "PO-Revision-Date: 2021-10-28 15:02\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=ASCII\n" "Content-Transfer-Encoding: 8bit\n" "Language: fr\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" msgid "Hello" msgstr "Bonjour" pkgload/tests/testthat/test-data.r0000644000176200001440000000466313046675565017000 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/testShim/0000755000176200001440000000000014024321127016471 5ustar liggesuserspkgload/tests/testthat/testShim/NAMESPACE0000644000176200001440000000003013046675565017726 0ustar liggesusersexport(get_system.file) pkgload/tests/testthat/testShim/A.txt0000644000176200001440000000001413046675565017432 0ustar liggesusersfile /A.txt pkgload/tests/testthat/testShim/DESCRIPTION0000644000176200001440000000037213206753363020215 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.txt0000644000176200001440000000001413046675565017434 0ustar liggesusersfile /C.txt pkgload/tests/testthat/testShim/R/0000755000176200001440000000000014024310526016673 5ustar liggesuserspkgload/tests/testthat/testShim/R/a.r0000644000176200001440000000045513046675565017326 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/inst/0000755000176200001440000000000014024421220017441 5ustar liggesuserspkgload/tests/testthat/testShim/inst/B.txt0000644000176200001440000000001713046675565020413 0ustar liggesusersfile inst/B.txtpkgload/tests/testthat/testShim/inst/A.txt0000644000176200001440000000002013046675565020404 0ustar liggesusersfile inst/A.txt pkgload/tests/testthat/testLoadHelpers/0000755000176200001440000000000014024304173017775 5ustar liggesuserspkgload/tests/testthat/testLoadHelpers/NAMESPACE0000644000176200001440000000005613375234477021236 0ustar liggesusers# Generated by roxygen2: do not edit by hand pkgload/tests/testthat/testLoadHelpers/data/0000755000176200001440000000000014024273047020713 5ustar liggesuserspkgload/tests/testthat/testLoadHelpers/data/mtcars2.rda0000644000176200001440000000247013375234477022775 0ustar liggesusersBZh91AY&SY Ž%¿ÿÿÿÿþqÔwÿÿÿöýÝ?ÿÿþB 4L@Y`aKsИ/`ÎÛjšUFì2DhSšˆÓ1OÓ 2zžPi£Ôȵ ShƒCMPÐÐ4=CG¨Bh‰´)´ÑGˆê= 46 =M=@d¦ MHЧêySG”z†ƒz£56‘µA Ä44d¦€4ƒÔ4È4z€ƒ ‚2`&0LÀÀÓb0£ÂhÐ ™2H¤Ñêbh=F4€MC@@ Ä †€ê{§'çüm;zýíkŸz^÷¶6)”ã{»[Úø“dÁ`(¸h[EUB%Ð)K”¥9Ógt+=è¸ÑC* µªn:íÏZîw[ýnœpøû šZ*Í0·M! 4 &˜jT 6”Q!ÕÆÖ3!ññòï¸LMZ&N³*BƒÐÿvÖ$„3²~%Iô ’o G;K®î—qš7ÎSåÕ™)A¾ì'kFÐeç/4%®ÛµyÐEzÔR"!d@0""âîkAÎc#R)) a¥alÀ˜†I&,€‚”1U *РއQä1!7ÛZ=d—aƒÚhB `À#T=ŸÊBÐ:D/XÌZ‚ÁÍEJ«›Ú `‹›-XŸT8JÉ—–M£ Ê€mpq$¸&Ë’ÔgI`#MS@¸ø®¦2b$0‡|\ k#Ô„0êÝ*JÈ¢&æâ1ªXf¥$h_Fæ(‹À‚g´ŠP¿0âümÌZ.P–y”Ñ%{iyÍÍz›_ÂÙ/Gy7æ|õçEÆÝLØQ¨å{7M P°¦%•( 9[Ík^<T^æpsî¦^Ý­~ö"Á1 ô›ãkŸêcÊp8׉›¼®Žê(¥D=‚¡S ©L-¡“—±ØQŒ<ßrŒ©!¤ô> ZšZr[ çtª¾ãXɧHÚ#e#hÔòÑÕh$Ô*„æFÀ†¤X¦J¬- d¸…$¬¾ÞuE‰(‘uYB£Œuè‚ÿQð¸"ñåKnLÚ+Pu]Òk•5ï´îSœH‘¡¨_Wj¤öS©­Ü[µœbôIö°ÙÒ¾q×\dJí¬–Š 1£( ©zØ„Êb-r 1g ª¢yBÓ;Æ-Я"7K,-–< ÞµåE0muê@}•.ÞJ8Í:¸­PlCxuˆä ,Üϰ‘(Ê+·ôL»±ÉJÖÛ$ëƒÏ¬Qå¢nz ´õ˜8öµ~‘Øi¡â <øBêÙû(K.u?2\«Ÿ_=»ˆ ¥“3ÁÅD×ý‰™›ÆC™Í} ‚n[_ù™y‡U÷i¨(‰7œ<5Ïñ°¡P@3¼—§I="àɘ*B5Sà‚`ÄCaž µð UaþO¥†²KdbÿrE8P Ž%pkgload/tests/testthat/testLoadHelpers/DESCRIPTION0000644000176200001440000000043213375234477021523 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/testLoadHelpers/tests/0000755000176200001440000000000014024324452021141 5ustar liggesuserspkgload/tests/testthat/testLoadHelpers/tests/testthat/0000755000176200001440000000000014151432552023003 5ustar liggesuserspkgload/tests/testthat/testLoadHelpers/tests/testthat/helpers.R0000644000176200001440000000011313652577143024576 0ustar liggesusersfoo <- 1 head_mtcars <- head(mtcars2) helper_baz <- testLoadHelpers::baz pkgload/tests/testthat/testLoadHelpers/tests/testthat/test-foo.R0000644000176200001440000000012713375234477024703 0ustar liggesuserscontext("test-foo.R") test_that("multiplication works", { expect_equal(2 * 2, 4) }) pkgload/tests/testthat/testLoadHelpers/tests/testthat.R0000644000176200001440000000011213375234477023135 0ustar liggesuserslibrary(testthat) library(testLoadHelpers) test_check("testLoadHelpers") pkgload/tests/testthat/testLoadHelpers/R/0000755000176200001440000000000014024277425020207 5ustar liggesuserspkgload/tests/testthat/testLoadHelpers/R/a.r0000644000176200001440000000001113375234477020612 0ustar liggesusersbaz <- 1 pkgload/tests/testthat/testCollateMissing/0000755000176200001440000000000014024305361020510 5ustar liggesuserspkgload/tests/testthat/testCollateMissing/DESCRIPTION0000644000176200001440000000031613206753363022230 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/testCollateMissing/R/0000755000176200001440000000000014024303347020713 5ustar liggesuserspkgload/tests/testthat/testCollateMissing/R/a.r0000644000176200001440000000000613046675565021333 0ustar liggesusersa <- 1pkgload/tests/testthat/testCollateMissing/R/b.r0000644000176200001440000000000613046675565021334 0ustar liggesusersb <- 2pkgload/tests/testthat/test-load-hooks.r0000644000176200001440000001075314117650005020102 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/testS3removed2/0000755000176200001440000000000014151367624017537 5ustar liggesuserspkgload/tests/testthat/testS3removed2/NAMESPACE0000644000176200001440000000005614015406141020742 0ustar liggesusers# Generated by roxygen2: do not edit by hand pkgload/tests/testthat/testS3removed2/DESCRIPTION0000644000176200001440000000031714015406141021231 0ustar liggesusersPackage: testS3removed Title: Test package with S3 method removed (after) License: MIT Author: Lionel Henry Maintainer: Lionel Henry Version: 1.0 RoxygenNote: 7.1.1 pkgload/tests/testthat/testS3removed2/R/0000755000176200001440000000000014024377053017734 5ustar liggesuserspkgload/tests/testthat/testS3removed2/R/S3.r0000644000176200001440000000000014015406141020361 0ustar liggesuserspkgload/tests/testthat/testCollateAbsent/0000755000176200001440000000000014024307360020314 5ustar liggesuserspkgload/tests/testthat/testCollateAbsent/DESCRIPTION0000644000176200001440000000030013046675565022035 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/testCollateAbsent/R/0000755000176200001440000000000014024323704020515 5ustar liggesuserspkgload/tests/testthat/testCollateAbsent/R/a.r0000644000176200001440000000000613046675565021136 0ustar liggesusersa <- 1pkgload/tests/testthat/testCollateAbsent/R/b.r0000644000176200001440000000000613046675565021137 0ustar liggesusersa <- 2pkgload/tests/testthat/testCollateAbsent/R/c.r0000644000176200001440000000000613046675565021140 0ustar liggesusersa <- 3pkgload/tests/testthat/testS4export/0000755000176200001440000000000014024401437017324 5ustar liggesuserspkgload/tests/testthat/testS4export/NAMESPACE0000644000176200001440000000003713046675565020565 0ustar liggesusersexportClasses(class_to_export) pkgload/tests/testthat/testS4export/DESCRIPTION0000644000176200001440000000053613046675565021060 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/testS4export/R/0000755000176200001440000000000014024306527017531 5ustar liggesuserspkgload/tests/testthat/testS4export/R/all.r0000644000176200001440000000007613375234477020503 0ustar liggesuserssetClass("foo") setClass('class_to_export', contains = "foo") pkgload/tests/testthat/test-description.r0000644000176200001440000000035113206753363020367 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/testData/0000755000176200001440000000000014024322107016441 5ustar liggesuserspkgload/tests/testthat/testData/NAMESPACE0000644000176200001440000000002713046675565017705 0ustar liggesusersexport(sysdata_export) pkgload/tests/testthat/testData/data/0000755000176200001440000000000014024311031017344 5ustar liggesuserspkgload/tests/testthat/testData/data/b.r0000644000176200001440000000000713046675565020001 0ustar liggesusersb <- 2 pkgload/tests/testthat/testData/data/a.rda0000644000176200001440000000007313046675565020310 0ustar liggesusers‹ r‰0âŠàb```b`âbf “… H02°0p‚èD ÁbØ`€(+ýL8pkgload/tests/testthat/testData/DESCRIPTION0000644000176200001440000000026713046675565020202 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/testData/R/0000755000176200001440000000000014024323123016641 5ustar liggesuserspkgload/tests/testthat/testData/R/sysdata.rda0000644000176200001440000000013013046675565021022 0ustar liggesusers‹ r‰0âŠàb```b`âgf`b2Y˜€# 'æ+®,NI,IŒO­(È/*‰€d8 Eµ Lu^~š˜†5µÝvpkgload/tests/testthat/test-metadata.r0000644000176200001440000000264613046675565017646 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/testHelp/0000755000176200001440000000000014024406336016467 5ustar liggesuserspkgload/tests/testthat/testHelp/NAMESPACE0000644000176200001440000000017313652577143017722 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(foofoo) export(testCustomMacro) export(testHelp) export(testSysMacro) pkgload/tests/testthat/testHelp/man/0000755000176200001440000000000014024403131017230 5ustar liggesuserspkgload/tests/testthat/testHelp/man/testCustomMacro.Rd0000644000176200001440000000042213652577143022676 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/foofoo.r \name{testCustomMacro} \alias{testCustomMacro} \title{Function that has a system and a custom macro} \usage{ testCustomMacro() } \description{ This is \CRANpkg{pkgload}. \foobar{Yeah!} } pkgload/tests/testthat/testHelp/man/testSysMacro.Rd0000644000176200001440000000035513652577143022207 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/foofoo.r \name{testSysMacro} \alias{testSysMacro} \title{Function that has a system macro} \usage{ testSysMacro() } \description{ This is \CRANpkg{pkgload}. } pkgload/tests/testthat/testHelp/man/macros/0000755000176200001440000000000014024400775020527 5ustar liggesuserspkgload/tests/testthat/testHelp/man/macros/macros.Rd0000644000176200001440000000004013652577143022306 0ustar liggesusers\newcommand{\foobar}{\emph{#1}} pkgload/tests/testthat/testHelp/man/testHelp.Rd0000644000176200001440000000034713206753363021333 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.Rd0000644000176200001440000000044013206753363021024 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.Rd0000644000176200001440000000063613206753363022725 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/testHelp/DESCRIPTION0000644000176200001440000000044313206753363020204 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/R/0000755000176200001440000000000014024372340016665 5ustar liggesuserspkgload/tests/testthat/testHelp/R/foofoo.r0000644000176200001440000000120513652577143020353 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" #' Function that has a system macro #' #' This is \CRANpkg{pkgload}. #' #' @export testSysMacro <- function() "It is all good" #' Function that has a system and a custom macro #' #' This is \CRANpkg{pkgload}. \foobar{Yeah!} #' #' @export testCustomMacro <- function() "It is still all good" pkgload/tests/testthat/test-load-collate.r0000644000176200001440000000106114117650005020372 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/testCollateOrder/0000755000176200001440000000000014024305037020152 5ustar liggesuserspkgload/tests/testthat/testCollateOrder/NAMESPACE0000644000176200001440000000003113046675565021406 0ustar liggesusersexportPattern("^[^\\.]") pkgload/tests/testthat/testCollateOrder/DESCRIPTION0000644000176200001440000000030113046675565021675 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/testCollateOrder/R/0000755000176200001440000000000014024410301020342 5ustar liggesuserspkgload/tests/testthat/testCollateOrder/R/a.r0000644000176200001440000000003013046675565020772 0ustar liggesusers#' @include b.r a <- 1 pkgload/tests/testthat/testCollateOrder/R/b.r0000644000176200001440000000000713046675565020777 0ustar liggesusersa <- 2 pkgload/tests/testthat/testNamespace/0000755000176200001440000000000014024325445017474 5ustar liggesuserspkgload/tests/testthat/testNamespace/NAMESPACE0000644000176200001440000000013513046675565020730 0ustar liggesusersexport(a) export(bitAnd) import(compiler) importFrom(bitops,bitAnd) importFrom(bitops,bitOr) pkgload/tests/testthat/testNamespace/DESCRIPTION0000644000176200001440000000035713206753363021214 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/testNamespace/R/0000755000176200001440000000000014024415611017670 5ustar liggesuserspkgload/tests/testthat/testNamespace/R/a.r0000644000176200001440000000000713046675565020313 0ustar liggesusersa <- 1 pkgload/tests/testthat/testNamespace/R/b.r0000644000176200001440000000000713046675565020314 0ustar liggesusersb <- 2 pkgload/tests/testthat.R0000644000176200001440000000021013046675565015032 0ustar liggesuserslibrary(testthat) library(pkgload) # Needed so that install.packages works correctly Sys.setenv("R_TESTS" = "") test_check("pkgload") pkgload/R/0000755000176200001440000000000014151367411012077 5ustar liggesuserspkgload/R/has_tests.R0000644000176200001440000000123313652577143014230 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/R/zzz.r0000644000176200001440000000213414027067237013124 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_package_root_file", rprojroot::find_package_root_file, 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/load-code.r0000644000176200001440000000317114015406141014104 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) if (length(missing) > 0) { cli::cli_alert_warning("Skipping missing files: {.file {missing}}") } collate <- setdiff(collate, missing) extra <- setdiff(r_files, collate) if (length(extra) > 0) { cli::cli_alert_warning("Adding files missing in collate: {.file {extra}}") } r_files <- union(collate, r_files) } r_files } pkgload/R/po.R0000644000176200001440000000070114151367411012636 0ustar liggesusersload_po <- function(package, path) { po_path <- file.path(path, "inst", "po") if (!file.exists(po_path)) { return() } # Reset cache to avoid gettext() retrieving cached value # See for details bindtextdomain("reset", withr::local_tempdir()) bindtextdomain(paste0("R-", package), po_path) # R level messages bindtextdomain(package, po_path) # C level messages invisible() } pkgload/R/dev-meta.r0000644000176200001440000000204713206753363013774 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/utils.R0000644000176200001440000001122314061605345013362 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 used to check the version #' @keywords internal #' @export 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()) { cli::cli_alert_info(msg) cli::cli_alert_danger("Would 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("pkgload is incompatible with the current version of R. `load_all()` may function incorrectly.", call. = FALSE) } 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 = "'") } ns_s3_methods <- function(pkg) { ns_env(pkg)$.__S3MethodsTable__. } pkgload/R/inst.r0000644000176200001440000000150413206753363013244 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/file-cache.r0000644000176200001440000000142413046675565014261 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-topic.r0000644000176200001440000000544713652577143014200 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) macros <- load_rd_macros(path) rds <- rd_files(path) aliases <- function(path) { parsed <- tools::parse_Rd(path, macros = macros) 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/source.r0000644000176200001440000000151013206753363013564 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/package-deps.r0000644000176200001440000000500313750505224014604 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), call. = FALSE ) } return(TRUE) } pkgload/R/aaa.r0000644000176200001440000000033213206753363013007 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/load-data.r0000644000176200001440000000227113750540733014116 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/namespace-env.r0000644000176200001440000002007714117645411015013 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) { ns <- asNamespace(package) if (isBaseNamespace(ns)) return(path.package(package)) getNamespaceInfo(ns, "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", { pattern <- if (getRversion() >= "4.1.0") { quote(if (.isMethodsDispatchOn() && hasS4m && !identical(package, "methods")) NULL) } else { quote(if (.isMethodsDispatchOn() && .hasS4MetaData(ns) && !identical(package, "methods")) NULL) } make_function(alist(ns =, package =, exports =, nsInfo =), call("{", quote(lev <- 0L), quote(hasS4m <- .hasS4MetaData(ns)), extract_lang( f = comp_lang, y = pattern, idx = c(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 try(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.") # Force all bindings of the namespace in case of dangling # references. If lazy bindings are forced after the namespace is # unloaded, it might lead to decompress errors if unloaded or to # inconsistencies if reloaded (the bindings are resolved in the new # namespace). eapply(ns_env(name), force, all.names = TRUE) # Remove the item from the registry do.call(rm, args = list(name, envir = ns_registry())) invisible() } unregister_methods <- function(package) { # Unloading S3 methods manually avoids lazy-load errors when the new # package is loaded overtop the old one. It also prevents removed # methods from staying registered. s3_unregister(package) # S4 classes that were created by the package need to be removed in a special way. remove_s4_classes(package) } pkgload/R/load.r0000644000176200001440000002633514151367411013212 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 `pkgload::compile_dll()` #' for more details. #' #' \item Loads any compiled translations in `inst/po`. #' #' \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 largely equivalent to running #' [unload()], however the old namespaces are not completely removed and no #' `.onUnload()` hooks are called. 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` #' @param warn_conflicts If `TRUE`, issues a warning if a function in the global #' environment masks a function in the package. This can happen when you #' accidentally source a `.R` file, rather than using `load_all()`, or if you #' define a function directly in the R console. This is frustrating to debug, #' as it feels like the changes you make to the package source aren't having #' the expected effect. #' @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, warn_conflicts = TRUE) { path <- pkg_path(path) package <- pkg_name(path) description <- pkg_desc(path) if (!quiet) cli::cli_alert_info("Loading {.pkg {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) } # Compile dll if requested, we don't ever need to do this if a package doesn't # have a src/ directory if (!dir.exists(file.path(path, "src"))) { compile <- FALSE } else if (missing(compile) && !missing(recompile)) { compile <- if (isTRUE(recompile)) TRUE else NA } if (isTRUE(compile)) { rlang::check_installed("pkgbuild", reason = "to compile packages with a `src/` directory.") pkgbuild::compile_dll(path, force = TRUE, quiet = quiet) } else if (identical(compile, NA)) { rlang::check_installed("pkgbuild", reason = "to compile packages with a `src/` directory.") 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) } old_methods <- list() if (reset) { clear_cache() # Remove package from known namespaces. We don't unload it to allow # safe usage of dangling references. if (is_loaded(package)) { methods_env <- ns_s3_methods(package) unload_pkg_env(package) unregister_methods(package) unregister_namespace(package) # Save foreign methods after unregistering the package's own # methods. We'll restore the foreign methods but let the package # register its own methods again. old_methods <- as.list(methods_env) old_methods <- Filter(function(x) is_foreign_method(x, package), old_methods) } } 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) if (identical(compile, FALSE)) { out$dll <- try_load_dll(path) } else { out$dll <- load_dll(path) } # attach testthat to the search path if (isTRUE(attach_testthat) && package != "testthat") { ("base" %:::% "library")("testthat", warn.conflicts = FALSE) } load_po(package, path) # 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) # 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) env_bind(ns_s3_methods(package), !!!old_methods) # Run hooks run_pkg_hook(package, "attach") run_user_hook(package, "attach") # 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 = pkg_env(package)) ) } # Replace help and ? in utils package environment insert_global_shims() if (isTRUE(warn_conflicts)) { warn_if_conflicts( package, out$env, globalenv() ) } invisible(out) } is_function_in_environment <- function(name, env) { vapply(name, exists, logical(1), where = env, mode = "function", inherits = FALSE) } warn_if_conflicts <- function(package, env1, env2) { nms1 <- get_exports(env1) nms2 <- get_exports(env2) both <- sort(intersect(nms1, nms2)) # Verify are functions in both environments both <- both[ is_function_in_environment(both, env1) & is_function_in_environment(both, env2) ] if (length(both) == 0) { return(invisible()) } header <- cli::rule( left = crayon::bold("Conflicts"), right = paste0(package, " ", "conflicts") ) bullets <- conflict_bullets(package, both) directions <- crayon::silver( paste0( "Did you accidentally source a file rather than using `load_all()`?\n", "Run `rm(list = c(", paste0('"', both, '"', collapse = ", "), "))` to remove the conflicts." ) ) rlang::warn( sprintf( "\n%s\n%s\n\n%s", header, bullets, directions ), .subclass = "pkgload::conflict" ) } get_exports <- function(ns) { if (isNamespace(ns)) { nms <- getNamespaceExports(ns) } else { nms <- names(ns) } nms } conflict_bullets <- function(package, both) { # Show three bullets plus ellipsis if more than four bullets. # The output size is limited, also the bullets are vers repetitive. MAX_BULLETS <- 3 if (length(both) > MAX_BULLETS + 1) { more <- paste0( "\n", cli::symbol$ellipsis, " and ", length(both) - MAX_BULLETS, " more" ) both <- utils::head(both, MAX_BULLETS) } else { more <- "" } bullets <- paste0(collapse = "\n", sprintf( "%s %s masks %s::%s()", crayon::red(cli::symbol$cross), format(crayon::green(paste0(both, "()"))), crayon::blue(package), both ) ) paste0(bullets, more) } uses_testthat <- function(path = ".") { paths <- c( package_file("inst", "tests", path = path), package_file("tests", "testthat", path = path) ) any(dir.exists(paths)) && requireNamespace("testthat", quietly = TRUE) } 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) } is_foreign_method <- function(x, package) { env <- environment(x) !is_namespace(env) || !is_string(ns_env_name(env), package) } pkgload/R/load-dll.r0000644000176200001440000001013114061605345013747 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) # Delete the temporary SO when the namespace gets garbage collected dll_path <- dlls[[package]][["path"]] new_weakref(env, finalizer = ns_finalizer(dll_path)) invisible(dlls) } load_dll <- expr_interp(load_dll) fn_env(load_dll) <- rlang::ns_env("pkgload") load_dll }) ns_finalizer <- function(path) { force(path) function(...) { # Clean up the temporary .so file. unlink(path) # Remove the .so from the cached list of loaded modules loaded <- .dynLibs() loaded <- Filter(function(x) !is_string(x[["path"]], path), loaded) .dynLibs(loaded) } } # 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) dyn_ext <- .Platform$dynlib.ext dllname <- paste(lib, dyn_ext, sep = "") dllfile <- package_file("src", dllname, path = path) if (!file.exists(dllfile)) { return(invisible()) } # Copy the .so to a temporary directory with a unique name. This way # we may have different versions of the .so loaded, in case # references to the previously loaded .so linger in the session. # The .so should have the package name so that R can find the # `R_init_` function by itself. dll_copy_dir <- tempfile("pkgload") dll_copy_file <- file.path(dll_copy_dir, dllname) dir.create(dll_copy_dir) file.copy(dllfile, dll_copy_file) # # The loading and registering of the dll is similar to how it's done # # in library.dynam. dllinfo <- dyn.load(dll_copy_file) # 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 }) try_load_dll <- function(path = ".") { tryCatch( load_dll(path = path), error = function(e) { warn(paste0("Failed to load at least one DLL: ", e$message)) list() } ) } pkgload/R/dev-help.r0000644000176200001440000001623714015406141013770 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" ) } load_rd_macros <- function(dir) { macros <- tools::loadPkgRdMacros(dir) macros <- tools::loadRdMacros( file.path(R.home("share"), "Rd", "macros", "system.Rd"), macros = macros ) } #' @export print.dev_topic <- function(x, ...) { cli::cli_alert_info("Rendering development documentation for {.val {x$topic}}") type <- match.arg(x$type %||% "text", c("text", "html")) out_path <- paste(tempfile("Rtxt"), type, sep = ".") macros <- load_rd_macros(dirname(dirname(x$path))) if (type == "text") { tools::Rd2txt(x$path, out = out_path, package = x$pkg, stages = x$stage, macros = macros) 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, macros = macros) 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. #' #' @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/package.r0000644000176200001440000000433314027067237013665 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 <- tryCatch({ rprojroot_find_package_root_file(path = path) }, error = function(e) { abort(paste( "Could not find a root 'DESCRIPTION' file that starts with '^Package' in", paste0("'", normalizePath(path), "'."), "Are you in your project directory,", "and does your project have a 'DESCRIPTION' file?" ), class = "pkgload_no_desc") }) # 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/imports-env.r0000644000176200001440000000733514015406141014546 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(envir = 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 }) pkgload/R/shims.r0000644000176200001440000001047413756713140013417 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 #' #' @rdname system.file #' @name system.file 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/run-loadhooks.r0000644000176200001440000000253714015405742015055 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/package-env.r0000644000176200001440000000620313752507203014445 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/dev-example.r0000644000176200001440000000436113750505224014475 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. #' #' @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) run_example(topic$path, quiet = quiet) } #' @rdname dev_example #' @export #' @param path Path to `.Rd` file #' @param run_dontrun if `TRUE`, do run `\dontrun` sections in the Rd files. #' @param run_donttest if `TRUE`, do run `\donttest` sections in the Rd files. #' out. #' @param env Environment in which code will be run. #' @param macros Custom macros to use to parse the `.Rd` file. See the #' `macros` argument of [tools::parse_Rd()]. If `NULL`, then the #' [tools::Rd2ex()] (and [tools::parse_Rd()]) default is used. #' @param run,test Deprecated, see `run_dontrun` and `run_donttest` above. run_example <- function(path, run_donttest = FALSE, run_dontrun = FALSE, env = new.env(parent = globalenv()), quiet = FALSE, macros = NULL, run, test) { if (!missing(run)) { warning("`run_example(run=)` is deprecated, please use `run_example(run_dontrun=)` instead", call. = FALSE) run_dontrun <- run } if (!missing(test)) { warning("`run_example(test=)` is deprecated, please use `run_example(run_donttest=)` instead", call. = FALSE) run_donttest <- test } if (!file.exists(path)) { stop("'", path, "' does not exist", call. = FALSE) } tmp <- tempfile(fileext = ".R") if (is.null(macros)) { tools::Rd2ex( path, out = tmp, commentDontrun = !run_dontrun, commentDonttest = !run_donttest ) } else { tools::Rd2ex( path, out = tmp, commentDontrun = !run_dontrun, commentDonttest = !run_donttest, macros = macros ) } if (file.exists(tmp)) { source(tmp, echo = !quiet, local = env, max.deparse.length = Inf) } invisible(env) } pkgload/R/unload.r0000644000176200001440000001064414044442422013546 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{https://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.") } } if (!package %in% loadedNamespaces()) { stop("Package ", package, " not found in loaded packages or namespaces") } unregister_methods(package) # unloadNamespace calls onUnload hook and .onUnload, and detaches the # package if it's attached. It will fail if a loaded package needs it. unloaded <- tryCatch({ unloadNamespace(package) TRUE }, error = function(e) FALSE) if (!unloaded) { # unloadNamespace() failed before we get to the detach, so need to # manually detach unload_pkg_env(package) # Can't use loadedNamespaces() and unloadNamespace() here because # things can be in a weird state. 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) } unload_pkg_env <- function(package) { if (is_attached(package)) { pos <- which(pkg_env_name(package) == search()) suppressWarnings(detach(pos = pos, force = TRUE)) } } # 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() } s3_unregister <- function(package) { ns <- ns_env(package) # If the package is loaded, but not installed this will fail, so we bail out in that case. ns_defs <- suppressWarnings(try(parse_ns_file(system.file(package = package)), silent = TRUE)) if (inherits(ns_defs, "try-error")) { return() } methods <- ns_defs$S3methods[, 1:2, drop = FALSE] for (i in seq_len(nrow(methods))) { method <- methods[i, , drop = FALSE] generic <- env_get(ns, method[[1]], inherit = TRUE, default = NULL) if (is_null(generic)) { next } generic_ns <- topenv(fn_env(generic)) if (!is_namespace(generic_ns)) { next } # Don't remove methods for generics defined in the namespace being # unloaded. The stale namespace should still work as much as # possible. if (is_string(ns_env_name(generic_ns), package)) { next } table <- generic_ns$.__S3MethodsTable__. if (!is_environment(table)) { next } nm <- paste0(method, collapse = ".") env_unbind(table, nm) } } pkgload/R/remove-s4-class.r0000644000176200001440000001205513375234477015225 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/load-depends.r0000644000176200001440000000076613206753363014637 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/enc.R0000644000176200001440000000044413206753363012776 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/NEWS.md0000644000176200001440000001525014151367450013002 0ustar liggesusers# pkgload 1.2.4 * Lionel Henry is now the maintainer. * `load_all()` automatically registers package translations, if found. # pkgload 1.2.3 * pkgload now forces all bindings on unload. This fixes errors and inconsistencies when dangling references force lazy bindings after unload or reload. * `load_all()` now restores S3 methods registered by third party packages (#163). * `load_dll()` will now preserve the DLL name when loading instead of always using the package name. This allows packages to include DLL's with different names (#162, @dfalbel). # pkgload 1.2.2 # pkgload 1.2.1 * `unload()` no longer unregisters methods for generics of the package being unloaded. This way dangling references to generics defined in the stale namespace still work as expected (r-lib/vctrs#1341). * `load_all()` will now work for packages that have testthat tests but do not have testthat installed (#151) * The `pkgbuild` dependency has been moved to `Suggests`, as it is only needed for packages with compiled code. * `load_all()` will now work for packages that have testthat tests but do not have testthat installed (#151) * `load_all(warn_conflicts = TRUE)` becomes more narrow and only warns when a *function* in the global environment masks a *function* in the package, consistent with the docs (#125, #143 @jennybc). * `load_all()` no longer does a comprehensive check on the `DESCRIPTION` file when loading, instead just checking that it exists and starts with Package (#149, @malcolmbarrett) * `unload()` no longer warns when it can't unload a namespace. # pkgload 1.2.0 * Fix test failure in R 4.1 with regards to S4 method registration * `load_all()` now preserves existing namespaces in working order. In particular, it doesn't unload the package's shared library and keeps it loaded instead. When reloading, a copy of the SO for the new namespace is loaded from a temporary location. These temporary SOs are only unloaded on GC and deleted from their temporary location via a weak reference attached to the namespace. This mechanism ensures that lingering references to the namespace keep working as expected. Consequently the namespace propagation routine that was added to pkgload as a workaround has been removed. Note that `.Call()` invocations that pass a string symbol rather than a structured symbol may keep crashing, because R will look into the most recently loaded SO of a given name. Since symbol registration is now the norm, we don't expect this to cause much trouble. * `load_all()` no longer forces all bindings of a namespace to avoid lazy-load errors. Instead, it removes exported S3 methods from the relevant tables. - This improves the loading behaviour with packages that define objects in their namespaces lazily (e.g. with `delayedAssign()`). - This also makes `load_all()` more predictable after a method has been removed from the package. It is now actually removed from the generic table. It would previously linger until R was restarted. * If `load_all()` attaches testthat, it automatically suppresses conflicts. # pkgload 1.1.0 * `dev_example()` now works after removing an inconsistent call to `load_all()` (@riccardoporreca, #122). * `load_all()` now issues a warning if exported objects conflict with objects defined in the global environment (#112) * `run_example()` arguments `run` and `test` are deprecated in favor of the (hopefully) more clear `run_dontrun` and `run_donttest` (#107). * Internal fixes for compatibility with the future 4.1.0 release. # pkgload 1.0.2 * `shim_question()` now works for topics from the R base package that are passed with the double colon operator (e.g. `base::min`) (@mdequeljoe, #99). * `load_all()` now allows using explicitly qualified, exported names in test helpers (@klmr, #95). * `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/MD50000644000176200001440000002677214151432552012223 0ustar liggesusers3e192e138b43cd8d5c98030ddea00584 *DESCRIPTION d239f26218f2aae12cc7ea8731affbdc *NAMESPACE 5b2a6a11c136ec38235ac768a75c6868 *NEWS.md a9cebe46e41ae836bd6d65f9aa5393b6 *R/aaa.r 57cba0195e38e39ac9d578cbd6308d1c *R/dev-example.r b2713a1e7453330fc21952d0b268cf89 *R/dev-help.r cf2ddbdbdc3b6cb28adc699ce8e6c94a *R/dev-meta.r 709ff76f81416ebf99705928831fb5d6 *R/dev-topic.r ce8cd86bf8ce6af5800835dc5dd519a6 *R/enc.R ec20041c1e398e82c95c105a8ea8b542 *R/file-cache.r bdae5e091eaa6a85cd10591e26455d55 *R/has_tests.R d265c6507ce707b3332566f53570975e *R/imports-env.r 3828ece4f7f3d42bb62e7c5e117ea995 *R/inst.r eed5bbf728acc5542aad04c411d0bedd *R/load-code.r 39dc14e21ff57b1e6e32508f8f2b51b0 *R/load-data.r f896448493c8bca7dc16691c2d70e145 *R/load-depends.r 247fb7682248fb7b9f4f124ac756acca *R/load-dll.r 076082f2f208b7aed3013f1278952e66 *R/load.r 9307185cfb40eaf9b1fa383b33b23dc7 *R/namespace-env.r e5c1d030f51f0062d5e953dc70fb8f33 *R/package-deps.r e8750f9b35d889cbdaa90408af13a3ad *R/package-env.r 7589116e123c471d4c1c607c67de01a4 *R/package.r 7daba45e900f224905e9ea3117b6e568 *R/po.R c8d97095ed556c0c24a0524d59525942 *R/remove-s4-class.r b8fabf24e0ce1b1392568750622ff174 *R/run-loadhooks.r 188dd459a7d4254b206cc655aec68d2a *R/shims.r f20ca6ada867484a0bd51e163d56f4a4 *R/source.r 2b8824779e6895a6cf864467d2710067 *R/unload.r 2de47c63062674e2bde6ea1bc7c99f9c *R/utils.R f12518d82f2b6b8a473a0aa8c360dbf8 *R/zzz.r 209119b2aa6cf197379d130e8b9b04e5 *README.md 04a4c539154069ec2326a98e04179aa1 *inst/WORDLIST b4f4e747e4036f6155784fd7ebc44f33 *man/check_dep_version.Rd 4e6de018cc978094a65295459492b9f8 *man/check_suggested.Rd 0051c3e3d6c3aa5d66cf7ac653acf487 *man/dev_example.Rd 490b93258d127f32b6f49a9064dba8ac *man/dev_help.Rd f00c77ba9f4a4eb759d9cddc317a5f1d *man/dev_meta.Rd 5f213ad75ab776275a30b7331a2f7517 *man/has_tests.Rd 4779f9d2b3f0117e4402cc30e6a190d4 *man/help.Rd a0a833c948ce9fd690db2b28cdf159f8 *man/imports_env.Rd 2a7be3e73a89e6d254f6733c7076cb8b *man/inst.Rd 24c1d6c3190a88154d2e843d86ce18ac *man/is_dev_package.Rd 05e5fa67668cae3b2e7558f15b211325 *man/load_all.Rd 645d99b9ab2065a57b5ed382bb4fca83 *man/load_code.Rd cd41c163b83e1b1c2a235a60c3637695 *man/load_data.Rd b1adb0b029bbc2fad19fcd6eff7dd50b *man/load_dll.Rd 72fc1338153b7acee96a954a93e855ed *man/load_imports.Rd dd8acd933791df9141ac4c32ed23beca *man/ns_env.Rd 76342a70136bbc1e1b63ad14cefed751 *man/package_file.Rd 6be08f7737a94400dd927ea1021a3a6c *man/packages.Rd 9c30abeb80e4f15274c07236527ba605 *man/parse_deps.Rd 341612f64731b62bc1b46b1dd6dcfc56 *man/parse_ns_file.Rd 1980e23d6a73db166e73713cda37a76d *man/pkg_env.Rd d05d8f1c775815e9c2ad35ae8b4296ca *man/pkgtest.Rd a60b1512c7039cadaa60ddc946159946 *man/run_pkg_hook.Rd b61224c456bc663d1d77dfb2261105f2 *man/system.file.Rd b613be712b56580c3cc399bf387aa029 *man/unload.Rd 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 56ee4fda23b29f8562550d74fa113e3c *tests/testthat/test-examples.R 68b8dab49b36ee11bf2f30de68827d80 *tests/testthat/test-examples.Rd 40962eabd9ed8729293931399897feed *tests/testthat/test-extraction.R 655f678f6da74d4e954a46ba7145fbcf *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 618d2c5c3d2d16adf8415b0c4b4b29da *tests/testthat/test-load.r 2229534d8dc55e86910105826ce02656 *tests/testthat/test-metadata.r 4cc889f93542e9bcf7843e72b636ccf1 *tests/testthat/test-namespace.r 795f9cdcf7dec52b149ce0c864b5fb1c *tests/testthat/test-package.R 93d4fa6bc0994e600c2b1dc8143676c7 *tests/testthat/test-po.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 0c8827bd3100199eada5cf76012f3686 *tests/testthat/testDllRcpp/src/RcppExports.cpp cdae79fe661bbb694dd79074547735b9 *tests/testthat/testDllRcpp/src/rcpp_hello_world.cpp 1ff255921b6b11864580451a5ed503b7 *tests/testthat/testHelp/DESCRIPTION ff09290426402d763c4542e5426dadd3 *tests/testthat/testHelp/NAMESPACE 66236785036c947fd7014e9a02cbf6f9 *tests/testthat/testHelp/R/foofoo.r d72f199234418eb348b7aa2a76d665e3 *tests/testthat/testHelp/man/foofoo.Rd d9194183e8c46d455622f166e4014b06 *tests/testthat/testHelp/man/macros/macros.Rd 7aaf1b4f012efc5b6ff64971488b2b87 *tests/testthat/testHelp/man/testCustomMacro.Rd efec94ac198b7dff257466964248bb43 *tests/testthat/testHelp/man/testHelp-package.Rd 36983a265f6825008e4ca9c2b621f36f *tests/testthat/testHelp/man/testHelp.Rd e04363946cb90d523291b3e468a710b5 *tests/testthat/testHelp/man/testSysMacro.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 71d7817960bc6e4582ffe00044d902c6 *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 e980cc57e21a5e0e0ddf87705ce9f444 *tests/testthat/testLoadLazy/DESCRIPTION 9c9114e191dfc8c4face36bca76c5648 *tests/testthat/testLoadLazy/NAMESPACE c23239cba08bc8aae2be8627eff1c975 *tests/testthat/testLoadLazy/R/bindings.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 3a884f3538f6f69ce26b6f76f6e9f1c1 *tests/testthat/testS3removed/DESCRIPTION b4b8452ca5b830996ac4565d33e29634 *tests/testthat/testS3removed/NAMESPACE 5060a3834cef2931b473b1f2882fcaab *tests/testthat/testS3removed/R/S3.r 52aa7c4531c989b52272125dfb942409 *tests/testthat/testS3removed2/DESCRIPTION dc21c19f0d6968ee25d441b2cf46017d *tests/testthat/testS3removed2/NAMESPACE d41d8cd98f00b204e9800998ecf8427e *tests/testthat/testS3removed2/R/S3.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 1b52fde955450cbefa30dc871752a575 *tests/testthat/testTranslations/DESCRIPTION cea30ae8568f3d1407abd1b23febfbe9 *tests/testthat/testTranslations/R/hello.r d8d02e415297e89aa5661c49dc29a2fe *tests/testthat/testTranslations/inst/po/fr/LC_MESSAGES/R-testTranslations.mo ece193fa5a3d121085507eca8095eb39 *tests/testthat/testTranslations/po/R-fr.po 7b49caa498cd8c376153517e4f3e1c0e *tests/testthat/testTranslations/po/R-testTranslations.pot pkgload/inst/0000755000176200001440000000000014024376572012662 5ustar liggesuserspkgload/inst/WORDLIST0000644000176200001440000000003513652577143014055 0ustar liggesusersdevtools dir dirs recompiles