-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
752 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Run tests | ||
|
||
on: | ||
push: | ||
branches: [ develop ] | ||
pull_request: | ||
branches: [ develop ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
container: | ||
image: ghcr.io/ctsit/rstudio-ci:4.1.0 | ||
credentials: | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.CR_PAT }} | ||
|
||
env: | ||
CI: "TRUE" | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Check | ||
run: devtools::test(stop_on_failure = TRUE) | ||
shell: Rscript {0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 0.1.0 | ||
Version: 0.2.0 | ||
Authors@R: c( | ||
person("Philip", "Chase", email = "[email protected]", role = c("aut", "cre")), | ||
person("Laurence", "James-Woodley", email = "[email protected]", role = "aut"), | ||
|
@@ -23,11 +23,13 @@ Imports: | |
glue, | ||
lubridate, | ||
magrittr, | ||
mRpostman, | ||
purrr, | ||
rjson, | ||
rlang, | ||
rstudioapi, | ||
sendmailR, | ||
stringr, | ||
sqldf, | ||
tibble, | ||
tidyr, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#' A template function for fetching authoritative email address data | ||
#' and other institutional data | ||
#' | ||
#' @param user_ids a optional vector of REDCap user IDs to be used in a query | ||
#' against the institutional data | ||
#' | ||
#' @return A Dataframe | ||
#' \itemize{ | ||
#' \item user_id - a column of redcap user_ids / institutional IDs | ||
#' \item email - a column of with the authoritative email address for user_id | ||
#' \item ... - Additional columns are allowed in the return data frame | ||
#' } | ||
#' @export | ||
#' | ||
#' @examples | ||
#' redcap_users <- c("jane_doe", "john_q_public") | ||
#' get_institutional_person_data(user_ids = redcap_users) | ||
get_institutional_person_data <- function(user_ids = c(NA_character_)) { | ||
email_data <- dplyr::tribble( | ||
~user_id, ~email, | ||
"inappropriate_user_id", "[email protected]", | ||
"jane_doe", "[email protected]", | ||
"john_q_public", "[email protected]" | ||
) | ||
|
||
if (length(user_ids) == 1 && is.na(user_ids)) { | ||
result <- email_data | ||
} else { | ||
result <- email_data %>% | ||
dplyr::filter(.data$user_id %in% user_ids) | ||
} | ||
|
||
return(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
#' Enumerate bad email addresses described in LISTSERV email digests | ||
#' | ||
#' Connect to an imap mailbox, identify LISTSERV digest emails sent | ||
#' after `messages_since_date`, and extract bounced email addresses | ||
#' from those digest messages. | ||
#' | ||
#' @param url The IMAP URL of the host that houses the mailbox | ||
#' @param username The username of the IMAP mailbox | ||
#' @param password The password of the IMAP mailbox | ||
#' @param messages_since_date The sent date of the oldest message that should be inspected | ||
#' | ||
#' @return A dataframe of bad email addresses | ||
#' \itemize{ | ||
#' \item email - a column of bad email address | ||
#' } | ||
#' @export | ||
#' @importFrom magrittr "%>%" | ||
#' @importFrom rlang .data | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' get_bad_emails_from_listserv_digest( | ||
#' username = "jdoe", | ||
#' password = "jane_does_password", | ||
#' url ="imaps://outlook.office365.com", | ||
#' messages_since_date = as.Date("2022-01-01", format = "%Y-%m-%d") | ||
#' ) | ||
#' } | ||
|
||
get_bad_emails_from_listserv_digest <- function(username, | ||
password, | ||
url = "imaps://outlook.office365.com", | ||
messages_since_date) { | ||
utils::globalVariables(c(".")) | ||
|
||
imap_con <- mRpostman::configure_imap( | ||
url = url, | ||
username = username, | ||
password = password | ||
) | ||
|
||
imap_con$select_folder("INBOX") | ||
error_emails <- imap_con$search_string(expr = "Daily error monitoring report", where = "SUBJECT") | ||
messages_since_date <- imap_con$search_since(date_char = format(messages_since_date, format = "%d-%b-%Y")) | ||
digest_emails <- dplyr::intersect(error_emails, messages_since_date) | ||
|
||
if (!is.na(digest_emails)) { | ||
bounced_email_addresses <- digest_emails %>% | ||
imap_con$fetch_body() %>% | ||
# key on Err First Last Address row | ||
stringr::str_extract_all("\\d{1} \\d{2}/\\d{2} \\d{2}/\\d{2}.*") %>% | ||
# flatten nested list of email -> address rows | ||
unlist() %>% | ||
# extract email address portion | ||
sub(".*\\s(.*@.*).*", "\\1", .) %>% | ||
# remove html encoded < and > characters | ||
sub("<", "", .) %>% | ||
sub(">", "", .) %>% | ||
# remove literal < and > characters | ||
sub("<", "", .) %>% | ||
sub(">", "", .) %>% | ||
# remove html newline | ||
sub("<br>", "", .) %>% | ||
unique() | ||
} else { | ||
bounced_email_addresses <- NA_character_ | ||
} | ||
|
||
bounce_data <- dplyr::tibble(bounced_email_addresses) %>% | ||
dplyr::mutate(email = tolower(.data$bounced_email_addresses)) %>% | ||
dplyr::select(.data$email) | ||
|
||
return(bounce_data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1.0 | ||
0.2.0 |
Oops, something went wrong.