Skip to content

Commit

Permalink
output_file arg
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Mar 18, 2024
1 parent 87c0757 commit 480e7c3
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 38 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Imports:
Suggests:
curl (>= 4.3),
knitr (>= 1.28),
quarto (>= 1.0),
quarto (>= 1.4),
rmarkdown (>= 2.1),
testthat (>= 3.0.0),
xml2 (>= 1.3.2)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* `tar_map()` and other static branching target factories now append values to the target descriptions. Use the `descriptions` argument of those functions to customize.
* Ensure consistent `repository` settings in `tar_change()` and `tar_map_rep()`.
* `tar_knit()`, `tar_render()`, `tar_quarto()`, and their "rep" and "raw" versions all gain a `working_directory` argument to change the working directory the report knits from. Users who set `working_directory` need to supply the `store` argument of `tar_load()` and `tar_read()` relative to the working directory so the report knows where to find the data.
* `tar_knit()`, `tar_render()`, `tar_quarto()`, and their "raw" versions all gain an `output_file` argument to more conveniently set the file path to the rendered output file.

# tarchetypes 0.7.12

Expand Down
24 changes: 18 additions & 6 deletions R/tar_knit.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
tar_knit <- function(
name,
path,
output = NULL,
output_file = NULL,
working_directory = NULL,
tidy_eval = targets::tar_option_get("tidy_eval"),
packages = targets::tar_option_get("packages"),
Expand All @@ -90,8 +90,8 @@ tar_knit <- function(
) {
targets::tar_assert_package("knitr")
targets::tar_assert_file(path)
targets::tar_assert_chr(output %|||% "x")
targets::tar_assert_scalar(output %|||% "x")
targets::tar_assert_chr(output_file %|||% "x")
targets::tar_assert_scalar(output_file %|||% "x")
if (!is.null(working_directory)) {
targets::tar_assert_file(working_directory)
}
Expand All @@ -103,7 +103,13 @@ tar_knit <- function(
)
targets::tar_target_raw(
name = targets::tar_deparse_language(substitute(name)),
command = tar_knit_command(path, output, working_directory, args, quiet),
command = tar_knit_command(
path,
output_file,
working_directory,
args,
quiet
),
packages = packages,
library = library,
format = "file",
Expand All @@ -120,9 +126,15 @@ tar_knit <- function(
)
}

tar_knit_command <- function(path, output, working_directory, args, quiet) {
tar_knit_command <- function(
path,
output_file,
working_directory,
args,
quiet
) {
args$input <- path
args$output <- output
args$output <- output_file
args$quiet <- quiet
deps <- call_list(as_symbols(knitr_deps(path)))
fun <- call_ns("tarchetypes", "tar_knit_run")
Expand Down
8 changes: 4 additions & 4 deletions R/tar_knit_raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
tar_knit_raw <- function(
name,
path,
output = NULL,
output_file = NULL,
working_directory = NULL,
packages = targets::tar_option_get("packages"),
library = targets::tar_option_get("library"),
Expand All @@ -76,8 +76,8 @@ tar_knit_raw <- function(
targets::tar_assert_package("knitr")
targets::tar_assert_file(path)
targets::tar_assert_not_dirs(path)
targets::tar_assert_chr(output %|||% "x")
targets::tar_assert_scalar(output %|||% "x")
targets::tar_assert_chr(output_file %|||% "x")
targets::tar_assert_scalar(output_file %|||% "x")
if (!is.null(working_directory)) {
targets::tar_assert_file(working_directory)
}
Expand All @@ -87,7 +87,7 @@ tar_knit_raw <- function(
name = name,
command = tar_knit_command(
path,
output,
output_file,
working_directory,
knit_arguments,
quiet
Expand Down
2 changes: 2 additions & 0 deletions R/tar_quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
tar_quarto <- function(
name,
path = ".",
output_file = NULL,
working_directory = NULL,
extra_files = character(0),
execute = TRUE,
Expand Down Expand Up @@ -149,6 +150,7 @@ tar_quarto <- function(
tar_quarto_raw(
name = name,
path = path,
output_file = output_file,
working_directory = working_directory,
extra_files = extra_files,
execute = execute,
Expand Down
8 changes: 8 additions & 0 deletions R/tar_quarto_raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
tar_quarto_raw <- function(
name,
path = ".",
output_file = NULL,
working_directory = NULL,
extra_files = character(0),
execute = TRUE,
Expand Down Expand Up @@ -138,6 +139,9 @@ tar_quarto_raw <- function(
targets::tar_assert_chr(extra_files)
targets::tar_assert_nzchar(extra_files)
targets::tar_assert_file(path)
targets::tar_assert_chr(output_file %|||% "x")
targets::tar_assert_scalar(output_file %|||% "x")
targets::tar_assert_nzchar(output_file %|||% "x")
if (!is.null(working_directory)) {
targets::tar_assert_file(working_directory)
}
Expand Down Expand Up @@ -170,6 +174,7 @@ tar_quarto_raw <- function(
}
command <- tar_quarto_command(
path = path,
output_file = output_file,
working_directory = working_directory,
sources = sources,
output = output,
Expand Down Expand Up @@ -202,6 +207,7 @@ tar_quarto_raw <- function(

tar_quarto_command <- function(
path,
output_file,
working_directory,
sources,
output,
Expand All @@ -218,6 +224,7 @@ tar_quarto_command <- function(
args <- substitute(
list(
input = path,
output_file = output_file,
execute = execute,
execute_params = execute_params,
execute_dir = execute_dir,
Expand All @@ -233,6 +240,7 @@ tar_quarto_command <- function(
),
env = list(
path = path,
output_file = output_file,
execute = execute,
execute_dir = working_directory %|||% quote(getwd()),
execute_params = execute_params,
Expand Down
9 changes: 6 additions & 3 deletions R/tar_render.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#' @inheritParams rmarkdown::render
#' @param path Character string, file path to the R Markdown source file.
#' Must have length 1.
#' @param output Character string, file path to the rendered output file.
#' @param output_file Character string, file path to the rendered output file.
#' @param working_directory Optional character string,
#' path to the working directory
#' to temporarily set when running the report.
Expand Down Expand Up @@ -123,7 +123,7 @@
tar_render <- function(
name,
path,
output = NULL,
output_file = NULL,
working_directory = NULL,
tidy_eval = targets::tar_option_get("tidy_eval"),
packages = targets::tar_option_get("packages"),
Expand All @@ -142,6 +142,9 @@ tar_render <- function(
) {
targets::tar_assert_package("rmarkdown")
targets::tar_assert_file(path)
targets::tar_assert_chr(output_file %|||% "x")
targets::tar_assert_scalar(output_file %|||% "x")
targets::tar_assert_nzchar(output_file %|||% "x")
if (!is.null(working_directory)) {
targets::tar_assert_file(working_directory)
}
Expand All @@ -155,7 +158,7 @@ tar_render <- function(
name = targets::tar_deparse_language(substitute(name)),
command = tar_render_command(
path,
output,
output_file,
working_directory,
args,
quiet
Expand Down
10 changes: 5 additions & 5 deletions R/tar_render_raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
tar_render_raw <- function(
name,
path,
output = NULL,
output_file = NULL,
working_directory = NULL,
packages = targets::tar_option_get("packages"),
library = targets::tar_option_get("library"),
Expand All @@ -100,9 +100,9 @@ tar_render_raw <- function(
) {
targets::tar_assert_package("rmarkdown")
targets::tar_assert_file(path)
targets::tar_assert_chr(output %|||% "x")
targets::tar_assert_scalar(output %|||% "x")
targets::tar_assert_nzchar(output %|||% "x")
targets::tar_assert_chr(output_file %|||% "x")
targets::tar_assert_scalar(output_file %|||% "x")
targets::tar_assert_nzchar(output_file %|||% "x")
if (!is.null(working_directory)) {
targets::tar_assert_file(working_directory)
}
Expand All @@ -112,7 +112,7 @@ tar_render_raw <- function(
name = name,
command = tar_render_command(
path,
output,
output_file,
working_directory,
render_arguments,
quiet
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Boneri
Bostock
brancher
Broman
CLI
Broman's
bugfix
Bugfix
Expand Down
6 changes: 2 additions & 4 deletions man/tar_knit.Rd

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

6 changes: 2 additions & 4 deletions man/tar_knit_raw.Rd

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

8 changes: 7 additions & 1 deletion man/tar_quarto.Rd

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

8 changes: 7 additions & 1 deletion man/tar_quarto_raw.Rd

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

2 changes: 1 addition & 1 deletion man/tar_quarto_rep.Rd

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

2 changes: 1 addition & 1 deletion man/tar_quarto_rep_raw.Rd

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

4 changes: 2 additions & 2 deletions man/tar_render.Rd

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

4 changes: 2 additions & 2 deletions man/tar_render_raw.Rd

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

Loading

0 comments on commit 480e7c3

Please sign in to comment.