Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pbchase committed Dec 13, 2022
2 parents c4293d2 + f58fd93 commit 1f32c86
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: redcapcustodian
Type: Package
Title: System data cleaning for REDCap
Version: 1.3.2
Version: 1.4.0
Authors@R: c(
person("Philip", "Chase",
email = "[email protected]",
Expand Down
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rocker/tidyverse:4.2.1
FROM rocker/verse:4.2.1

WORKDIR /home/rocker

Expand All @@ -20,10 +20,12 @@ RUN R -e "install.packages(c( \
'rjson', \
'sendmailR', \
'sqldf', \
'writexl' \
'writexl', \
'kableExtra' \
))"

RUN R -e "devtools::install_github('allanvc/mRpostman')"
RUN wget -qO- "https://yihui.org/tinytex/install-bin-unix.sh" | sh

# build and install this package
ADD . /home/rocker/redcapcustodian
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ All notable changes to the redcapcustodian package and its contained scripts wil
This project adheres to [Semantic Versioning](http://semver.org/).


## [1.4.0] - 2022-12-13
### Added
- Switch Dockerfile from tidyverse to verse (Laurence James-Woodley)
- Add render_report.R to render Rmds (Laurence James-Woodley)


## [1.3.2] - 2022-09-14
### Changed
- Specify package for na.exclude() (Philip Chase)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.2
1.4.0
4 changes: 3 additions & 1 deletion docs/custom_rscript.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ Stop and think about architecture and study lifecycle.

If you need something to run periodically, you need to make it easy to run with all of its dependencies packaged up and you need to schedule it. The modern way to package dependencies is to put them all into a container, add your application and run the container. REDCap Custodian supports containerization with Docker. The [`./study_template/Dockerfile`](./study_template/Dockerfile) is template you can use to containerize your RScript and RMarkdown. Adapt it to your needs and build the container with [./build.sh](./build.sh). If you have good container infrastructure, use it to build and deploy your containers.


Running automated R Markdown reports from docker requires the use of an Rmd renderer.
[render_report.R](../study_template/report/render_report.R) contains functionality to knit an Rmd, email it and then log the job run. The Rmd script name is passed as a command line argument to [render_report.R](../study_template/report/render_report.R) via cron. Refer to [sample_report](../study_template/cron/sample_report) for an example cron job.

## Automation with Linux and cron

If you have no container management infrastructure available to you, but your IT support provides Linux hosts, have them build one for you, install Docker on it, and give you `sudo su` access. That will allow you to build and run docker images on the host.
Expand Down
2 changes: 2 additions & 0 deletions study_template/cron/sample_report
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Run the sample Rmd report
05 8-17 * * * root /usr/bin/docker run --rm --env-file /rcc/study_template/.env rcc.site Rscript report/render_report.R script_name=sample_report.Rmd
42 changes: 42 additions & 0 deletions study_template/report/render_report.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
library(tidyverse)
library(dotenv)
library(REDCapR)
library(lubridate)
library(rmarkdown)
library(sendmailR)
library(redcapcustodian)

init_etl("render_report")

if (!interactive()) {
args <- commandArgs(trailingOnly = T)
script_name <- word(args, 2, sep = "=")
} else {
script_name <- "sample_report.Rmd"
}

report_name <- word(script_name, 1, sep = "\\.")

script_run_time <- set_script_run_time()

output_file = paste0(report_name,
"_",
format(script_run_time, "%Y%m%d%H%M%S"))

full_path_to_output_file <- render(
paste0("report/", script_name),
output_file = output_file
)

output_file_extension <- word(full_path_to_output_file, 2 , sep = "\\.")
attachment_object <- mime_part(full_path_to_output_file, paste0(output_file, ".", output_file_extension))

email_subject <- paste(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)

log_job_success(jsonlite::toJSON(script_name))
28 changes: 28 additions & 0 deletions study_template/report/sample_report.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: "Sample Report"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

0 comments on commit 1f32c86

Please sign in to comment.