Skip to content

Commit 54bf436

Browse files
authored
use_air() (#2633)
1 parent 8943b48 commit 54bf436

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+643
-256
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
^\.lintr\.R$
2222
^notes$
2323
^CRAN-SUBMISSION$
24+
^[.]?air[.]toml$
25+
^\.vscode$

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"Posit.air-vscode"
4+
]
5+
}

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"[r]": {
3+
"editor.formatOnSave": true,
4+
"editor.defaultFormatter": "Posit.air-vscode"
5+
},
6+
"[quarto]": {
7+
"editor.formatOnSave": true,
8+
"editor.defaultFormatter": "quarto.quarto"
9+
}
10+
}

R/active.R

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
find_active_file <- function(arg = "file", call = parent.frame()) {
22
if (!is_rstudio_running()) {
3-
cli::cli_abort("Argument {.arg {arg}} is missing, with no default", call = call)
3+
cli::cli_abort(
4+
"Argument {.arg {arg}} is missing, with no default",
5+
call = call
6+
)
47
}
58
normalizePath(rstudioapi::getSourceEditorContext()$path)
69
}
@@ -18,7 +21,12 @@ find_test_file <- function(path, call = parent.frame()) {
1821
pkg <- as.package(dirname(path))
1922

2023
is_test <- type == "test"
21-
path[!is_test] <- paste0(pkg$path, "/tests/testthat/test-", name_source(path[!is_test]), ".R")
24+
path[!is_test] <- paste0(
25+
pkg$path,
26+
"/tests/testthat/test-",
27+
name_source(path[!is_test]),
28+
".R"
29+
)
2230
path <- unique(path[file_exists(path)])
2331

2432
if (length(path) == 0) {

R/build-manual.R

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@ build_manual <- function(pkg = ".", path = NULL) {
1010
pkg <- as.package(pkg)
1111
path <- path %||% path_dir(pkg$path)
1212
name <- paste0(pkg$package, "_", pkg$version, ".pdf", collapse = " ")
13-
tryCatch(msg <- callr::rcmd("Rd2pdf", cmdargs = c(
14-
"--force",
15-
paste0("--output=", path, "/", name),
16-
pkg$path
17-
), fail_on_status = TRUE, stderr = "2>&1", spinner = FALSE),
18-
error = function(e) {
19-
cat(e$stdout)
20-
cli::cli_abort("Failed to build manual")
21-
})
13+
tryCatch(
14+
msg <- callr::rcmd(
15+
"Rd2pdf",
16+
cmdargs = c(
17+
"--force",
18+
paste0("--output=", path, "/", name),
19+
pkg$path
20+
),
21+
fail_on_status = TRUE,
22+
stderr = "2>&1",
23+
spinner = FALSE
24+
),
25+
error = function(e) {
26+
cat(e$stdout)
27+
cli::cli_abort("Failed to build manual")
28+
}
29+
)
2230

2331
cat(msg$stdout)
2432
invisible(msg)

R/build-readme.R

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
#' @inheritParams install
1212
#' @inheritParams rmarkdown::render
1313
#' @export
14-
build_rmd <- function(files, path = ".", output_options = list(), ..., quiet = TRUE) {
14+
build_rmd <- function(
15+
files,
16+
path = ".",
17+
output_options = list(),
18+
...,
19+
quiet = TRUE
20+
) {
1521
check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn))
1622

1723
pkg <- as.package(path)
@@ -33,12 +39,16 @@ build_rmd <- function(files, path = ".", output_options = list(), ..., quiet = T
3339
# Ensure rendering github_document() doesn't generate HTML file
3440
output_options$html_preview <- FALSE
3541

36-
3742
for (path in paths) {
3843
cli::cli_inform(c(i = "Building {.path {path}}"))
3944
callr::r_safe(
4045
function(...) rmarkdown::render(...),
41-
args = list(input = path, ..., output_options = output_options, quiet = quiet),
46+
args = list(
47+
input = path,
48+
...,
49+
output_options = output_options,
50+
quiet = quiet
51+
),
4252
show = TRUE,
4353
spinner = FALSE,
4454
stderr = "2>&1"
@@ -54,13 +64,21 @@ build_readme <- function(path = ".", quiet = TRUE, ...) {
5464
pkg <- as.package(path)
5565

5666
regexp <- paste0(path_file(pkg$path), "/(inst/)?readme[.]rmd")
57-
readme_path <- path_abs(dir_ls(pkg$path, ignore.case = TRUE, regexp = regexp, recurse = 1, type = "file"))
67+
readme_path <- path_abs(dir_ls(
68+
pkg$path,
69+
ignore.case = TRUE,
70+
regexp = regexp,
71+
recurse = 1,
72+
type = "file"
73+
))
5874

5975
if (length(readme_path) == 0) {
6076
cli::cli_abort("Can't find {.file README.Rmd} or {.file inst/README.Rmd}.")
6177
}
6278
if (length(readme_path) > 1) {
63-
cli::cli_abort("Can't have both {.file README.Rmd} and {.file inst/README.Rmd}.")
79+
cli::cli_abort(
80+
"Can't have both {.file README.Rmd} and {.file inst/README.Rmd}."
81+
)
6482
}
6583

6684
build_rmd(readme_path, path = path, quiet = quiet, ...)

R/check-devtools.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ check_version <- function(pkg = ".") {
5959
check_vignette_titles <- function(pkg = ".") {
6060
pkg <- as.package(pkg)
6161
vigns <- tools::pkgVignettes(dir = pkg$path)
62-
if (length(vigns$docs) == 0) return()
62+
if (length(vigns$docs) == 0) {
63+
return()
64+
}
6365

6466
has_vignette_title <- function(v, n) {
6567
h <- readLines(v, n = n)

R/check-mac.R

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111
#' @family build functions
1212
#' @return The url with the check results (invisibly)
1313
#' @export
14-
check_mac_release <- function(pkg = ".", dep_pkgs = character(), args = NULL, manual = TRUE, quiet = FALSE, ...) {
14+
check_mac_release <- function(
15+
pkg = ".",
16+
dep_pkgs = character(),
17+
args = NULL,
18+
manual = TRUE,
19+
quiet = FALSE,
20+
...
21+
) {
1522
check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn))
1623

1724
pkg <- as.package(pkg)
@@ -23,17 +30,25 @@ check_mac_release <- function(pkg = ".", dep_pkgs = character(), args = NULL, ma
2330
))
2431
}
2532

26-
built_path <- pkgbuild::build(pkg$path, tempdir(),
33+
built_path <- pkgbuild::build(
34+
pkg$path,
35+
tempdir(),
2736
args = args,
28-
manual = manual, quiet = quiet, ...
37+
manual = manual,
38+
quiet = quiet,
39+
...
2940
)
3041

3142
dep_built_paths <- character()
3243
for (i in seq_along(dep_pkgs)) {
3344
dep_pkg <- as.package(dep_pkgs[[i]])$path
34-
dep_built_paths[[i]] <- pkgbuild::build(dep_pkg, tempdir(),
45+
dep_built_paths[[i]] <- pkgbuild::build(
46+
dep_pkg,
47+
tempdir(),
3548
args = args,
36-
manual = manual, quiet = quiet, ...
49+
manual = manual,
50+
quiet = quiet,
51+
...
3752
)
3853
}
3954
on.exit(file_delete(c(built_path, dep_built_paths)), add = TRUE)
@@ -49,7 +64,8 @@ check_mac_release <- function(pkg = ".", dep_pkgs = character(), args = NULL, ma
4964
body <- append(body, uploads)
5065
}
5166

52-
res <- httr::POST(url,
67+
res <- httr::POST(
68+
url,
5369
body = body,
5470
headers = list(
5571
"Content-Type" = "multipart/form-data"

R/check-win.R

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,82 @@ NULL
2020

2121
#' @describeIn check_win Check package on the development version of R.
2222
#' @export
23-
check_win_devel <- function(pkg = ".", args = NULL, manual = TRUE, email = NULL, quiet = FALSE, ...) {
23+
check_win_devel <- function(
24+
pkg = ".",
25+
args = NULL,
26+
manual = TRUE,
27+
email = NULL,
28+
quiet = FALSE,
29+
...
30+
) {
2431
check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn))
2532

2633
check_win(
27-
pkg = pkg, version = "R-devel", args = args, manual = manual,
28-
email = email, quiet = quiet, ...
34+
pkg = pkg,
35+
version = "R-devel",
36+
args = args,
37+
manual = manual,
38+
email = email,
39+
quiet = quiet,
40+
...
2941
)
3042
}
3143

3244
#' @describeIn check_win Check package on the released version of R.
3345
#' @export
34-
check_win_release <- function(pkg = ".", args = NULL, manual = TRUE, email = NULL, quiet = FALSE, ...) {
46+
check_win_release <- function(
47+
pkg = ".",
48+
args = NULL,
49+
manual = TRUE,
50+
email = NULL,
51+
quiet = FALSE,
52+
...
53+
) {
3554
check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn))
3655

3756
check_win(
38-
pkg = pkg, version = "R-release", args = args, manual = manual,
39-
email = email, quiet = quiet, ...
57+
pkg = pkg,
58+
version = "R-release",
59+
args = args,
60+
manual = manual,
61+
email = email,
62+
quiet = quiet,
63+
...
4064
)
4165
}
4266

4367
#' @describeIn check_win Check package on the previous major release version of R.
4468
#' @export
45-
check_win_oldrelease <- function(pkg = ".", args = NULL, manual = TRUE, email = NULL, quiet = FALSE, ...) {
69+
check_win_oldrelease <- function(
70+
pkg = ".",
71+
args = NULL,
72+
manual = TRUE,
73+
email = NULL,
74+
quiet = FALSE,
75+
...
76+
) {
4677
check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn))
4778

4879
check_win(
49-
pkg = pkg, version = "R-oldrelease", args = args, manual = manual,
50-
email = email, quiet = quiet, ...
80+
pkg = pkg,
81+
version = "R-oldrelease",
82+
args = args,
83+
manual = manual,
84+
email = email,
85+
quiet = quiet,
86+
...
5187
)
5288
}
5389

54-
check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelease"),
55-
args = NULL, manual = TRUE, email = NULL, quiet = FALSE, ...) {
90+
check_win <- function(
91+
pkg = ".",
92+
version = c("R-devel", "R-release", "R-oldrelease"),
93+
args = NULL,
94+
manual = TRUE,
95+
email = NULL,
96+
quiet = FALSE,
97+
...
98+
) {
5699
pkg <- as.package(pkg)
57100

58101
if (!is.null(email)) {
@@ -80,14 +123,20 @@ check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelea
80123
}
81124
}
82125

83-
built_path <- pkgbuild::build(pkg$path, tempdir(),
126+
built_path <- pkgbuild::build(
127+
pkg$path,
128+
tempdir(),
84129
args = args,
85-
manual = manual, quiet = quiet, ...
130+
manual = manual,
131+
quiet = quiet,
132+
...
86133
)
87134
on.exit(file_delete(built_path), add = TRUE)
88135

89136
url <- paste0(
90-
"ftp://win-builder.r-project.org/", version, "/",
137+
"ftp://win-builder.r-project.org/",
138+
version,
139+
"/",
91140
path_file(built_path)
92141
)
93142
lapply(url, upload_ftp, file = built_path)
@@ -142,8 +191,12 @@ upload_ftp <- function(file, url, verbose = FALSE) {
142191
con <- file(file, open = "rb")
143192
on.exit(close(con), add = TRUE)
144193
h <- curl::new_handle(upload = TRUE, filetime = FALSE)
145-
curl::handle_setopt(h, readfunction = function(n) {
146-
readBin(con, raw(), n = n)
147-
}, verbose = verbose)
194+
curl::handle_setopt(
195+
h,
196+
readfunction = function(n) {
197+
readBin(con, raw(), n = n)
198+
},
199+
verbose = verbose
200+
)
148201
curl::curl_fetch_memory(url, handle = h)
149202
}

0 commit comments

Comments
 (0)