Skip to content

Commit 3640c41

Browse files
committed
pr: copy rmd and setup tempdir only once
1 parent 309c5ac commit 3640c41

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

R/tm_rmarkdown.R

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,15 @@ srv_rmarkdown <- function(id, data, rmd_file, allow_download, extra_transform) {
201201
transformators = extra_transform
202202
)
203203

204+
temp_dir <- tempdir()
205+
temp_rmd <- tempfile(tmpdir = temp_dir, fileext = ".Rmd")
206+
file.copy(rmd_file, temp_rmd) # Use a copy of the Rmd file to avoid modifying the original
207+
204208
rendered_path_r <- reactive({
205209
datasets <- req(q_r()) # Ensure data is available
206-
temp_dir <- tempdir()
207-
temp_rmd <- tempfile(tmpdir = temp_dir, fileext = ".Rmd")
208-
temp_html <- tempfile(tmpdir = temp_dir, fileext = ".md")
209-
file.copy(rmd_file, temp_rmd) # Use a copy of the Rmd file to avoid modifying the original
210+
211+
temp_output <- tempfile(tmpdir = temp_dir, fileext = ".md")
212+
210213

211214
tryCatch(
212215
{
@@ -217,13 +220,13 @@ srv_rmarkdown <- function(id, data, rmd_file, allow_download, extra_transform) {
217220
toc = TRUE,
218221
preserve_yaml = TRUE
219222
),
220-
output_file = temp_html,
223+
output_file = temp_output,
221224
params = datasets[["rmd_data"]],
222225
envir = new.env(parent = globalenv()),
223226
quiet = TRUE,
224227
runtime = "static"
225228
)
226-
temp_html
229+
temp_output
227230
},
228231
error = function(e) {
229232
warning("Error rendering RMD file: ", e$message) # verbose error in logs

0 commit comments

Comments
 (0)