Skip to content

Commit 2fd494e

Browse files
salim-bcderv
andauthored
Add param profile to quarto_inspect() and quarto_render() (#123)
Co-authored-by: Christophe Dervieux <[email protected]>
1 parent 03b8658 commit 2fd494e

File tree

13 files changed

+164
-21
lines changed

13 files changed

+164
-21
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.2
3+
Version: 1.3.3
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 `profile` arguments to `quarto_render()` and `quarto_inspect()` (thanks, #95, @andrewheiss, #123, @salim-b).
4+
35
* Add `metadata` and `metadata_file` to `quarto_render()` to pass modify Quarto metadata from calling render. If both are set, `metadata` will be merged over `metadata_file` content. Internally, metadata will be passed as a `--metadata-file` to `quarto render` (thanks, @mcanouil, #52, @maelle, #49).
46

57
* Added a `NEWS.md` file to track changes to the package.

R/inspect.R

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
#' config and engines. Inspecting an input path return its formats, engine,
55
#' and dependent resources.
66
#'
7+
#' @inheritParams quarto_render
78
#' @param input The input file or project directory to inspect.
89
#'
9-
#' @return Named list. For input files, the list has members engine, format,
10-
#' and resources. For projects the list has members engines and config
11-
#'
12-
#' @importFrom jsonlite fromJSON
10+
#' @return Named list. For input files, the list contains the elements
11+
#' `quarto`, `engines`, `formats`, `resources`, plus `project` if the file is
12+
#' part of a Quarto project. For projects, the list contains the elements
13+
#' `quarto`, `dir`, `engines`, `config` and `files`.
1314
#'
1415
#' @examples
1516
#' \dontrun{
@@ -18,18 +19,26 @@
1819
#'
1920
#' # Inspect project
2021
#' quarto_inspect("myproject")
21-
#' }
2222
#'
23+
#' # Inspect project's advanced profile
24+
#' quarto_inspect(
25+
#' input = "myproject",
26+
#' profile = "advanced"
27+
#' )}
28+
#' @importFrom jsonlite fromJSON
2329
#' @export
24-
quarto_inspect <- function(input = ".") {
30+
quarto_inspect <- function(input = ".",
31+
profile = NULL) {
2532

2633
quarto_bin <- find_quarto()
2734

28-
output <- system2(quarto_bin, stdout = TRUE, c(
29-
"inspect",
30-
path.expand(input)
31-
))
35+
args <- c("inspect", path.expand(input))
3236

33-
fromJSON(output)
34-
}
37+
if (!is.null(profile)) {
38+
args <- c(args, c("--profile", paste0(profile, collapse = ",")))
39+
}
40+
41+
res <- processx::run(quarto_bin, args, echo_cmd = getOption("quarto.echo_cmd", FALSE))
3542

43+
fromJSON(res$stdout)
44+
}

R/quarto-args.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cli_arg_profile <- function(profile, ...) {
2+
arg <- c("--profile", paste0(profile, collapse = ","))
3+
append_cli_args(arg, ...)
4+
}
5+
6+
append_cli_args <- function(new, append_to = NULL, after = length(append_to)) {
7+
if (!is.null(append_to)) return(append(append_to, new, after))
8+
new
9+
}

R/render.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#' specified, with low precedence on `metadata` options.
3737
#' @param debug Leave intermediate files in place after render.
3838
#' @param quiet Suppress warning and other messages.
39+
#' @param profile [Quarto project
40+
#' profile(s)](https://quarto.org/docs/projects/profiles.html) to use. Either
41+
#' a character vector of profile names or `NULL` to use the default profile.
3942
#' @param pandoc_args Additional command line options to pass to pandoc.
4043
#' @param as_job Render as an RStudio background job. Default is "auto",
4144
#' which will render individual documents normally and projects as
@@ -76,6 +79,7 @@ quarto_render <- function(input = NULL,
7679
metadata_file = NULL,
7780
debug = FALSE,
7881
quiet = FALSE,
82+
profile = NULL,
7983
pandoc_args = NULL,
8084
as_job = getOption("quarto.render_as_job", "auto")) {
8185

@@ -107,7 +111,7 @@ quarto_render <- function(input = NULL,
107111
workingDir = getwd(),
108112
importEnv = TRUE
109113
)
110-
return (invisible(NULL))
114+
return(invisible(NULL))
111115
}
112116

113117

@@ -167,6 +171,9 @@ quarto_render <- function(input = NULL,
167171
if (isTRUE(quiet)) {
168172
args <- c(args, "--quiet")
169173
}
174+
if (!is.null(profile)) {
175+
args <- cli_arg_profile(profile, args)
176+
}
170177
if (!is.null(pandoc_args)) {
171178
args <- c(args, pandoc_args)
172179
}

man/quarto_inspect.Rd

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

man/quarto_render.Rd

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
execute:
2+
echo: true

tests/testthat/project/_quarto.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
project:
22
type: site
3+
4+
execute:
5+
echo: false

tests/testthat/test-inspect.R

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
test_that("R Markdown documents can be inspected", {
1+
test_that("Documents can be inspected", {
22
skip_if_no_quarto()
3-
metadata <- quarto_inspect("test.Rmd")
3+
metadata <- quarto_inspect(test_path("test.Rmd"))
4+
expect_type(metadata$formats, "list")
5+
metadata <- quarto_inspect(test_path("test.qmd"))
6+
expect_type(metadata$formats, "list")
7+
metadata <- quarto_inspect(test_path("test.ipynb"))
48
expect_type(metadata$formats, "list")
59
})
610

711
test_that("Quarto projects can be inspected", {
812
skip_if_no_quarto()
9-
metadata <- quarto_inspect("project")
13+
metadata <- quarto_inspect(test_path("project"))
14+
expect_type(metadata$config, "list")
15+
})
16+
17+
test_that("Quarto projects can be inspected with profile", {
18+
skip_if_no_quarto()
19+
metadata <- quarto_inspect(test_path("project"), "test")
1020
expect_type(metadata$config, "list")
21+
expect_identical(metadata$config$execute$echo, TRUE)
1122
})

0 commit comments

Comments
 (0)