diff --git a/report/render_report.R b/report/render_report.R index 643dae0..e41a08e 100644 --- a/report/render_report.R +++ b/report/render_report.R @@ -18,38 +18,44 @@ if (!interactive()) { stop(sprintf("Specified file, %s, does not exist", script_name)) } } else { - script_name <- "dummy.qmd" - stop(sprintf("Specified file, %s, does not exist", script_name)) + script_name <- "report/sample_report.qmd" + if(!fs::file_exists(script_name)) { + stop(sprintf("Specified file, %s, does not exist", script_name)) + } } report_name <- word(script_name, 1, sep = "\\.") report_type <- word(script_name, 2, sep = "\\.") script_run_time <- set_script_run_time() -output_file <- - paste0(str_replace(report_name, ".*/", ""), - "_", - format(script_run_time, "%Y%m%d%H%M%S"), - if_else(report_type == "qmd", ".pdf", "") - ) +output_filename <- + paste0( + str_replace(report_name, ".*/", ""), + "_", + format(script_run_time, "%Y%m%d%H%M%S") + ) if (report_type == "qmd") { - quarto::quarto_render( + full_path_to_output_file <- quarto::quarto_render( script_name, - output_file = output_file, + output_file = paste0(output_filename, ".pdf"), output_format = "pdf" ) + + attachment_object <- mime_part(paste0(output_filename, ".pdf")) } else { - render( + full_path_to_output_file <- render( script_name, - output_file = output_file + output_file = output_filename ) -} -output_file_extension <- word(output_file, 2 , sep = "\\.") -attachment_object <- mime_part(output_file, output_file) + attachment_object <- mime_part( + full_path_to_output_file, + basename(full_path_to_output_file) + ) +} -email_subject <- paste(report_name, "|", script_run_time) +email_subject <- paste(basename(report_name), "|", script_run_time) body <- "Please see the attached report." email_body <- list(body, attachment_object) @@ -57,4 +63,5 @@ email_body <- list(body, attachment_object) # send the email with the attached output file send_email(email_body, email_subject) +set_script_name("render_report") log_job_success(jsonlite::toJSON(script_name)) diff --git a/report/sample_report.qmd b/report/sample_report.qmd new file mode 100644 index 0000000..9f3d18f --- /dev/null +++ b/report/sample_report.qmd @@ -0,0 +1,29 @@ +--- +title: "sample_report" +format: + html: + toc: true + pdf: + toc: true +--- + +## Quarto + +Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see . + +## Running Code + +When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this: + +```{r} +1 + 1 +``` + +You can add options to executable code like this + +```{r} +#| echo: false +2 * 2 +``` + +The `echo: false` option disables the printing of code (only output is displayed). diff --git a/study_template/report/render_report.R b/study_template/report/render_report.R index 643dae0..e41a08e 100644 --- a/study_template/report/render_report.R +++ b/study_template/report/render_report.R @@ -18,38 +18,44 @@ if (!interactive()) { stop(sprintf("Specified file, %s, does not exist", script_name)) } } else { - script_name <- "dummy.qmd" - stop(sprintf("Specified file, %s, does not exist", script_name)) + script_name <- "report/sample_report.qmd" + if(!fs::file_exists(script_name)) { + stop(sprintf("Specified file, %s, does not exist", script_name)) + } } report_name <- word(script_name, 1, sep = "\\.") report_type <- word(script_name, 2, sep = "\\.") script_run_time <- set_script_run_time() -output_file <- - paste0(str_replace(report_name, ".*/", ""), - "_", - format(script_run_time, "%Y%m%d%H%M%S"), - if_else(report_type == "qmd", ".pdf", "") - ) +output_filename <- + paste0( + str_replace(report_name, ".*/", ""), + "_", + format(script_run_time, "%Y%m%d%H%M%S") + ) if (report_type == "qmd") { - quarto::quarto_render( + full_path_to_output_file <- quarto::quarto_render( script_name, - output_file = output_file, + output_file = paste0(output_filename, ".pdf"), output_format = "pdf" ) + + attachment_object <- mime_part(paste0(output_filename, ".pdf")) } else { - render( + full_path_to_output_file <- render( script_name, - output_file = output_file + output_file = output_filename ) -} -output_file_extension <- word(output_file, 2 , sep = "\\.") -attachment_object <- mime_part(output_file, output_file) + attachment_object <- mime_part( + full_path_to_output_file, + basename(full_path_to_output_file) + ) +} -email_subject <- paste(report_name, "|", script_run_time) +email_subject <- paste(basename(report_name), "|", script_run_time) body <- "Please see the attached report." email_body <- list(body, attachment_object) @@ -57,4 +63,5 @@ email_body <- list(body, attachment_object) # send the email with the attached output file send_email(email_body, email_subject) +set_script_name("render_report") log_job_success(jsonlite::toJSON(script_name)) diff --git a/study_template/report/sample_report.qmd b/study_template/report/sample_report.qmd new file mode 100644 index 0000000..9f3d18f --- /dev/null +++ b/study_template/report/sample_report.qmd @@ -0,0 +1,29 @@ +--- +title: "sample_report" +format: + html: + toc: true + pdf: + toc: true +--- + +## Quarto + +Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see . + +## Running Code + +When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this: + +```{r} +1 + 1 +``` + +You can add options to executable code like this + +```{r} +#| echo: false +2 * 2 +``` + +The `echo: false` option disables the printing of code (only output is displayed).