Skip to content

Commit aeb2f7b

Browse files
committed
Merge branch 'release/1.19.0'
2 parents 6fa90ac + 2d9249c commit aeb2f7b

10 files changed

+271
-2
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: redcapcustodian
22
Type: Package
33
Title: Data automation for R-centric workflows with a nod towards REDCap
4-
Version: 1.18.0
4+
Version: 1.19.0
55
Authors@R: c(
66
person("Philip", "Chase",
77
email = "pbc@ufl.edu",

NAMESPACE

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export(log_job_failure)
4040
export(log_job_success)
4141
export(mutate_columns_to_posixct)
4242
export(quit_non_interactive_run)
43+
export(read_project_data)
44+
export(read_project_metadata)
4345
export(scrape_user_api_tokens)
4446
export(send_email)
4547
export(set_package_scope_var)
@@ -57,6 +59,7 @@ export(update_redcap_email_addresses)
5759
export(write_allocations)
5860
export(write_error_log_entry)
5961
export(write_info_log_entry)
62+
export(write_project_data)
6063
export(write_summary_metrics)
6164
export(write_to_sql_db)
6265
importFrom(magrittr,"%>%")

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# redcapcustodian 1.19.0 (released 2024-01-30)
2+
- Add REDCapR wrapper functions (@ljwoodley, #147, #148)
3+
14
# redcapcustodian 1.18.0 (released 2024-01-10)
25
- Update Dockerfile to verse:4.3.2 (@pbchase)
36

R/read_project_data.R

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#' read_project_data Read data from a REDCap project
2+
#'
3+
#' @param ... parameters to pass on to `REDCapR::redcap_read`
4+
#' @param conn Connection object to the credentials database
5+
#' @param project_pid the project PID in the REDCap system.
6+
#' This string will be used to search through a REDCap custodian
7+
#' credentials database to locate the `token` and `redcap_uri`
8+
#' @param server_short_name an optional name of the server that
9+
#' houses the REDCap project of interest. This will prevent
10+
#' project PID clashes.
11+
#'
12+
#' @return a dataframe of data read from a REDCap project
13+
#' @export
14+
#' @importFrom rlang .data
15+
#' @examples
16+
#' \dontrun{
17+
#' library(redcapcustodian)
18+
#' library(DBI)
19+
#'
20+
#' dotenv::load_dot_env("testing.env")
21+
#' init_etl("dummy")
22+
#'
23+
#' support_data <- read_project_data(
24+
#' conn = DBI::dbConnect(RSQLite::SQLite(), Sys.getenv("CREDENTIALS_DB")),
25+
#' project_pid = Sys.getenv("MY_PROJECT_PID"))
26+
#' }
27+
read_project_data <- function(..., conn, project_pid, server_short_name = as.character(NA)) {
28+
redcap_credentials <- dplyr::tbl(conn, "credentials") |>
29+
dplyr::filter(.data$project_id == project_pid) |>
30+
dplyr::filter(is.na(server_short_name) | .data$server_short_name == server_short_name) |>
31+
dplyr::collect()
32+
33+
# Get the data from the REDCap Project
34+
data_read <- REDCapR::redcap_read(
35+
redcap_uri = redcap_credentials$redcap_uri,
36+
token = redcap_credentials$token,
37+
batch_size = 2000,
38+
...
39+
)
40+
41+
if (data_read$success) {
42+
data <- data_read$data
43+
}
44+
45+
return(data_read)
46+
}

R/read_project_metadata.R

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#' read_project_metadata Read data from a REDCap project
2+
#'
3+
#' @param ... parameters to pass on to `REDCapR::redcap_metadata_read`
4+
#' @param conn Connection object to the credentials database
5+
#' @param project_pid the project PID in the REDCap system.
6+
#' This string will be used to search through a REDCap custodian
7+
#' credentials database to locate the `token` and `redcap_uri`
8+
#' @param server_short_name an optional name of the server that
9+
#' houses the REDCap project of interest. This will prevent
10+
#' project PID clashes.
11+
#'
12+
#' @return a dataframe of metadata read from a REDCap project
13+
#' @export
14+
#' @importFrom rlang .data
15+
#' @examples
16+
#' \dontrun{
17+
#' library(redcapcustodian)
18+
#' library(DBI)
19+
#'
20+
#' dotenv::load_dot_env("testing.env")
21+
#' init_etl("dummy")
22+
#'
23+
#' support_data <- read_project_metadata(
24+
#' conn = DBI::dbConnect(RSQLite::SQLite(), Sys.getenv("CREDENTIALS_DB")),
25+
#' project_pid = Sys.getenv("MY_PROJECT_PID"))
26+
#' }
27+
read_project_metadata <- function(..., conn, project_pid, server_short_name = as.character(NA)) {
28+
redcap_credentials <- dplyr::tbl(conn, "credentials") |>
29+
dplyr::filter(.data$project_id == project_pid) |>
30+
dplyr::filter(is.na(server_short_name) | .data$server_short_name == server_short_name) |>
31+
dplyr::collect()
32+
33+
# Get the data from the REDCap Project
34+
data_read <- REDCapR::redcap_metadata_read (
35+
redcap_uri = redcap_credentials$redcap_uri,
36+
token = redcap_credentials$token,
37+
...
38+
)
39+
40+
if (data_read$success) {
41+
data <- data_read$data
42+
}
43+
44+
return(data_read)
45+
}

R/write_project_data.R

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#' write_project_data Write data from a REDCap project
2+
#'
3+
#' @param ... parameters to pass on to `REDCapR::redcap_write`
4+
#' @param conn Connection object to the credentials database
5+
#' @param project_pid the project PID in the REDCap system.
6+
#' This string will be used to search through a REDCap custodian
7+
#' credentials database to locate the `token` and `redcap_uri`
8+
#' @param server_short_name an optional name of the server that
9+
#' houses the REDCap project of interest. This will prevent
10+
#' project PID clashes.
11+
#'
12+
#' @return a dataframe of data write from a REDCap project
13+
#' @export
14+
#' @importFrom rlang .data
15+
#' @examples
16+
#' \dontrun{
17+
#' library(redcapcustodian)
18+
#' library(DBI)
19+
#'
20+
#' dotenv::load_dot_env("testing.env")
21+
#' init_etl("dummy")
22+
#'
23+
#' support_data <- write_project_data(
24+
#' conn = DBI::dbConnect(RSQLite::SQLite(), Sys.getenv("CREDENTIALS_DB")),
25+
#' project_pid = Sys.getenv("MY_PROJECT_PID"))
26+
#' }
27+
write_project_data <- function(..., conn, project_pid, server_short_name = as.character(NA)) {
28+
redcap_credentials <- dplyr::tbl(conn, "credentials") |>
29+
dplyr::filter(.data$project_id == project_pid) |>
30+
dplyr::filter(is.na(server_short_name) | .data$server_short_name == server_short_name) |>
31+
dplyr::collect()
32+
33+
# Get the data from the REDCap Project
34+
data_write <- REDCapR::redcap_write(
35+
redcap_uri = redcap_credentials$redcap_uri,
36+
token = redcap_credentials$token,
37+
batch_size = 2000,
38+
...
39+
)
40+
41+
return(data_write)
42+
}

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.18.0
1+
1.19.0

man/read_project_data.Rd

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/read_project_metadata.Rd

+45
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/write_project_data.Rd

+45
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)