Dev Tools
Dev Tools
Dev Tools
May 9, 2015
Title Tools to Make Developing R Packages Easier
Version 1.8.0
Description Collection of package development tools.
URL http://github.com/hadley/devtools
BugReports http://github.com/hadley/devtools/issues
Depends R (>= 3.0.2)
Imports httr (>= 0.4), RCurl, utils, tools, methods, memoise, whisker,
evaluate, digest, rstudioapi (>= 0.2.0), jsonlite, roxygen2 (>=
4.1.0), rversions, stats, git2r
Suggests testthat (>= 0.7), BiocInstaller, Rcpp (>= 0.10.0), MASS,
rmarkdown, knitr, lintr (>= 0.2.1)
License GPL (>= 2)
NeedsCompilation yes
Author Hadley Wickham [aut, cre],
Winston Chang [aut],
RStudio [cph],
R Core team [ctb] (Some namespace and vignette code extracted from base
R)
Maintainer Hadley Wickham <[email protected]>
Repository CRAN
Date/Publication 2015-05-09 06:20:37
R topics documented:
bash . . . . . . . . . .
build . . . . . . . . . .
build_github_devtools
build_vignettes . . . .
build_win . . . . . . .
check . . . . . . . . .
check_doc . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3
3
4
5
6
6
8
R topics documented:
2
clean_dll . . . . . . . . .
clean_source . . . . . .
clean_vignettes . . . . .
compiler_flags . . . . . .
compile_dll . . . . . . .
create . . . . . . . . . .
create_description . . . .
devtools . . . . . . . . .
dev_example . . . . . .
dev_help . . . . . . . . .
dev_mode . . . . . . . .
document . . . . . . . .
dr_devtools . . . . . . .
dr_github . . . . . . . .
eval_clean . . . . . . . .
github_pull . . . . . . .
has_devel . . . . . . . .
help . . . . . . . . . . .
infrastructure . . . . . .
inst . . . . . . . . . . . .
install . . . . . . . . . .
install_bitbucket . . . . .
install_deps . . . . . . .
install_git . . . . . . . .
install_github . . . . . .
install_gitorious . . . . .
install_local . . . . . . .
install_svn . . . . . . . .
install_url . . . . . . . .
install_version . . . . . .
lint . . . . . . . . . . . .
load_all . . . . . . . . .
load_code . . . . . . . .
load_data . . . . . . . .
load_dll . . . . . . . . .
missing_s3 . . . . . . .
package_deps . . . . . .
path . . . . . . . . . . .
RCMD . . . . . . . . . .
release . . . . . . . . . .
reload . . . . . . . . . .
revdep . . . . . . . . . .
revdep_check_save_logs
run_examples . . . . . .
session_info . . . . . . .
show_news . . . . . . .
source_gist . . . . . . .
source_url . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
8
9
9
10
10
11
12
13
13
14
15
15
16
16
17
17
18
18
20
22
22
24
25
25
26
27
28
29
30
30
31
32
33
34
34
35
35
36
37
37
38
39
40
42
43
43
44
45
bash
3
system.file . . . .
system_check . .
test . . . . . . . .
unload . . . . . .
update_packages
use_data . . . . .
use_data_raw . .
use_git . . . . . .
use_package . . .
wd . . . . . . . .
with_debug . . .
with_something .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Index
bash
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
46
46
47
48
48
49
50
51
51
52
53
54
56
Description
Open bash shell in package directory.
Usage
bash(pkg = ".")
Arguments
pkg
build
package description, can be path or package name. See as.package for more
information
Build package.
Description
Building converts a package source directory into a single bundled file. If binary = FALSE this
creates a tar.gz package that can be installed on any platform, provided they have a full development environment (although packages without source code can typically be install out of the box).
If binary = TRUE, the package will have a platform specific extension (e.g. .zip for windows),
and will only be installable on the current platform, but no development environment is needed.
Usage
build(pkg = ".", path = NULL, binary = FALSE, vignettes = TRUE,
manual = FALSE, args = NULL, quiet = FALSE)
build_github_devtools
Arguments
pkg
package description, can be path or package name. See as.package for more
information
path
binary
vignettes,manual
For source packages: if FALSE, dont build PDF vignettes (--no-vignettes) or
manual (--no-manual).
args
quiet
Value
a string giving the location (including file name) of the built package
See Also
Other build functions: build_win
Description
This function is especially useful for Windows users who want to upgrade their version of devtools
to the development version hosted on on GitHub. In Windows, its not possible to upgrade devtools
while the package is loaded because there is an open DLL, which in Windows cant be overwritten.
This function allows you to build a binary package of the development version of devtools; then
you can restart R (so that devtools isnt loaded) and install the package.
Usage
build_github_devtools(outfile = NULL)
Arguments
outfile
The name of the output file. If NULL (the default), it uses ./devtools.tgz (Mac
and Linux), or ./devtools.zip (Windows).
build_vignettes
Details
Mac and Linux users dont need this function; they can use install_github to install devtools
directly, without going through the separate build-restart-install steps.
This function requires a working development environment. On Windows, it needs http://cran.
r-project.org/bin/windows/Rtools/.
Value
a string giving the location (including file name) of the built package
Examples
## Not run:
library(devtools)
build_github_devtools()
#### Restart R before continuing ####
install.packages("./devtools.zip", repos = NULL)
# Remove the package after installation
unlink("./devtools.zip")
## End(Not run)
build_vignettes
Description
Builds package vignettes using the same algorithm that R CMD build does. This means including
non-Sweave vignettes, using make files (if present), and copying over extra files. You need to ensure
that these files are not included in the built package - ideally they should not be checked into source,
or at least excluded with .Rbuildignore
Usage
build_vignettes(pkg = ".")
Arguments
pkg
package description, can be path or package name. See as.package for more
information
See Also
clean_vignettes to remove the pdfs in inst/doc created from vignettes
clean_vignettes to remove build tex/pdf files.
check
build_win
Description
This function works by bundling source package, and then uploading to http://win-builder.
r-project.org/. Once building is complete youll receive a link to the built package in the email
address listed in the maintainer field. It usually takes around 30 minutes. As a side effect, win-build
also runs R CMD check on the package, so build_win is also useful to check that your package is
ok on windows.
Usage
build_win(pkg = ".", version = c("R-release", "R-devel"), args = NULL,
quiet = FALSE)
Arguments
pkg
package description, can be path or package name. See as.package for more
information
version
args
quiet
See Also
Other build functions: build
check
Description
check automatically builds and checks a source package, using all known best practices. Passing
R CMD check is essential if you want to submit your package to CRAN: you must not have any
ERRORs or WARNINGs, and you want to ensure that there are as few NOTEs as possible. If you
are not submitting to CRAN, at least ensure that there are no ERRORs: these typically represent
serious problems.
check
Usage
check(pkg = ".", document = TRUE, cleanup = TRUE, cran = TRUE,
check_version = FALSE, force_suggests = TRUE, args = NULL,
build_args = NULL, quiet = FALSE, check_dir = tempdir(), ...)
Arguments
pkg
package description, can be path or package name. See as.package for more
information
document
if TRUE (the default), will update and check documentation before running formal check.
cleanup
if TRUE the check directory is removed if the check is successful - this allows
you to inspect the results to figure out what went wrong. If FALSE the check
directory is never removed.
cran
if TRUE (the default), check using the same settings as CRAN uses.
check_version if TRUE, check that the new version is greater than the current version on CRAN,
by setting the _R_CHECK_CRAN_INCOMING_ environment variable to TRUE. (This
also enables spell checking of the packages DESCRIPTION by setting the _R_CHECK_CRAN_INCOMING_USE_
environment variable to TRUE; if no spell checker is installed, a warning is issued.)
force_suggests if FALSE, dont force suggested packages, by setting the _R_CHECK_FORCE_SUGGESTS_
environment variable to FALSE.
args,build_args
An optional character vector of additional command line arguments to be passed
to R CMD check/R CMD build/R CMD INSTALL.
quiet
if TRUE suppresses output from this function.
check_dir
the directory in which the package is checked
...
Additional arguments passed to build
Details
check automatically builds a package before using R CMD check as this is the recommended way
to check packages. Note that this process runs in an independent realisation of R, so nothing in your
current workspace will affect the process.
Environment variables
Devtools does its best to set up an environment that combines best practices with how check works
on CRAN. This includes:
The standard environment variables set by devtools: r_env_vars. Of particular note for package tests is the NOT_CRAN env var which lets you know that your tests are not running on cran,
and hence can take a reasonable amount of time.
Debugging flags for the compiler, set by compiler_flags(FALSE).
Special environment variables set to the same values that CRAN uses when testing packages:
cran_env_vars. Unfortunately exactly what CRAN does when checking a package is not
publicly documented, but we do our best to simulate as accurately as possible given what we
know.
clean_dll
See Also
release if you want to send the checked package to CRAN.
check_doc
Description
This function attempts to run the documentation related checks in the same way that R CMD check
does. Unfortunately it cant run them all because some tests require the package to be loaded, and
the way they attempt to load the code conflicts with how devtools does it.
Usage
check_doc(pkg = ".")
Arguments
pkg
package description, can be path or package name. See as.package for more
information
Value
Nothing. This function is called purely for its side effects: if
Examples
## Not run:
check_doc("mypkg")
## End(Not run)
clean_dll
Description
Invisibly returns the names of the deleted files.
Usage
clean_dll(pkg = ".")
Arguments
pkg
package description, can be path or package name. See as.package for more
information
clean_source
See Also
compile_dll
clean_source
Description
Opens up a fresh R environment and sources file, ensuring that it works independently of the current
working environment.
Usage
clean_source(path, quiet = FALSE)
Arguments
path
path to R script
quiet
If FALSE, the default, all input and output will be displayed, as if youd copied
and paste the code. If TRUE only the final result and the any explicitly printed
output will be displayed.
clean_vignettes
Description
This uses a fairly rudimentary algorithm where any files in inst/doc with a name that exists in
vignettes are removed.
Usage
clean_vignettes(pkg = ".")
Arguments
pkg
package description, can be path or package name. See as.package for more
information
10
compile_dll
compiler_flags
Description
These default flags enforce good coding practice by ensuring that CFLAGS and CXXFLAGS are set to
-Wall -pedantic. These tests are run by cran and are generally considered to be good practice.
Usage
compiler_flags(debug = FALSE)
Arguments
debug
Details
By default compile_dll is run with compiler_flags(TRUE), and check with compiler_flags(FALSE).
If you want to avoid the possible performance penalty from the debug flags, install the package.
See Also
Other debugging flags: with_debug
Examples
compiler_flags()
compiler_flags(TRUE)
compile_dll
Description
compile_dll performs a fake R CMD install so code that works here should work with a regular
install (and vice versa).
Usage
compile_dll(pkg = ".", quiet = FALSE)
Arguments
pkg
package description, can be path or package name. See as.package for more
information
quiet
create
11
Details
During compilation, debug flags are set with compiler_flags(TRUE).
Invisibly returns the names of the DLL.
Note
If this is used to compile code that uses Rcpp, you will need to add the following line to your
Makevars file so that it knows where to find the Rcpp headers: PKG_CPPFLAGS=`$(R_HOME)/bin/Rscript -e 'Rcpp:::CxxF
See Also
clean_dll to delete the compiled files.
create
Description
Similar to package.skeleton, except that it only creates the standard devtools directory structures;
it doesnt try and create source code and data files by inspecting the global environment.
Usage
create(path, description = getOption("devtools.desc"), check = FALSE,
rstudio = TRUE)
setup(path = ".", description = getOption("devtools.desc"), check = FALSE,
rstudio = TRUE)
Arguments
path
location to create new package. The last component of the path will be used as
the package name.
description
check
rstudio
Details
create requires that the directory doesnt exist yet; it will be created but deleted upon failure.
setup assumes an existing directory from which it will infer the package name.
See Also
Text with package.skeleton
12
create_description
Examples
## Not run:
# Create a package using all defaults:
path <- file.path(tempdir(), "myDefaultPackage")
create(path)
# Override a description attribute.
path <- file.path(tempdir(), "myCustomPackage")
my_description <- list("Maintainer" =
"'Yoni Ben-Meshulam' <[email protected]>")
create(path, my_description)
## End(Not run)
create_description
Description
Create a default DESCRIPTION file for a package.
Usage
create_description(path = ".", extra = getOption("devtools.desc"),
quiet = FALSE)
Arguments
path
extra
quiet
Details
To set the default author and licenses, set options devtools.desc.author and devtools.desc.license.
I use options(devtools.desc.author = '"Hadley Wickham <[email protected]> [aut,cre]"', devtools.desc
devtools
13
devtools
Description
Package development tools for R.
Package options
Devtools uses the following options to configure behaviour:
devtools.path: path to use for dev_mode
devtools.name: your name, used when signing draft emails.
devtools.install.args: a string giving extra arguments passed to R CMD install by
install.
devtools.desc.author: a string providing a default Authors@R string to be used in new
DESCRIPTIONs. Should be a R code, and look like "Hadley Wickham <[email protected]> [aut, cre]".
See as.person for more details.
devtools.desc.license: a default license string to use for new packages.
devtools.desc.suggests: a character vector listing packages to to add to suggests by defaults for new packages.
devtools.desc: a named list listing any other extra options to add to DESCRIPTION
dev_example
Description
Run a examples for an in-development function.
Usage
dev_example(topic)
Arguments
topic
See Also
Other example functions: run_examples
14
dev_help
Examples
## Not run:
# Runs installed example:
library("ggplot2")
example("ggplot")
# Runs develoment example:
load_all("ggplot2")
dev_example("ggplot")
## End(Not run)
dev_help
Description
Note that this only renders a single documentation file, so that links to other files within the package
wont work.
Usage
dev_help(topic, stage = "render", type = getOption("help_type"))
Arguments
topic
stage
at which stage ("build", "install", or "render") should \Sexpr macros be executed? This is only important if youre using \Sexpr macros in your Rd files.
type
Examples
## Not run:
library("ggplot2")
help("ggplot") # loads installed documentation for ggplot
load_all("ggplot2")
dev_help("ggplot") # loads development documentation for ggplot
## End(Not run)
dev_mode
dev_mode
15
Description
When activated, dev_mode creates a new library for storing installed packages. This new library
is automatically created when dev_mode is activated if it does not already exist. This allows you
to test development packages in a sandbox, without interfering with the other packages you have
installed.
Usage
dev_mode(on = NULL, path = getOption("devtools.path"))
Arguments
on
path
turn dev mode on (TRUE) or off (FALSE). If omitted will guess based on whether
or not path is in .libPaths
directory to library.
Examples
## Not run:
dev_mode()
dev_mode()
## End(Not run)
document
Description
This function is a wrapper for the roxygenize() function from the roxygen2 package. See the
documentation and vignettes of that package to learn how to use roxygen.
Usage
document(pkg = ".", clean = NULL, roclets = NULL, reload = TRUE)
Arguments
pkg
clean,reload
roclets
package description, can be path or package name. See as.package for more
information
Deprecated.
Character vector of roclet names to use with package. This defaults to NULL,
which will use the roclets fields in the list provided in the Roxygen DESCRIPTION field. If none are specified, defaults to c("collate", "namespace", "rd").
16
dr_github
See Also
roxygenize, browseVignettes("roxygen2")
dr_devtools
Description
This checks to make sure youre using the latest release of R, the released version of RStudio (if
youre using it as your gui), and the latest version of devtools and its dependencies.
Usage
dr_devtools()
See Also
Other doctors: dr_github
Examples
dr_devtools()
dr_github
Description
Diagnose potential github issues
Usage
dr_github(path = ".")
Arguments
path
See Also
Other doctors: dr_devtools
Examples
dr_github()
eval_clean
eval_clean
17
Description
Evaluate code in a clean R session.
Usage
eval_clean(expr, quiet = TRUE)
evalq_clean(expr, quiet = TRUE)
Arguments
expr
quiet
if TRUE, the default, only the final result and the any explicitly printed output
will be displayed. If FALSE, all input and output will be displayed, as if youd
copied and paste the code.
Value
An invisible TRUE on success.
Examples
x <- 1
y <- 2
ls()
evalq_clean(ls())
evalq_clean(ls(), FALSE)
eval_clean(quote({
z <- 1
ls()
}))
github_pull
GitHub references
Description
Use as ref parameter to install_github. Allows installing a specific pull request or the latest
release.
18
help
Usage
github_pull(pull)
github_release()
Arguments
pull
See Also
install_github
has_devel
Description
Thanks to the suggestion of Simon Urbanek.
Usage
has_devel()
Value
TRUE if your development environment is correctly set up, otherwise returns an error.
Examples
has_devel()
help
Description
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.
Usage
# help(topic, package = NULL, ...)
# ?e2
# e1?e2
help
19
Arguments
topic
package
A name or character string specifying the package in which to search for the
help topic. If NULL, seach all packages.
...
e1
e2
Details
The ? function is a replacement for ? from the utils package. It will search for help in devtoolsloaded packages first, then in regular packages.
The help function is a replacement for 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.
Examples
## Not run:
# 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")
## End(Not run)
# To see the help pages for utils::help and utils::`?`:
help("help", "utils")
help("?", "utils")
## Not run:
# 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')
## End(Not run)
20
infrastructure
infrastructure
Description
Add useful infrastructure to a package.
Usage
use_testthat(pkg = ".")
use_test(name, pkg = ".")
use_rstudio(pkg = ".")
use_vignette(name, pkg = ".")
use_rcpp(pkg = ".")
use_travis(pkg = ".")
use_coveralls(pkg = ".")
use_appveyor(pkg = ".")
use_package_doc(pkg = ".")
use_revdep(pkg = ".")
use_cran_comments(pkg = ".")
use_code_of_conduct(pkg = ".")
use_cran_badge(pkg = ".")
Arguments
pkg
package description, can be path or package name. See as.package for more
information.
name
File name to use for new vignette. Should consist only of numbers, letters, _
and -. I recommend using lower case.
use_testthat
Add testing infrastructure to a package that does not already have it. This will create tests/testthat.R,
tests/testthat/ and add testthat to the suggested packages. This is called automatically from
test if needed.
infrastructure
21
use_test
Add a test file, also add testing infrastructure if necessary. This will create tests/testthat/test-<name>.R
with a user-specified name for the test. Will fail if the file exists.
use_rstudio
Does not modify .Rbuildignore as RStudio will do that when opened for the first time.
use_vignette
Adds needed packages to DESCRIPTION, and creates draft vignette in vignettes/. It adds inst/doc
to .gitignore so you dont accidentally check in the built vignettes.
use_rcpp
Creates src/ and adds needed packages to DESCRIPTION.
use_travis
Add basic travis template to a package. Also adds .travis.yml to .Rbuildignore so it isnt
included in the built package.
use_coveralls
Add coveralls to basic travis template to a package.
use_appveyor
Add basic AppVeyor template to a package. Also adds appveyor.yml to .Rbuildignore so it isnt
included in the built package.
use_package_doc
Adds a roxygen template for package documentation
use_revdep
Add revdep directory and basic check template.
use_cran_comments
Add cran-comments.md template.
use_code_of_conduct
Add a code of conduct to from http://contributor-covenant.org.
use_cran_badge
Add a badge to show CRAN status and version number on the README
22
install
See Also
Other infrastructure: add_build_ignore, use_build_ignore; use_data_raw; use_data; use_package;
use_readme_rmd
inst
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.
Usage
inst(name)
Arguments
name
Details
It searches for the package in .libPaths(). If multiple dirs are found, it will return the first one.
Examples
inst("devtools")
inst("grid")
## Not run:
# Can be passed to other devtools functions
unload(inst("ggplot2"))
## End(Not run)
install
Description
Uses R CMD INSTALL to install the package. Will also try to install dependencies of the package
from CRAN, if theyre not already installed.
install
23
Usage
install(pkg = ".", reload = TRUE, quick = FALSE, local = TRUE,
args = getOption("devtools.install.args"), quiet = FALSE,
dependencies = NA, build_vignettes = FALSE,
keep_source = getOption("keep.source.pkgs"), threads = getOption("Ncpus",
1), ...)
Arguments
pkg
package description, can be path or package name. See as.package for more
information
reload
if TRUE (the default), will automatically reload the package after installing.
quick
if TRUE skips docs, multiple-architectures, demos, and vignettes, to make installation as fast as possible.
local
if FALSE builds the package first: this ensures that the installation is completely
clean, and prevents any binary artefacts (like .o, .so) from appearing in your
local package directory, but is considerably slower, because every compile has
to start from scratch.
args
quiet
dependencies
logical indicating to also install uninstalled packages which this pkg depends
on/links to/suggests. See argument dependencies of install.packages.
build_vignettes
if TRUE, will build vignettes. Normally it is build thats responsible for creating
vignettes; this argument makes sure vignettes are built even if a build never
happens (i.e. because local = TRUE.
keep_source
If TRUE will keep the srcrefs from an installed package. This is useful for debugging (especially inside of RStudio). It defaults to the option "keep.source.pkgs".
threads
...
additional arguments passed to install.packages when installing dependencies. pkg is installed with R CMD INSTALL.
Details
By default, installation takes place using the current package directory. If you have compiled code,
this means that artefacts of compilation will be created in the src/ directory. If you want to avoid
this, you can use local = FALSE to first build a package bundle and then install it from a temporary
directory. This is slower, but keeps the source directory pristine.
If the package is loaded, it will be reloaded after installation. This is not always completely possible,
see reload for caveats.
To install a package in a non-default library, use with_libpaths.
24
install_bitbucket
See Also
with_debug to install packages with debugging flags set.
Other package installation: install_bitbucket; install_github; install_gitorious; install_git;
install_svn; install_url; install_version
install_bitbucket
Description
This function is vectorised so you can install multiple packages in a single command.
Usage
install_bitbucket(repo, username, ref = "master", subdir = NULL,
auth_user = NULL, password = NULL, ...)
Arguments
repo
Repository address in the format username/repo[/subdir][@ref|#pull]. Alternatively, you can specify subdir and/or ref using the respective parameters
(see below); if both is specified, the values in repo take precedence.
username
ref
Desired git reference; culd be a commit, tag, or branch name. Defaults to master.
subdir
auth_user
password
your password
...
See Also
Bitbucket API docs: https://confluence.atlassian.com/display/BITBUCKET/Use+the+Bitbucket+
REST+APIs
Other package installation: install_github; install_gitorious; install_git; install_svn;
install_url; install_version; install
Examples
## Not run:
install_bitbucket("sulab/mygene.r@default")
install_bitbucket("dannavarro/lsr-package")
## End(Not run)
install_deps
install_deps
25
Description
Install package dependencies if needed.
Usage
install_deps(pkg = ".", dependencies = NA, threads = getOption("Ncpus",
1), ...)
Arguments
pkg
dependencies
threads
...
package description, can be path or package name. See as.package for more
information
logical indicating to also install uninstalled packages which this pkg depends
on/links to/suggests. See argument dependencies of install.packages.
number of concurrent threads to use for installing dependencies. It defaults to
the option "Ncpus" or 1 if unset.
additional arguments passed to install.packages.
Examples
## Not run: install_deps(".")
install_git
Description
It is vectorised so you can install multiple packages with a single command. You do not need to
have git installed.
Usage
install_git(url, subdir = NULL, branch = NULL, args = character(0), ...)
Arguments
url
subdir
branch
args
...
26
install_github
See Also
Other package installation: install_bitbucket; install_github; install_gitorious; install_svn;
install_url; install_version; install
Examples
## Not run:
install_git("git://github.com/hadley/stringr.git")
install_git("git://github.com/hadley/stringr.git", branch = "stringr-0.2")
## End(Not run)
install_github
Description
This function is vectorised on repo so you can install multiple packages in a single command.
Usage
install_github(repo, username = NULL, ref = "master", subdir = NULL,
auth_token = github_pat(), host = "api.github.com", ...)
Arguments
repo
username
ref
subdir
auth_token
host
...
Repository address in the format username/repo[/subdir][@ref|#pull]. Alternatively, you can specify subdir and/or ref using the respective parameters
(see below); if both is specified, the values in repo take precedence.
User name. Deprecated: please include username in the repo
Desired git reference. Could be a commit, tag, or branch name, or a call to
github_pull. Defaults to "master".
subdirectory within repo that contains the R package.
To install from a private repo, generate a personal access token (PAT) in https:
//github.com/settings/applications and supply to this argument. This
is safer than using a password because you can easily delete a PAT without
affecting any others. Defaults to the GITHUB_PAT environment variable.
Github API host to use. Override with your github enterprise hostname, for
example, "github.hostname.com/api/v3".
Other arguments passed on to install.
Details
Attempting to install from a source repository that uses submodules raises a warning. Because
the zipped sources provided by GitHub do not include submodules, this may lead to unexpected
behaviour or compilation failure in source packages. In this case, cloning the repository manually
using install_git with args="--recursive" may yield better results.
install_gitorious
27
See Also
github_pull
Other package installation: install_bitbucket; install_gitorious; install_git; install_svn;
install_url; install_version; install
Examples
## Not run:
install_github("klutometis/roxygen")
install_github("wch/ggplot2")
install_github(c("rstudio/httpuv", "rstudio/shiny"))
install_github(c("hadley/[email protected]", "klutometis/roxygen#142",
"mfrasca/r-logging/pkg"))
# Update devtools to the latest version, on Linux and Mac
# On Windows, this won't work - see ?build_github_devtools
install_github("hadley/devtools")
# To install from a private repo, use auth_token with a token
# from https://github.com/settings/applications. You only need the
# repo scope. Best practice is to save your PAT in env var called
# GITHUB_PAT.
install_github("hadley/private", auth_token = "abc")
## End(Not run)
install_gitorious
Description
This function is vectorised so you can install multiple packages in a single command.
Usage
install_gitorious(repo, ref = "master", subdir = NULL, ...)
Arguments
repo
Repository address in the format username/repo[/subdir][@ref|#pull]. Alternatively, you can specify subdir and/or ref using the respective parameters
(see below); if both is specified, the values in repo take precedence.
ref
subdir
...
28
install_local
See Also
Other package installation: install_bitbucket; install_github; install_git; install_svn;
install_url; install_version; install
Examples
## Not run:
install_gitorious("r-mpc-package/r-mpc-package")
## End(Not run)
install_local
Description
This function is vectorised so you can install multiple packages in a single command.
Usage
install_local(path, subdir = NULL, ...)
Arguments
path
path to local directory, or compressed file (tar, zip, tar.gz tar.bz2, tgz2 or tbz)
subdir
...
Examples
## Not run:
dir <- tempfile()
dir.create(dir)
pkg <- download.packages("testthat", dir, type = "source")
install_local(pkg[, 2])
## End(Not run)
install_svn
install_svn
29
Description
This function requires svn to be installed on your system in order to be used.
Usage
install_svn(url, subdir = NULL, branch = NULL, args = character(0), ...,
revision = NULL)
Arguments
url
subdir
A sub-directory withing a svn repository that may contain the package we are
interested in installing. By default, this points to the trunk directory.
branch
args
...
revision
Details
It is vectorised so you can install multiple packages with a single command.
See Also
Other package installation: install_bitbucket; install_github; install_gitorious; install_git;
install_url; install_version; install
Examples
## Not run:
install_svn("https://github.com/hadley/stringr")
install_svn("https://github.com/hadley/httr", branch = "oauth")
## End(Not run)
30
install_version
install_url
Description
This function is vectorised so you can install multiple packages in a single command.
Usage
install_url(url, subdir = NULL, config = list(), ...)
Arguments
url
location of package on internet. The url should point to a zip file, a tar file or a
bzipped/gzipped tar file.
subdir
config
...
See Also
Other package installation: install_bitbucket; install_github; install_gitorious; install_git;
install_svn; install_version; install
Examples
## Not run:
install_url("https://github.com/hadley/stringr/archive/master.zip")
## End(Not run)
install_version
Description
If you are installing an package that contains compiled code, you will need to have an R development environment installed. You can check if you do by running has_devel.
Usage
install_version(package, version = NULL, repos = getOption("repos"),
type = getOption("pkgType"), ...)
lint
31
Arguments
package
package name
version
If the specified version is NULL or the same as the most recent version of the
package, this function simply calls install. Otherwise, it looks at the list of
archived source tarballs and tries to install an older version instead.
repos
character vector, the base URL(s) of the repositories to use, e.g., the URL of a
CRAN mirror such as "http://cran.us.r-project.org". For more details
on supported URL schemes see url.
Can be NULL to install from local files, directories or URLs: this will be inferred
by extension from pkgs if of length one.
type
character, indicating the type of package to download and install. Will be "source"
except on Windows and some OS X builds: see the section on Binary packages
for those.
...
Author(s)
Jeremy Stephens
See Also
Other package installation: install_bitbucket; install_github; install_gitorious; install_git;
install_svn; install_url; install
lint
Description
The default lintings correspond to the style guide at http://r-pkgs.had.co.nz/r.html#style,
however it is possible to override any or all of them using the linters parameter.
Usage
lint(pkg = ".", cache = TRUE, ...)
Arguments
pkg
package description, can be path or package name. See as.package for more
information
cache
store the lint results so repeated lints of the same content use the previous results.
...
32
load_all
Details
The lintr cache is by default stored in ~/.R/lintr_cache/ (this can be configured by setting
options(lintr.cache_directory)). It can be cleared by calling clear_cache.
See Also
lint_package, lint
load_all
Description
load_all loads a package. It roughly simulates what happens when a package is installed and
loaded with library.
Usage
load_all(pkg = ".", reset = TRUE, recompile = FALSE, export_all = TRUE,
quiet = FALSE)
Arguments
pkg
package description, can be path or package name. See as.package for more information. If the DESCRIPTION file does not exist, it is created using create_description.
reset
clear package environment and reset file cache before loading any pieces of
the package. This is equivalent to running unload and is the default. Use
reset = FALSE may be faster for large code bases, but is a significantly less
accurate approximation.
recompile
export_all
If TRUE (the default), export all objects. If FALSE, export only the objects that
are listed as exports in the NAMESPACE file.
quiet
Details
Currently load_all:
Loads all data files in data/. See load_data for more details.
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.
Compiles any C, C++, or Fortran code in the src/ directory and connects the generated DLL
into R. See compile_dll for more details.
Runs .onAttach(), .onLoad() and .onUnload() functions at the correct times.
load_code
33
Namespaces
The namespace environment <namespace:pkgname>, is a child of the imports environment, which
has the name attribute imports:pkgname. It is in turn is a child of <namespace:base>, 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 <package:pkgname> 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.
Shim files
load_all also inserts shim functions into the imports environment of the laded 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.
Examples
## Not run:
# 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)
## End(Not run)
load_code
Load R code.
Description
Load all R code in the R directory. The first time the code is loaded, .onLoad will be run if it exists.
34
load_dll
Usage
load_code(pkg = ".")
Arguments
pkg
package description, can be path or package name. See as.package for more
information
load_data
Load data.
Description
Loads all .RData files in the data subdirectory.
Usage
load_data(pkg = ".")
Arguments
pkg
package description, can be path or package name. See as.package for more
information
load_dll
Description
Load a compiled DLL
Usage
load_dll(pkg = ".")
Arguments
pkg
package description, can be path or package name. See as.package for more
information
missing_s3
35
missing_s3
Description
The method is heuristic - looking for objs with a period in their name.
Usage
missing_s3(pkg = ".")
Arguments
pkg
package_deps
package description, can be path or package name. See as.package for more
information
Description
Find all the dependencies of a package and determine whether they ahead or behind cran. A
print() method focusses on mismatches between local and CRAN version; a update() method
installs outdated or missing packages from CRAN.
Usage
package_deps(pkg, dependencies = NA, repos = getOption("repos"),
type = getOption("pkgType"))
dev_package_deps(pkg = ".", dependencies = NA, repos = getOption("repos"),
type = getOption("pkgType"))
## S3 method for class 'package_deps'
update(object, ..., quiet = FALSE)
Arguments
pkg
dependencies
36
path
repos
type
object,...
Arguments ot
quiet
Value
A data frame with additional.
Examples
## Not run:
package_deps("devtools")
# Use update to update any updated/
update(package_deps("devtools"))
## End(Not run)
path
Description
Get/set the PATH variable.
Usage
get_path()
set_path(path)
add_path(path, after = Inf)
Arguments
path
after
for add_path, the place on the PATH where the new paths should be added
Value
set_path invisibly returns the old path.
See Also
with_path to temporarily set the path for a block of code
Other path: on_path
RCMD
37
Examples
path <- get_path()
length(path)
old <- add_path(".")
length(get_path())
set_path(old)
length(get_path())
RCMD
Description
Run R CMD xxx from within R
Usage
RCMD(cmd, options, path = tempdir(), env_vars = NULL, ...)
Arguments
cmd
options
path
env_vars
...
Value
TRUE if the command succeeds, throws an error if the command fails.
release
Description
Run automated and manual tests, then ftp to CRAN.
Usage
release(pkg = ".", check = TRUE)
38
reload
Arguments
pkg
package description, can be path or package name. See as.package for more
information
check
if TRUE, run checking, otherwise omit it. This is useful if youve just checked
your package and youre ready to release it.
Details
The package release process will:
Confirm that the package passes R CMD check
Ask if youve checked your code on win-builder
Confirm that news is up-to-date
Confirm that DESCRIPTION is ok
Ask if youve checked packages that depend on your package
Build the package
Submit the package to CRAN, using comments in "cran-comments.md"
You can also add arbitrary extra questions by defining an (un-exported) function called release_questions()
that returns a character vector of additional questions to ask.
You also need to read the CRAN repository policy at http://cran.r-project.org/web/packages/
policies.html and make sure youre in line with the policies. release tries to automate as many
of polices as possible, but its impossible to be completely comprehensive, and they do change in
between releases of devtools.
Guarantee
If a devtools bug causes one of the CRAN maintainers to treat you impolitely, I will personally send
you a handwritten apology note. Please forward me the email and your address, and Ill get a card
in the mail.
reload
Description
This attempts to unload and reload a package. If the package is not loaded already, it does nothing.
Its not always possible to cleanly unload a package: see the caveats in unload for some of the
potential failure points. If in doubt, restart R and reload the package with library.
Usage
reload(pkg = ".", quiet = FALSE)
revdep
39
Arguments
pkg
package description, can be path or package name. See as.package for more
information
quiet
Examples
## Not run:
# Reload package that is in current directory
reload(".")
# Reload package that is in ./ggplot2/
reload("ggplot2/")
# Can use inst() to find the package path
# This will reload the installed ggplot2 package
reload(inst("ggplot2"))
## End(Not run)
revdep
Description
Tools to check and notify maintainers of all CRAN and bioconductor packages that depend on the
specified package.
Usage
revdep(pkg, dependencies = c("Depends", "Imports", "Suggests", "LinkingTo"),
recursive = FALSE, ignore = NULL, bioconductor = FALSE)
revdep_maintainers(pkg = ".")
Arguments
pkg
Package name. This is unlike most devtools packages which take a path because
you might want to determine dependencies for a package that you dont have
installed. If omitted, defaults to the name of the current package.
dependencies
recursive
ignore
A character vector of package names to ignore. These packages will not appear in returned vector. This is used in revdep_check to avoid packages with
installation problems or extremely long check times.
bioconductor
40
revdep_check_save_logs
Details
The first run in a session will be time-consuming because it must download all package metadata
from CRAN and bioconductor. Subsequent runs will be faster.
See Also
revdep_check() to run R CMD check on all reverse dependencies.
Examples
## Not run:
revdep("ggplot2")
revdep("ggplot2", ignore = c("xkcd", "zoo"))
## End(Not run)
revdep_check_save_logs
Run R CMD check on all downstream dependencies.
Description
Use revdep_check() to run check_cran() on all downstream dependencies. Summarises the
results with revdep_check_summary and save logs with revdep_check_save_logs.
Usage
revdep_check_save_logs(res, log_dir = "revdep")
revdep_check_save_summary(res, log_dir = "revdep")
revdep_check_summary(res)
revdep_check(pkg = ".", recursive = FALSE, ignore = NULL,
dependencies = c("Depends", "Imports", "Suggests", "LinkingTo"),
libpath = getOption("devtools.revdep.libpath"), srcpath = libpath,
bioconductor = FALSE, type = getOption("pkgType"),
threads = getOption("Ncpus", 1), check_dir = tempfile("check_cran"))
Arguments
res
Result of revdep_check
log_dir
pkg
recursive
revdep_check_save_logs
41
ignore
A character vector of package names to ignore. These packages will not appear in returned vector. This is used in revdep_check to avoid packages with
installation problems or extremely long check times.
dependencies
libpath
Path to library to store dependencies packages - if you youre doing this a lot its
a good idea to pick a directory and stick with it so you dont have to download
all the packages every time.
srcpath
bioconductor
type
binary Package type to test (source, mac.binary etc). Defaults to the same type
as install.packages().
threads
check_dir
Value
An invisible list of results. But youll probably want to look at the check results on disk, which are
saved in check_dir. Summaries of all ERRORs and WARNINGs will be stored in check_dir/00check-summary.txt.
Check process
1. Install pkg (in special library, see below).
2. Find all CRAN packges that dependent on pkg.
3. Install those packages, along with their dependencies.
4. Run R CMD check on each package.
5. Uninstall pkg (so other reverse dependency checks dont use the development version instead
of the CRAN version)
Package library
By default revdep_check uses temporary library to store any packages that are required by the
packages being tested. This ensures that they dont interfere with your default library, but means
that if you restart R between checks, youll need to reinstall all the packages. If youre doing reverse
dependency checks frequently, I recommend that you create a directory for these packages and set
option(devtools.libpath).
See Also
revdep_maintainers() to run R CMD check on all reverse dependencies.
42
run_examples
Examples
## Not run:
# Run R CMD check on all downstream dependencies of ggplot2
res <- revdep_check("ggplot2")
revdep_check_summary(res)
revdep_check_save_logs(res)
## End(Not run)
run_examples
Description
One of the most frustrating parts of R CMD check is getting all of your examples to pass - whenever one fails you need to fix the problem and then restart the whole process. This function makes
it a little easier by making it possible to run all examples from an R function.
Usage
run_examples(pkg = ".", start = NULL, show = TRUE, test = FALSE,
run = TRUE, fresh = FALSE)
Arguments
pkg
package description, can be path or package name. See as.package for more
information
start
Where to start running the examples: this can either be the name of Rd file to
start with (with or without extensions), or a topic name. If omitted, will start
with the (lexicographically) first file. This is useful if you have a lot of examples
and dont want to rerun them every time you fix a problem.
show
test
run
fresh
if TRUE, will be run in a fresh R session. This has the advantage that theres no
way the examples can depend on anything in the current session, but interactive
code (like browser) wont work.
See Also
Other example functions: dev_example
session_info
43
session_info
Description
This is sessionInfo() re-written from scratch to both exclude data thats rarely useful (e.g., the
full collate string or base packages loaded) and include stuff youd like to know (e.g., where a
package was installed from).
Usage
session_info(pkgs = NULL, include_base = FALSE)
Arguments
pkgs
Either a vector of package names or NULL. If NULL, displays all loaded packages. If a character vector, also, includes all dependencies of the package.
include_base
Include base packages in summary? By default this is false since base packages
should always match the R version.
Examples
session_info()
session_info("devtools")
show_news
Description
Show package news
Usage
show_news(pkg = ".", latest = TRUE, ...)
Arguments
pkg
package description, can be path or package name. See as.package for more
information
latest
if TRUE, only show the news for the most recent version.
...
44
source_gist
source_gist
Description
Gist is a simple way to share snippets and pastes with others. All gists are git repositories, so they
are automatically versioned, forkable and usable as a git repository. https://gist.github.com/
Usage
source_gist(id, ..., sha1 = NULL, quiet = FALSE)
Arguments
id
...
sha1
The SHA-1 hash of the file at the remote URL. This is highly recommend as
it prevents you from accidentally running code thats not what you expect. See
source_url for more information on using a SHA-1 hash.
quiet
Examples
# You can run gists given their id
source_gist(6872663)
source_gist("6872663")
# Or their html url
source_gist("https://gist.github.com/hadley/6872663")
source_gist("gist.github.com/hadley/6872663")
# It's highly recommend that you run source_gist with the optional
# sha1 argument - this will throw an error if the file has changed since
# you first ran it
source_gist(6872663, sha1 = "54f1db27e60")
## Not run:
# Wrong hash will result in error
source_gist(6872663, sha1 = "54f1db27e61")
## End(Not run)
source_url
45
source_url
Run a script through some protocols such as http, https, ftp, etc.
Description
Internally, source_url calls getURL in RCurl package and then read the contents by textConnection,
which is then sourceed. See ?getURL for the available protocol.
Usage
source_url(url, ..., sha1 = NULL)
Arguments
url
url
...
sha1
The (prefix of the) SHA-1 hash of the file at the remote URL.
Details
If a SHA-1 hash is specified with the sha1 argument, then this function will check the SHA-1 hash
of the downloaded file to make sure it matches the expected value, and throw an error if it does
not match. If the SHA-1 hash is not specified, it will print a message displaying the hash of the
downloaded file. The purpose of this is to improve security when running remotely-hosted code; if
you have a hash of the file, you can be sure that it has not changed. For convenience, it is possible
to use a truncated SHA1 hash, down to 6 characters, but keep in mind that a truncated hash wont
be as secure as the full hash.
Examples
## Not run:
source_url("https://gist.github.com/hadley/6872663/raw/hi.r")
# With a hash, to make sure the remote file hasn't changed
source_url("https://gist.github.com/hadley/6872663/raw/hi.r",
sha1 = "54f1db27e60bb7e0486d785604909b49e8fef9f9")
# With a truncated hash
source_url("https://gist.github.com/hadley/6872663/raw/hi.r",
sha1 = "54f1db27e60")
## End(Not run)
46
system_check
system.file
Description
This function is meant to intercept calls to system.file, so that it behaves well with packages
loaded by devtools. It is made available when a package is loaded with load_all.
Usage
# system.file(..., package = "base", lib.loc = NULL, mustWork = FALSE)
Arguments
...
character vectors, specifying subdirectory and file(s) within some package. The
default, none, returns the root of the package. Wildcards are not supported.
package
a character string with the name of a single package. An error occurs if more
than one package name is given.
lib.loc
a character vector with path names of R libraries. See Details for the meaning
of the default value of NULL.
mustWork
Details
When system.file is called from the R console (the global envrironment), 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 packages 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.
system_check
Description
Run a system command and check if it succeeds.
Usage
system_check(cmd, args = character(), env = character(), quiet = FALSE,
...)
test
47
Arguments
cmd
args
env
quiet
...
Value
TRUE if the command succeeds, an error will be thrown if the command fails.
test
Description
Tests are assumed to be located in either the inst/tests/ or tests/testthat directory (the latter
is recommended). See test_dir for the naming convention of test scripts within one of those
directories and test_check for the folder structure conventions.
Usage
test(pkg = ".", filter = NULL, ...)
Arguments
pkg
package description, can be path or package name. See as.package for more
information
filter
If not NULL, only tests with file names matching this regular expression will
be executed. Matching will take on the file name after it has been stripped of
"test-" and ".r".
...
Details
If no testing infrastructure is present, youll be asked if you want devtools to create it for you (in
interactive sessions only). See add_test_infrastructure for more details.
48
update_packages
unload
Unload a package
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
useDynLib(pkgname) and may fail in other cases. If you do encounter a failure, please file a
bug report at http://github.com/hadley/devtools/issues.
Usage
unload(pkg = ".")
Arguments
pkg
package description, can be path or package name. See as.package for more
information
Examples
## Not run:
# Unload package that is in current directory
unload(".")
# Unload package that is in ./ggplot2/
unload("ggplot2/")
# Can use inst() to find the path of an installed package
# This will load and unload the installed ggplot2 package
library(ggplot2)
unload(inst("ggplot2"))
## End(Not run)
update_packages
Description
Works similarly to install.packages() but doesnt install packages that are already installed, and
also upgrades out dated dependencies.
use_data
49
Usage
update_packages(pkgs, dependencies = NA, repos = getOption("repos"),
type = getOption("pkgType"))
Arguments
pkgs
dependencies
Which dependencies do you want to check? Can be a character vector (selecting from "Depends", "Imports", "LinkingTo", "Suggests", or "Enhances"), or a
logical vector.
TRUE is shorthand for "Depends", "Imports", "LinkingTo" and "Suggests". NA is
shorthand for "Depends", "Imports" and "LinkingTo" and is the default. FALSE
is shorthand for no dependencies (i.e. just check this package, not its dependencies).
repos
type
See Also
package_deps to see which packages are out of date/ missing.
Examples
## Not run:
update_packages("ggplot2")
update_packages(c("plyr", "ggplot2"))
## End(Not run)
use_data
Description
This function makes it easy to save package data in the correct format.
Usage
use_data(..., pkg = ".", internal = FALSE, overwrite = FALSE,
compress = "bzip2")
50
use_data_raw
Arguments
...
pkg
internal
If FALSE, saves each object in individual .rda files in the data/ directory. These
are available whenever the package is loaded. If TRUE, stores all objects in a
single R/sysdata.rda file. These objects are only available within the package.
overwrite
By default, use_data will not overwrite existing files. If you really want to do
so, set this to TRUE.
compress
Choose the type of compression used by save. Should be one of "gzip", "bzip2"
or "xz".
See Also
Other infrastructure: add_build_ignore, use_build_ignore; add_rstudio_project, add_test_infrastructure,
add_test_infrastructure, add_travis, add_travis, add_travis, add_travis, infrastructure,
use_appveyor, use_code_of_conduct, use_coveralls, use_cran_badge, use_cran_comments,
use_package_doc, use_rcpp, use_revdep, use_rstudio, use_test, use_testthat, use_travis,
use_vignette; use_data_raw; use_package; use_readme_rmd
Examples
## Not run:
x <- 1:10
y <- 1:100
use_data(x, y) # For external use
use_data(x, y, internal = TRUE) # For internal use
## End(Not run)
use_data_raw
Description
Use data-raw to compute package datasets.
Usage
use_data_raw(pkg = ".")
Arguments
pkg
use_git
51
See Also
Other infrastructure: add_build_ignore, use_build_ignore; add_rstudio_project, add_test_infrastructure,
add_test_infrastructure, add_travis, add_travis, add_travis, add_travis, infrastructure,
use_appveyor, use_code_of_conduct, use_coveralls, use_cran_badge, use_cran_comments,
use_package_doc, use_rcpp, use_revdep, use_rstudio, use_test, use_testthat, use_travis,
use_vignette; use_data; use_package; use_readme_rmd
use_git
Description
Initialise a git repository.
Usage
use_git(message = "Initial commit", pkg = ".")
Arguments
message
pkg
See Also
Other git infrastructure: use_git_hook; use_github
Examples
## Not run: use_git()
use_package
Description
This adds a dependency to DESCRIPTION and offers a little advice about how to best use it.
Usage
use_package(package, type = "Imports", pkg = ".")
52
wd
Arguments
package
type
Type of dependency: must be one of "Imports", "Suggests", "Depends", "Suggests", "Enhances", or "LinkingTo" (or unique abbreviation)
pkg
package description, can be path or package name. See as.package for more
information.
See Also
Other infrastructure: add_build_ignore, use_build_ignore; add_rstudio_project, add_test_infrastructure,
add_test_infrastructure, add_travis, add_travis, add_travis, add_travis, infrastructure,
use_appveyor, use_code_of_conduct, use_coveralls, use_cran_badge, use_cran_comments,
use_package_doc, use_rcpp, use_revdep, use_rstudio, use_test, use_testthat, use_travis,
use_vignette; use_data_raw; use_data; use_readme_rmd
Examples
## Not run:
use_package("ggplot2")
use_package("dplyr", "suggests")
## End(Not run)
wd
Description
Set working directory.
Usage
wd(pkg = ".", path = "")
Arguments
pkg
package description, can be path or package name. See as.package for more
information
path
path within package. Leave empty to change working directory to package directory.
with_debug
with_debug
53
Description
Temporarily set debugging compilation flags.
Usage
with_debug(code, CFLAGS = NULL, CXXFLAGS = NULL, FFLAGS = NULL,
FCFLAGS = NULL, debug = TRUE, action = "replace")
Arguments
code
to execute.
CFLAGS
CXXFLAGS
FFLAGS
FCFLAGS
debug
action
See Also
Other debugging flags: compiler_flags
Examples
flags <- names(compiler_flags(TRUE))
with_debug(Sys.getenv(flags))
## Not run:
install("mypkg")
with_debug(install("mypkg"))
## End(Not run)
54
with_something
with_something
Description
Usage
with_envvar(new, code, action = "replace")
with_env(new, code)
with_locale(new, code)
with_collate(new, code)
in_dir(new, code)
with_libpaths(new, code)
with_lib(new, code)
with_options(new, code)
with_par(new, code)
with_path(new, code, add = TRUE)
Arguments
new
code
action
add
with_something
Deprecation
with_env will be deprecated in devtools 1.2 and removed in devtools 1.3
Examples
getwd()
in_dir(tempdir(), getwd())
getwd()
Sys.getenv("HADLEY")
with_envvar(c("HADLEY" = 2), Sys.getenv("HADLEY"))
Sys.getenv("HADLEY")
with_envvar(c("A" = 1),
with_envvar(c("A" = 2), action = "suffix", Sys.getenv("A"))
)
55
Index
create, 11
create_description, 12, 32
Topic programming
build_vignettes, 5
load_all, 32
load_code, 33
load_data, 34
load_dll, 34
run_examples, 42
.libPaths, 15, 22
?, 19
? (help), 18
dev_example, 13, 42
dev_help, 14
dev_mode, 13, 15
dev_package_deps (package_deps), 35
devtools, 13
devtools-package (devtools), 13
document, 15
dr_devtools, 16, 16
dr_github, 16, 16
eval_clean, 17
evalq_clean (eval_clean), 17
GET, 30
get_path (path), 36
getURL, 45
github_pull, 17, 26, 27
github_release (github_pull), 17
has_devel, 18, 30
help, 18, 19
bash, 3
browser, 42
build, 3, 6, 7, 23
build_github_devtools, 4
build_vignettes, 5
build_win, 4, 6
in_dir (with_something), 54
infrastructure, 20, 5052
inst, 22
install, 13, 22, 2431
install.packages, 23, 25, 41
install_bitbucket, 24, 24, 2631
install_deps, 25
install_git, 24, 25, 2631
install_github, 5, 17, 18, 24, 26, 26, 2831
install_gitorious, 24, 26, 27, 27, 2931
install_local, 28
install_svn, 24, 2628, 29, 30, 31
install_url, 24, 2629, 30, 31
install_version, 24, 2630, 30
check, 6, 11
check_cran, 40
check_doc, 8
clean_dll, 8, 11, 32
clean_source, 9
clean_vignettes, 5, 9
clear_cache, 32
compile_dll, 9, 10, 10, 32
compiler_flags, 7, 10, 11, 53
INDEX
lint, 31, 32
lint_package, 31, 32
load_all, 18, 32, 46
load_code, 32, 33
load_data, 32, 34
load_dll, 34
missing_s3, 35
on_path, 36
options, 13
package.skeleton, 11
package_deps, 35, 49
path, 36
r_env_vars, 7
RCMD, 37
release, 8, 37
reload, 23, 38
revdep, 39
revdep_check, 3941
revdep_check (revdep_check_save_logs),
40
revdep_check_save_logs, 40
revdep_check_save_summary
(revdep_check_save_logs), 40
revdep_check_summary
(revdep_check_save_logs), 40
revdep_maintainers, 41
revdep_maintainers (revdep), 39
roxygenize, 15, 16
run_examples, 13, 42
save, 50
session_info, 43
sessionInfo, 43
set_path (path), 36
setup (create), 11
shim_help (help), 18
shim_question (help), 18
shim_system.file (system.file), 46
show_news, 43
source, 44, 45
source_gist, 44
source_url, 44, 45
system, 47
system.file, 46, 46
system_check, 37, 46
57
test, 20, 47
test_check, 47
test_dir, 47
textConnection, 45
unload, 32, 38, 48
update.package_deps (package_deps), 35
update_packages, 48
url, 31
use_appveyor, 5052
use_appveyor (infrastructure), 20
use_build_ignore, 22, 5052
use_code_of_conduct, 5052
use_code_of_conduct (infrastructure), 20
use_coveralls, 5052
use_coveralls (infrastructure), 20
use_cran_badge, 5052
use_cran_badge (infrastructure), 20
use_cran_comments, 5052
use_cran_comments (infrastructure), 20
use_data, 22, 49, 51, 52
use_data_raw, 22, 50, 50, 52
use_git, 51
use_git_hook, 51
use_github, 51
use_package, 22, 50, 51, 51
use_package_doc, 5052
use_package_doc (infrastructure), 20
use_rcpp, 5052
use_rcpp (infrastructure), 20
use_readme_rmd, 22, 5052
use_revdep, 5052
use_revdep (infrastructure), 20
use_rstudio, 11, 5052
use_rstudio (infrastructure), 20
use_test, 5052
use_test (infrastructure), 20
use_testthat, 5052
use_testthat (infrastructure), 20
use_travis, 5052
use_travis (infrastructure), 20
use_vignette, 5052
use_vignette (infrastructure), 20
wd, 52
with_collate (with_something), 54
with_debug, 10, 24, 53
with_env (with_something), 54
with_envvar (with_something), 54
58
with_lib (with_something), 54
with_libpaths, 23
with_libpaths (with_something), 54
with_locale (with_something), 54
with_options (with_something), 54
with_par (with_something), 54
with_path, 36, 54
with_path (with_something), 54
with_something, 54
INDEX