Skip to content

Commit

Permalink
ignore log and output folders ad add timestamp to logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
ljwoodley committed Oct 23, 2024
1 parent 87231be commit 90ecf83
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*.zip
site
!inst/testdata/*.csv
report/*log.txt
report/*.html
report/output/*
report/log/*

# env file
*.env
Expand Down
5 changes: 3 additions & 2 deletions R/reporting.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ render_report <- function(script_path) {

script_path_without_extension <- tools::file_path_sans_ext(script_path)
base_script_name <- basename(script_path_without_extension)
logfile <- paste0(script_path_without_extension, "_log.txt")
run_time <- format(redcapcustodian::get_script_run_time(), "%Y-%m-%d_%H%M%S")
logfile <- here::here("report", "log", paste0(base_script_name, "_", run_time, ".txt"))

result <- tryCatch({
capture.output(quarto::quarto_render(script_path), file = logfile)
Expand All @@ -57,7 +58,7 @@ render_report <- function(script_path) {
report_name <- paste0(
base_script_name,
"_",
format(redcapcustodian::get_script_run_time(), "%Y-%m-%d_%H%M%S"),
run_time,
".",
file_extension
)
Expand Down
1 change: 1 addition & 0 deletions man/render_report.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions report/log/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
6 changes: 2 additions & 4 deletions report/output/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
*.csv
*.xlsx
*.html
*.pdf
*
!.gitignore
14 changes: 6 additions & 8 deletions report/render_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ library(argparse)
init_etl("render_report")

parser <- ArgumentParser()
parser$add_argument("script_path", nargs=1, help="The full path of the script to be run")
parser$add_argument("script_path", nargs=1, help="The path of the script to be run")

if (!interactive()) {
args <- parser$parse_args()
script_path <- args$script_path
if(!fs::file_exists(script_path)) {
stop(sprintf("Specified file, %s, does not exist", script_path))
}
} else {
script_path <- "study_template/report/quarto_html_example.qmd"
if(!fs::file_exists(script_path)) {
stop(sprintf("Specified file, %s, does not exist", script_path))
}
script_path <- here::here("report", "sample_report.Rmd")
}

if(!fs::file_exists(script_path)) {
stop(sprintf("Specified file, %s, does not exist", script_path))
}

render_results <- render_report(script_path)
Expand Down
3 changes: 2 additions & 1 deletion study_template/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
*.env
!examples/testing.env
output/
report/*log.txt
report/output/*
report/log/*
2 changes: 2 additions & 0 deletions study_template/report/log/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
14 changes: 6 additions & 8 deletions study_template/report/render_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ library(argparse)
init_etl("render_report")

parser <- ArgumentParser()
parser$add_argument("script_path", nargs=1, help="The full path of the script to be run")
parser$add_argument("script_path", nargs=1, help="The path of the script to be run")

if (!interactive()) {
args <- parser$parse_args()
script_path <- args$script_path
if(!fs::file_exists(script_path)) {
stop(sprintf("Specified file, %s, does not exist", script_path))
}
} else {
script_path <- "study_template/report/quarto_html_example.qmd"
if(!fs::file_exists(script_path)) {
stop(sprintf("Specified file, %s, does not exist", script_path))
}
script_path <- here::here("report", "quarto_html_example.qmd")
}

if(!fs::file_exists(script_path)) {
stop(sprintf("Specified file, %s, does not exist", script_path))
}

render_results <- render_report(script_path)
Expand Down

0 comments on commit 90ecf83

Please sign in to comment.