-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathquarto-render-basic-report.R
61 lines (51 loc) · 2.1 KB
/
quarto-render-basic-report.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# quarto-render-basic-report.R ####
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# R code of the Learning Technology & Analytics Research Group of THUAS
# Copyright 2025 THUAS
# Web Page: http://www.thuas.com
# Contact: Theo Bakker ([email protected])
# Distribution outside THUAS: Yes
#
# Purpose: Rendering quarto profile: basic-report
#
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Set minimal libraries
library(here)
library(cli)
library(rvest)
library(stringr)
library(glue)
library(quarto)
# Define the parameters for the quarto file
execute_params_list <- list(
sp = "CMD", # CMD or VD
sp_form = "VT"
)
# Delete the _freeze folder (bug in Quarto)
if (dir.exists("_freeze")) {
unlink("_freeze", recursive = TRUE)
}
# Test if model building for the current study programme has been executed, if not, alert
if (file.exists(here::here("_advanced-report", "ch-models.html"))) {
# Define text and search string
text_content <- html_text(read_html(here::here("_advanced-report", "ch-models.html")))
search_string <- sprintf("(%s)", execute_params_list$sp)
# Check if the search string is found in the text content
if (!str_detect(text_content, search_string)) {
cli_alert_warning(glue("First, render the advanced-report ",
"for the study programme {execute_params_list$sp}."))
} else {
cli_alert_info(glue("The advanced-report was rendered for the study programme ",
"{execute_params_list$sp} \n",
"The basic-report is rendered now."))
# Render a basic report
withr::with_envvar(new = c("QUARTO_PROFILE" = "basic-report"), {
quarto::quarto_render(execute_params = execute_params_list,
as_job = FALSE)
})
}
} else {
cli_alert_warning(glue("First, render the advanced-report ",
"for the study programme {execute_params_list$sp}."))
}