Skip to content

Commit

Permalink
Save open files in the IDE for command functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jimhester committed Aug 17, 2017
1 parent 89d8597 commit 5517fdb
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 14 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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 <https://builder.r-hub.io/>.

* `run_examples` was mistakenly passing `show` to
Expand Down
4 changes: 4 additions & 0 deletions R/check.r
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions R/document.r
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
12 changes: 10 additions & 2 deletions R/pkgbuild.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 13 additions & 2 deletions R/pkgload.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions R/test.r
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
46 changes: 46 additions & 0 deletions man/build.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 100 additions & 0 deletions man/load_all.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions man/reexports.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5517fdb

Please # to comment.