Skip to content

Commit 8531660

Browse files
committed
use_air() and run it to format package
1 parent 50c2791 commit 8531660

25 files changed

+369
-138
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
^cran-comments\.md$
1616
^codecov\.yml$
1717
^CRAN-SUBMISSION$
18+
^[\.]?air\.toml$

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
.Rproj.user
22
.Rhistory
33

4-
.vscode
5-
64
inst/doc
75
docs
86

.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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"[r]": {
3+
"editor.formatOnSave": true,
4+
"editor.defaultFormatter": "Posit.air-vscode"
5+
}
6+
}

R/add.R

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,30 @@
3131
#' @importFrom rlang is_interactive
3232
#' @importFrom cli cli_abort
3333
#' @export
34-
quarto_add_extension <- function(extension = NULL, no_prompt = FALSE, quiet = FALSE, quarto_args = NULL) {
34+
quarto_add_extension <- function(
35+
extension = NULL,
36+
no_prompt = FALSE,
37+
quiet = FALSE,
38+
quarto_args = NULL
39+
) {
3540
rlang::check_required(extension)
3641

3742
quarto_bin <- find_quarto()
3843

3944
# This will ask for approval or stop installation
40-
approval <- check_extension_approval(no_prompt, "Quarto extensions", "https://quarto.org/docs/extensions/managing.html")
45+
approval <- check_extension_approval(
46+
no_prompt,
47+
"Quarto extensions",
48+
"https://quarto.org/docs/extensions/managing.html"
49+
)
4150

4251
if (approval) {
43-
args <- c(extension, "--no-prompt", if (is_quiet(quiet)) cli_arg_quiet(), quarto_args)
52+
args <- c(
53+
extension,
54+
"--no-prompt",
55+
if (is_quiet(quiet)) cli_arg_quiet(),
56+
quarto_args
57+
)
4458
quarto_add(args, quarto_bin = quarto_bin, echo = TRUE)
4559
}
4660

R/create.R

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,19 @@
2020
#' @inheritParams quarto_add_extension
2121
#'
2222
#' @export
23-
quarto_create_project <- function(name, type = "default", dir = ".", no_prompt = FALSE, quiet = FALSE, quarto_args = NULL) {
24-
check_quarto_version("1.4", "quarto create project", "https://quarto.org/docs/projects/quarto-projects.html")
23+
quarto_create_project <- function(
24+
name,
25+
type = "default",
26+
dir = ".",
27+
no_prompt = FALSE,
28+
quiet = FALSE,
29+
quarto_args = NULL
30+
) {
31+
check_quarto_version(
32+
"1.4",
33+
"quarto create project",
34+
"https://quarto.org/docs/projects/quarto-projects.html"
35+
)
2536

2637
if (rlang::is_missing(name)) {
2738
cli::cli_abort("You need to provide {.arg name} for the new project.")
@@ -39,7 +50,15 @@ quarto_create_project <- function(name, type = "default", dir = ".", no_prompt =
3950

4051
quarto_bin <- find_quarto()
4152

42-
args <- c("project", type, name, "--no-prompt", "--no-open", if (is_quiet(quiet)) cli_arg_quiet(), quarto_args = NULL)
53+
args <- c(
54+
"project",
55+
type,
56+
name,
57+
"--no-prompt",
58+
"--no-open",
59+
if (is_quiet(quiet)) cli_arg_quiet(),
60+
quarto_args = NULL
61+
)
4362

4463
owd <- setwd(dir)
4564
on.exit(setwd(owd), add = TRUE, after = FALSE)

R/daemon.R

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
run_serve_daemon <- function(command, target, wd, extra_args, render, port, host, browse) {
1+
run_serve_daemon <- function(
2+
command,
3+
target,
4+
wd,
5+
extra_args,
6+
render,
7+
port,
8+
host,
9+
browse
10+
) {
211
# resolve target if provided
312
if (!is.null(target)) {
413
target <- path.expand(target)
@@ -91,8 +100,6 @@ run_serve_daemon <- function(command, target, wd, extra_args, render, port, host
91100
}
92101
quarto[[port_key]] <- port
93102

94-
95-
96103
# monitor the process for abnormal exit
97104
poll_process <- function() {
98105
if (is.null(quarto[[ps_key]])) {
@@ -101,7 +108,11 @@ run_serve_daemon <- function(command, target, wd, extra_args, render, port, host
101108
ro <- quarto[[ps_key]]$read_output()
102109
cat(ro)
103110
# Look at url to browse too in `quarto preview log`
104-
if (!isFALSE(browse) && is.null(quarto[[url_key]]) && grepl("Browse at https?://", ro)) {
111+
if (
112+
!isFALSE(browse) &&
113+
is.null(quarto[[url_key]]) &&
114+
grepl("Browse at https?://", ro)
115+
) {
105116
m <- regexec("Browse at (https?://[^ ]+)\n", ro)
106117
quarto[[url_key]] <- regmatches(ro, m)[[1]][2]
107118
}
@@ -117,14 +128,14 @@ run_serve_daemon <- function(command, target, wd, extra_args, render, port, host
117128
}
118129
poll_process()
119130

120-
121131
# indicate server is running
122132
cat(paste0("Stop the preview with quarto_", command, "_stop()"))
123133

124134
# run the preview browser
125135
if (!isFALSE(browse)) {
126136
if (!is.function(browse)) {
127-
browse <- ifelse(rstudioapi::isAvailable(),
137+
browse <- ifelse(
138+
rstudioapi::isAvailable(),
128139
rstudioapi::viewer,
129140
utils::browseURL
130141
)

R/inspect.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
#' }
3030
#' @importFrom jsonlite fromJSON
3131
#' @export
32-
quarto_inspect <- function(input = ".",
33-
profile = NULL,
34-
quiet = FALSE,
35-
quarto_args = NULL) {
32+
quarto_inspect <- function(
33+
input = ".",
34+
profile = NULL,
35+
quiet = FALSE,
36+
quarto_args = NULL
37+
) {
3638
quarto_bin <- find_quarto()
3739

3840
args <- c("inspect", path.expand(input))

R/preview.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@
4545
#' }
4646
#'
4747
#' @export
48-
quarto_preview <- function(file = NULL,
49-
render = "auto",
50-
port = "auto",
51-
host = "127.0.0.1",
52-
browse = TRUE,
53-
watch = TRUE,
54-
navigate = TRUE) {
48+
quarto_preview <- function(
49+
file = NULL,
50+
render = "auto",
51+
port = "auto",
52+
host = "127.0.0.1",
53+
browse = TRUE,
54+
watch = TRUE,
55+
navigate = TRUE
56+
) {
5557
# default for file
5658
if (is.null(file)) {
5759
file <- getwd()

R/publish.R

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@
2525
#' }
2626
#'
2727
#' @export
28-
quarto_publish_doc <- function(input,
29-
name = NULL,
30-
title = NULL,
31-
server = NULL,
32-
account = NULL,
33-
render = c("local", "server", "none"),
34-
metadata = list(),
35-
...) {
28+
quarto_publish_doc <- function(
29+
input,
30+
name = NULL,
31+
title = NULL,
32+
server = NULL,
33+
account = NULL,
34+
render = c("local", "server", "none"),
35+
metadata = list(),
36+
...
37+
) {
3638
validate_rsconnect()
3739
# resolve render
3840
render <- match.arg(render)
@@ -51,7 +53,8 @@ quarto_publish_doc <- function(input,
5153
# render if requested (always render self-contained locally for rpubs)
5254
if (!is.null(rpubs_destination)) {
5355
render <- "local"
54-
quarto_render(input,
56+
quarto_render(
57+
input,
5558
output_format = format,
5659
pandoc_args = "--self-contained"
5760
)
@@ -139,14 +142,16 @@ quarto_publish_doc <- function(input,
139142

140143
#' @rdname quarto_publish_doc
141144
#' @export
142-
quarto_publish_app <- function(input = getwd(),
143-
name = NULL,
144-
title = NULL,
145-
server = NULL,
146-
account = NULL,
147-
render = c("local", "server", "none"),
148-
metadata = list(),
149-
...) {
145+
quarto_publish_app <- function(
146+
input = getwd(),
147+
name = NULL,
148+
title = NULL,
149+
server = NULL,
150+
account = NULL,
151+
render = c("local", "server", "none"),
152+
metadata = list(),
153+
...
154+
) {
150155
validate_rsconnect()
151156

152157
# resolve render
@@ -194,14 +199,16 @@ quarto_publish_app <- function(input = getwd(),
194199

195200
#' @rdname quarto_publish_doc
196201
#' @export
197-
quarto_publish_site <- function(input = getwd(),
198-
name = NULL,
199-
title = NULL,
200-
server = NULL,
201-
account = NULL,
202-
render = c("local", "server", "none"),
203-
metadata = list(),
204-
...) {
202+
quarto_publish_site <- function(
203+
input = getwd(),
204+
name = NULL,
205+
title = NULL,
206+
server = NULL,
207+
account = NULL,
208+
render = c("local", "server", "none"),
209+
metadata = list(),
210+
...
211+
) {
205212
validate_rsconnect()
206213

207214
# resolve render
@@ -257,8 +264,12 @@ quarto_publish_site <- function(input = getwd(),
257264

258265
find_app_primary_doc <- function(dir) {
259266
preferred <- c(
260-
"index.Rmd", "index.rmd", "index.qmd",
261-
"ui.Rmd", "ui.rmd", "ui.qmd"
267+
"index.Rmd",
268+
"index.rmd",
269+
"index.qmd",
270+
"ui.Rmd",
271+
"ui.rmd",
272+
"ui.qmd"
262273
)
263274
preferred <- preferred[file.exists(file.path(dir, preferred))]
264275
if (length(preferred) > 0) {
@@ -283,7 +294,9 @@ find_app_primary_doc <- function(dir) {
283294
}
284295

285296
is_shiny_prerendered <- function(runtime, server = NULL) {
286-
if (identical(runtime, "shinyrmd") || identical(runtime, "shiny_prerendered")) {
297+
if (
298+
identical(runtime, "shinyrmd") || identical(runtime, "shiny_prerendered")
299+
) {
287300
TRUE
288301
} else if (identical(server, "shiny")) {
289302
TRUE
@@ -365,7 +378,10 @@ resolve_destination <- function(server, account, allowShinyapps) {
365378
# create server if we need to
366379
servers <- rsconnect::servers()
367380
if (nrow(subset(servers, servers$name == server)) == 0) {
368-
rsconnect::addServer(sprintf("%s/__api__", server_with_protocol), server)
381+
rsconnect::addServer(
382+
sprintf("%s/__api__", server_with_protocol),
383+
server
384+
)
369385
}
370386

371387
# connect user
@@ -374,7 +390,8 @@ resolve_destination <- function(server, account, allowShinyapps) {
374390
account <- accounts$name
375391
} else {
376392
stop(
377-
"There is more than one account registered for ", server,
393+
"There is more than one account registered for ",
394+
server,
378395
"\nPlease specify which account you want to publish to."
379396
)
380397
}
@@ -387,7 +404,9 @@ resolve_destination <- function(server, account, allowShinyapps) {
387404
}
388405

389406

390-
validate_rsconnect <- function(reason = "for publishing using quarto R package.") {
407+
validate_rsconnect <- function(
408+
reason = "for publishing using quarto R package."
409+
) {
391410
rlang::check_installed("rsconnect", version = "0.8.26", reason = reason)
392411
}
393412

0 commit comments

Comments
 (0)