diff --git a/DESCRIPTION b/DESCRIPTION
index ba107109c..9b9496700 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -24,7 +24,7 @@ Imports:
memoise (>= 1.0.0),
whisker,
digest,
- rstudioapi (>= 0.2.0),
+ rstudioapi (>= 0.6.0.9000),
jsonlite,
stats,
git2r (>= 0.12.1),
@@ -58,7 +58,8 @@ Remotes:
mangothecat/callr,
r-lib/sessioninfo,
r-lib/usethis,
- r-hub/rhub
+ r-hub/rhub,
+ rstudio/rstudioapi
License: GPL (>= 2)
VignetteBuilder: knitr
RoxygenNote: 6.0.1
diff --git a/NAMESPACE b/NAMESPACE
index 73f0def71..8e2656235 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -163,12 +163,10 @@ export(uses_testthat)
export(wd)
export(with_debug)
importFrom(memoise,memoise)
-importFrom(pkgbuild,build)
importFrom(pkgbuild,clean_dll)
importFrom(pkgbuild,with_debug)
importFrom(pkgload,check_dep_version)
importFrom(pkgload,check_suggested)
-importFrom(pkgload,load_all)
importFrom(pkgload,parse_deps)
importFrom(pkgload,unload)
importFrom(stats,update)
diff --git a/NEWS.md b/NEWS.md
index 1f38b2bb2..e5ba29351 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,8 @@
# devtools 1.13.3.9000
+* `document()`, `load_all()`, `check()`, `build()` and `test()` now
+ automatically save open files when they are run inside the RStudio IDE. (#1576)
+
* New `rhub_check()` function to check packages using .
* `run_examples` was mistakenly passing `show` to
diff --git a/R/check.r b/R/check.r
index 347210da5..4f0ce6a6f 100644
--- a/R/check.r
+++ b/R/check.r
@@ -62,6 +62,10 @@ check <- function(pkg = ".",
quiet = FALSE) {
pkg <- as.package(pkg)
+ if (rstudioapi::isAvailable()) {
+ rstudioapi::documentSaveAll()
+ }
+
# document only if package uses roxygen, i.e. has RoxygenNote field
if (identical(document, NA)) {
document <- !is.null(pkg$roxygennote)
diff --git a/R/document.r b/R/document.r
index 8305599f9..bf97b4b73 100644
--- a/R/document.r
+++ b/R/document.r
@@ -24,6 +24,10 @@ document <- function(pkg = ".", clean = NULL, roclets = NULL, reload = TRUE) {
pkg <- as.package(pkg)
message("Updating ", pkg$package, " documentation")
+ if (rstudioapi::isAvailable()) {
+ rstudioapi::documentSaveAll()
+ }
+
load_all(pkg$path)
if (packageVersion("roxygen2") > "4.1.1") {
diff --git a/R/pkgbuild.R b/R/pkgbuild.R
index 5f3dc8fca..d51377752 100644
--- a/R/pkgbuild.R
+++ b/R/pkgbuild.R
@@ -1,6 +1,14 @@
-#' @importFrom pkgbuild build
+#' @inherit pkgbuild::build
+#' @param ... Additional arguments passed to [pkgbuild::build].
#' @export
-pkgbuild::build
+build <- function(path = ".", dest_path = NULL, binary = FALSE, vignettes = TRUE,
+ manual = FALSE, args = NULL, quiet = FALSE, ...) {
+ if (rstudioapi::isAvailable()) {
+ rstudioapi::documentSaveAll()
+ }
+ pkgbuild::build(path = path, dest_path = dest_path, binary = binary,
+ vignettes = vignettes, manual = manual, args = args, quiet = quiet, ...)
+}
#' @importFrom pkgbuild with_debug
#' @export
diff --git a/R/pkgload.R b/R/pkgload.R
index f8fd9f6dd..604575fd1 100644
--- a/R/pkgload.R
+++ b/R/pkgload.R
@@ -1,6 +1,17 @@
-#' @importFrom pkgload load_all
+#' @inherit pkgload::load_all
+#' @param ... Additional arguments passed to [pkgload::load].
#' @export
-pkgload::load_all
+load_all <- function(path = ".", reset = TRUE, recompile = FALSE,
+ export_all = TRUE, helpers = TRUE, recollate = FALSE,
+ quiet = FALSE, ...) {
+ if (rstudioapi::isAvailable()) {
+ rstudioapi::documentSaveAll()
+ }
+
+ pkgload::load_all(path = path, reset = reset, recompile = recompile,
+ export_all = export_all, helpers = helpers, recollate = recollate,
+ quiet = quiet, ...)
+}
#' @importFrom pkgload unload
#' @export
diff --git a/R/test.r b/R/test.r
index 0c2e02e3f..cb7028b28 100644
--- a/R/test.r
+++ b/R/test.r
@@ -19,6 +19,11 @@
#' @export
test <- function(pkg = ".", filter = NULL, ...) {
check_suggested("testthat")
+
+ if (rstudioapi::isAvailable()) {
+ rstudioapi::documentSaveAll()
+ }
+
pkg <- as.package(pkg)
if (!uses_testthat(pkg) && interactive()) {
diff --git a/man/build.Rd b/man/build.Rd
new file mode 100644
index 000000000..24c3c9440
--- /dev/null
+++ b/man/build.Rd
@@ -0,0 +1,46 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/pkgbuild.R
+\name{build}
+\alias{build}
+\title{Build package}
+\usage{
+build(path = ".", dest_path = NULL, binary = FALSE, vignettes = TRUE,
+ manual = FALSE, args = NULL, quiet = FALSE, ...)
+}
+\arguments{
+\item{path}{Path to a package, or within a package.}
+
+\item{dest_path}{path in which to produce package. If \code{NULL}, defaults to
+the parent directory of the package.}
+
+\item{binary}{Produce a binary (\code{--binary}) or source (
+\code{--no-manual --no-resave-data}) version of the package.}
+
+\item{vignettes}{For source packages: if \code{FALSE}, don't build PDF
+vignettes (\code{--no-build-vignettes}) or manual (\code{--no-manual}).}
+
+\item{manual}{For source packages: if \code{FALSE}, don't build PDF
+vignettes (\code{--no-build-vignettes}) or manual (\code{--no-manual}).}
+
+\item{args}{An optional character vector of additional command
+line arguments to be passed to \code{R CMD build} if \code{binary = FALSE},
+or \code{R CMD install} if \code{binary = TRUE}.}
+
+\item{quiet}{if \code{TRUE} suppresses output from this function.}
+
+\item{...}{Additional arguments passed to [pkgbuild::build].}
+}
+\value{
+a string giving the location (including file name) of the built
+package
+}
+\description{
+Building converts a package source directory into a single bundled file.
+If \code{binary = FALSE} this creates a \code{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 \code{binary = TRUE}, the package will have
+a platform specific extension (e.g. \code{.zip} for windows), and will
+only be installable on the current platform, but no development
+environment is needed.
+}
diff --git a/man/load_all.Rd b/man/load_all.Rd
new file mode 100644
index 000000000..dc4f20d22
--- /dev/null
+++ b/man/load_all.Rd
@@ -0,0 +1,100 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/pkgload.R
+\name{load_all}
+\alias{load_all}
+\title{Load complete package.}
+\usage{
+load_all(path = ".", reset = TRUE, recompile = FALSE, export_all = TRUE,
+ helpers = TRUE, recollate = FALSE, quiet = FALSE, ...)
+}
+\arguments{
+\item{path}{Path to a package, or within a package.}
+
+\item{reset}{clear package environment and reset file cache before loading
+any pieces of the package. This is equivalent to running
+\code{\link[=unload]{unload()}} and is the default. Use \code{reset = FALSE} may be
+faster for large code bases, but is a significantly less accurate
+approximation.}
+
+\item{recompile}{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{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{helpers}{if \code{TRUE} loads \pkg{testthat} test helpers.}
+
+\item{recollate}{if \code{TRUE}, run \code{\link[roxygen2:update_collate]{roxygen2::update_collate()}} before loading.}
+
+\item{quiet}{if \code{TRUE} suppresses output from this function.}
+
+\item{...}{Additional arguments passed to [pkgload::load].}
+}
+\description{
+\code{load_all} loads a package. It roughly simulates what happens
+when a package is installed and loaded with \code{\link[=library]{library()}}.
+}
+\details{
+Currently \code{load_all}:
+
+\itemize{
+\item Loads all data files in \code{data/}. See \code{\link[=load_data]{load_data()}}
+for more details.
+
+\item Sources all R files in the R directory, storing results in
+environment that behaves like a regular package namespace. See
+below and \code{\link[=load_code]{load_code()}} for more details.
+
+\item Compiles any C, C++, or Fortran code in the \code{src/} directory
+and connects the generated DLL into R. See \code{\link[=compile_dll]{compile_dll()}}
+for more details.
+
+\item Runs \code{.onAttach()}, \code{.onLoad()} and \code{.onUnload()}
+functions at the correct times.
+
+\item If you use \pkg{testthat}, will load all test helpers so
+you can access them interactively. Devtools sets the
+\code{DEVTOOLS_LOAD} environment variable to \code{"true"} to
+let you check whether the helpers are run during package loading.
+
+}
+}
+\section{Namespaces}{
+
+
+The namespace environment \code{}, is a child of
+the imports environment, which has the name attribute
+\code{imports:pkgname}. It is in turn is a child of
+\code{}, which is a child of the global environment.
+(There is also a copy of the base namespace that is a child of the empty
+environment.)
+
+The package environment \code{} is an ancestor of the
+global environment. Normally when loading a package, the objects
+listed as exports in the NAMESPACE file are copied from the namespace
+to the package environment. However, \code{load_all} by default will
+copy all objects (not just the ones listed as exports) to the package
+environment. This is useful during development because it makes all
+objects easy to access.
+
+To export only the objects listed as exports, use
+\code{export_all=FALSE}. This more closely simulates behavior when
+loading an installed package with \code{\link[=library]{library()}}, and can be
+useful for checking for missing exports.
+
+}
+
+\section{Shim files}{
+
+
+\code{load_all} also inserts shim functions into the imports environment
+of the laded 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}.
+
+}
+
diff --git a/man/reexports.Rd b/man/reexports.Rd
index df491492a..5bd7d33a4 100644
--- a/man/reexports.Rd
+++ b/man/reexports.Rd
@@ -7,14 +7,10 @@
\alias{reexports}
\alias{check_dep_version}
\alias{reexports}
-\alias{build}
-\alias{reexports}
\alias{with_debug}
\alias{reexports}
\alias{clean_dll}
\alias{reexports}
-\alias{load_all}
-\alias{reexports}
\alias{unload}
\alias{reexports}
\alias{check_suggested}
@@ -25,8 +21,8 @@ These objects are imported from other packages. Follow the links
below to see their documentation.
\describe{
- \item{pkgbuild}{\code{\link[pkgbuild]{build}}, \code{\link[pkgbuild]{with_debug}}, \code{\link[pkgbuild]{clean_dll}}}
+ \item{pkgbuild}{\code{\link[pkgbuild]{with_debug}}, \code{\link[pkgbuild]{clean_dll}}}
- \item{pkgload}{\code{\link[pkgload]{parse_deps}}, \code{\link[pkgload]{check_dep_version}}, \code{\link[pkgload]{load_all}}, \code{\link[pkgload]{unload}}, \code{\link[pkgload]{check_suggested}}}
+ \item{pkgload}{\code{\link[pkgload]{parse_deps}}, \code{\link[pkgload]{check_dep_version}}, \code{\link[pkgload]{unload}}, \code{\link[pkgload]{check_suggested}}}
}}