Skip to content

Commit 0884290

Browse files
committed
Add quarto_args to quarto_render()
closes #125
1 parent 003dfb6 commit 0884290

File tree

14 files changed

+60
-11
lines changed

14 files changed

+60
-11
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: quarto
22
Title: R Interface to 'Quarto' Markdown Publishing System
3-
Version: 1.3.6
3+
Version: 1.3.7
44
Authors@R: c(
55
person("JJ", "Allaire", , "[email protected]", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-0174-9868")),

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# quarto (development version)
22

3+
- Add `quarto_args` to `quarto_render()` and other commands to pass additional arguments to `quarto` CLI commands. This is for advanced usage e.g. when new options are added to Quarto CLI that would not be user-facing in this package's functions (thanks, @gadenbuie, #125).
4+
35
- Add `quiet` argument to pass `--quiet` to `quarto` CLI commands
46

57
- Error message now advises to re-run with `quiet = FALSE` because `quarto_render(quiet = TRUE)` will run `quarto render` in quiet mode (thanks to @gadenbuie, #126, @wlandau, #16).

R/add.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#'
2020
#' @param no_prompt Do not prompt to confirm approval to download external extension.
2121
#'
22-
#' @param quarto_args Character vector of other `quarto` CLI flag pass to the command.
23-
#'
2422
#' @examples
2523
#' \dontrun{
2624
#' # Install a template and set up a draft document from a GitHub repository

R/inspect.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' and dependent resources.
66
#'
77
#' @inheritParams quarto_render
8-
#' @inheritParams quarto_add_extension
8+
#'
99
#' @param input The input file or project directory to inspect.
1010
#'
1111
#' @return Named list. For input files, the list contains the elements

R/render.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#' @param profile [Quarto project
4242
#' profile(s)](https://quarto.org/docs/projects/profiles.html) to use. Either
4343
#' a character vector of profile names or `NULL` to use the default profile.
44+
#' @param quarto_args Character vector of other `quarto` CLI flag pass to the
45+
#' command. This is mainly for advanced usage, e.g it can be useful for new
46+
#' options added to quarto CLI and not yet supported as function argument.
4447
#' @param pandoc_args Additional command line options to pass to pandoc.
4548
#' @param as_job Render as an RStudio background job. Default is "auto",
4649
#' which will render individual documents normally and projects as
@@ -82,6 +85,7 @@ quarto_render <- function(input = NULL,
8285
debug = FALSE,
8386
quiet = FALSE,
8487
profile = NULL,
88+
quarto_args = NULL,
8589
pandoc_args = NULL,
8690
as_job = getOption("quarto.render_as_job", "auto")) {
8791

@@ -176,6 +180,9 @@ quarto_render <- function(input = NULL,
176180
if (!is.null(profile)) {
177181
args <- cli_arg_profile(profile, args)
178182
}
183+
if (!is.null(quarto_args)) {
184+
args <- c(args, quarto_args)
185+
}
179186
if (!is.null(pandoc_args)) {
180187
args <- c(args, pandoc_args)
181188
}

R/use.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#'
33
#' Install and use a template for Quarto using `quarto use`.
44
#'
5+
#' @inheritParams quarto_render
56
#' @inheritParams quarto_add_extension
67
#'
78
#' @param template The template to install, either an archive or a GitHub

man/quarto_add_extension.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/quarto_inspect.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/quarto_render.Rd

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/quarto_use_template.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/render.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# quarto_args in quarto_render
2+
3+
Code
4+
quarto_render("input.qmd", quiet = TRUE, quarto_args = c("--to", "native"))
5+
Output
6+
Running \
7+
"<quarto full path>" \
8+
render input.qmd --quiet --to native
9+

tests/testthat/helper.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ expect_snapshot_qmd_output <- function(name, input, output_file = NULL, ...) {
5757
}
5858

5959

60-
transform_quarto_cli_in_output <- function(lines) {
61-
# it will be quarto.exe only on windows
62-
gsub("quarto\\.(exe|cmd)", "quarto", lines)
60+
transform_quarto_cli_in_output <- function(full_path = FALSE) {
61+
return(
62+
function(lines) {
63+
if (full_path) {
64+
gsub(find_quarto(), "<quarto full path>", lines, fixed = TRUE)
65+
} else {
66+
# it will be quarto.exe only on windows
67+
gsub("quarto\\.(exe|cmd)", "quarto", lines)
68+
}
69+
}
70+
)
6371
}

tests/testthat/test-quarto.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ test_that("quarto_run gives guidance in error", {
88
expect_snapshot(
99
error = TRUE,
1010
quarto_run(c("rend", "--quiet")),
11-
transform = transform_quarto_cli_in_output
11+
transform = transform_quarto_cli_in_output()
1212
)
1313
})

tests/testthat/test-render.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,16 @@ test_that("metadata-file and metadata are merged in quarto_render", {
4545
metadata_file = yaml, metadata = list(title = "test2")
4646
)
4747
})
48+
49+
test_that("quarto_args in quarto_render", {
50+
skip_if_no_quarto()
51+
qmd <- local_qmd_file(c("content"))
52+
withr::local_options(quarto.echo_cmd = TRUE)
53+
withr::local_dir(dirname(qmd))
54+
file.rename(basename(qmd), "input.qmd")
55+
# metadata
56+
expect_snapshot(
57+
quarto_render("input.qmd", quiet = TRUE, quarto_args = c("--to", "native")),
58+
transform = transform_quarto_cli_in_output(full_path = TRUE)
59+
)
60+
})

0 commit comments

Comments
 (0)