Skip to content
New issue

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

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

Already on GitHub? # to your account

Update render report for qmd #129

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions report/render_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,50 @@ 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)

# 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))
29 changes: 29 additions & 0 deletions report/sample_report.qmd
Original file line number Diff line number Diff line change
@@ -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 <https://quarto.org>.

## 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).
39 changes: 23 additions & 16 deletions study_template/report/render_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,50 @@ 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)

# 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))
29 changes: 29 additions & 0 deletions study_template/report/sample_report.qmd
Original file line number Diff line number Diff line change
@@ -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 <https://quarto.org>.

## 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).