@@ -91,7 +91,13 @@ local_quarto_project <- function(
9191 return (file.path(path_tmp , name ))
9292}
9393
94- .render <- function (input , output_file = NULL , ... , .env = parent.frame()) {
94+ .render <- function (
95+ input ,
96+ output_file = NULL ,
97+ ... ,
98+ .quiet = TRUE ,
99+ .env = parent.frame()
100+ ) {
95101 skip_if_no_quarto()
96102 skip_if_not_installed(" withr" )
97103 # work inside input directory
@@ -102,7 +108,12 @@ local_quarto_project <- function(
102108 .local_envir = .env
103109 ))
104110 }
105- quarto_render(basename(input ), output_file = output_file , quiet = TRUE , ... )
111+ expect_no_error(quarto_render(
112+ basename(input ),
113+ output_file = output_file ,
114+ quiet = .quiet ,
115+ ...
116+ ))
106117 expect_true(file.exists(output_file ))
107118 normalizePath(output_file )
108119}
@@ -134,7 +145,8 @@ expect_snapshot_qmd_output <- function(name, input, output_file = NULL, ...) {
134145transform_quarto_cli_in_output <- function (
135146 full_path = FALSE ,
136147 version = FALSE ,
137- dir_only = FALSE
148+ dir_only = FALSE ,
149+ hide_stack = FALSE
138150) {
139151 hide_path <- function (lines , real_path ) {
140152 gsub(
@@ -147,6 +159,38 @@ transform_quarto_cli_in_output <- function(
147159
148160 return (
149161 function (lines ) {
162+ if (hide_stack ) {
163+ # Hide possible stack first
164+ stack_trace_index <- which(grepl(" \\ s*Stack trace\\ :" , lines ))
165+ if (
166+ length(stack_trace_index ) > 0 && stack_trace_index < length(lines )
167+ ) {
168+ at_lines_indices <- which(grepl(" ^\\ s*at " , lines ))
169+ at_lines_after_stack <- at_lines_indices [
170+ at_lines_indices > stack_trace_index
171+ ]
172+ if (length(at_lines_after_stack ) > 0 ) {
173+ # Find the continuous sequence (no gaps)
174+ gaps <- diff(at_lines_after_stack ) > 1
175+ end_pos <- if (any(gaps )) which(gaps )[1 ] else
176+ length(at_lines_after_stack )
177+ consecutive_indices <- at_lines_after_stack [1 : end_pos ]
178+
179+ stack_line <- lines [stack_trace_index ]
180+ indentation <- regmatches(stack_line , regexpr(" ^\\ s*" , stack_line ))
181+ lines [consecutive_indices [1 ]] <- paste0(
182+ indentation ,
183+ " <stack trace>"
184+ )
185+ if (length(consecutive_indices ) > 1 ) {
186+ lines <- lines [
187+ - consecutive_indices [2 : length(consecutive_indices )]
188+ ]
189+ }
190+ }
191+ }
192+ }
193+
150194 if (full_path ) {
151195 quarto_found <- find_quarto()
152196 if (dir_only ) {
@@ -207,3 +251,34 @@ local_quarto_run_echo_cmd <- function(.env = parent.frame()) {
207251 withr :: local_options(quarto.echo_cmd = TRUE , .local_envir = .env )
208252 }
209253}
254+
255+ quick_install <- function (package , lib , quiet = TRUE ) {
256+ skip_if_not_installed(" callr" )
257+ opts <- c(
258+ " --data-compress=none" ,
259+ " --no-byte-compile" ,
260+ " --no-data" ,
261+ " --no-demo" ,
262+ " --no-docs" ,
263+ " --no-help" ,
264+ " --no-html" ,
265+ " --no-libs" ,
266+ " --use-vanilla" ,
267+ sprintf(" --library=%s" , lib ),
268+ package
269+ )
270+ invisible (callr :: rcmd(" INSTALL" , opts , show = ! quiet , fail_on_status = TRUE ))
271+ }
272+
273+ install_dev_package <- function (.local_envir = parent.frame()) {
274+ # if not inside of R CMD check, install dev version into temp directory
275+ if (Sys.getenv(" _R_CHECK_TIMINGS_" ) == " " ) {
276+ skip_if_not_installed(" pkgload" )
277+ withr :: local_temp_libpaths(.local_envir = .local_envir )
278+ quick_install(pkgload :: pkg_path(" ." ), lib = .libPaths()[1 ])
279+ withr :: local_envvar(
280+ R_LIBS = paste0(.libPaths(), collapse = .Platform $ path.sep ),
281+ .local_envir = .local_envir
282+ )
283+ }
284+ }
0 commit comments