Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render on a separate directory #20

Merged
merged 13 commits into from
Feb 7, 2025
Prev Previous commit
Next Next commit
Render in a separate folder
  • Loading branch information
llrs-roche committed Jan 30, 2025
commit 2588f0210161dd8439c0adc0e821993e9009f4e4
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ License: MIT + file LICENSE
URL: https://github.com/pharmaR/riskreports
BugReports: https://github.com/pharmaR/riskreports/issues
Depends:
R (>= 3.5.0)
R (>= 4.4.0)
Imports:
methods,
quarto (>= 1.4.4)
17 changes: 12 additions & 5 deletions R/reporter.R
Original file line number Diff line number Diff line change
@@ -63,28 +63,35 @@ package_report <- function(
if (v < package_version("1.7.13")) {
warning("Please install the latest (devel) version of Quarto")
}
# https://github.com/quarto-dev/quarto-r/issues/81#issuecomment-1375691267
# quarto rendering happens in the same place as the file/project
# To avoid issues copy to a different place and render there.
render_dir <- rendering_dir()
file.copy(from = template_path, to = render_dir)
template <- list.files(render_dir, full.names = TRUE)
template <- template[endsWith(template, "qmd")]

suppressMessages({suppressWarnings({
out <- quarto::quarto_render(
template_path,
template,
output_format = "all",
execute_params = params,
output_file = paste0("validation_report_", full_name),
...
)
})})

# Move reports after creation (work around issue https://github.com/quarto-dev/quarto-cli/issues/5765)
lf <- list.files(dirname(template_path), full.names = TRUE)
lf <- list.files(render_dir, full.names = TRUE)
files_template <- lf[!dir.exists(lf)]
file_name <- tools::file_path_sans_ext(basename(template_path))
files_template <- files_template[startsWith(basename(files_template),
file_name)]
files_template <- files_template[!endsWith(files_template, ".qmd")]
output_file = paste0("validation_report_", full_name,
".", tools::file_ext(files_template))
file.rename(files_template, output_file)
invisible(output_file)
output_files <- normalizePath(file.path(output_dir(), output_file))
file.rename(files_template, output_files)
invisible(output_files)
}

is.empty <- function(x) {
15 changes: 15 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -17,3 +17,18 @@ fill_in <- function(list, names) {
list[missing_names] <- NA
list
}


output_dir <- function() {
opt <- getOption("riskreports_output_dir", default = NULL)
env <- Sys.getenv("RISKREPORTS_OUTPUT_DIR", unset = getwd())

opt %||% env
}

rendering_dir <- function() {
opt <- getOption("riskreports_rendering_dir", default = NULL)
env <- Sys.getenv("RISKREPORTS_RENDERING_DIR", unset = tempdir())

opt %||% env
}