Skip to content

Commit a54fc0f

Browse files
committed
Merge branch 'release/1.20.0'
2 parents aeb2f7b + 998c48b commit a54fc0f

12 files changed

+106
-268
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.19.0
4+
Version: 1.20.0
55
Authors@R: c(
66
person("Philip", "Chase",
77
email = "pbc@ufl.edu",

NAMESPACE

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export(get_institutional_person_data)
2424
export(get_job_duration)
2525
export(get_package_scope_var)
2626
export(get_project_life_cycle)
27+
export(get_redcap_credentials)
2728
export(get_redcap_db_connection)
2829
export(get_redcap_email_revisions)
2930
export(get_redcap_emails)
@@ -40,8 +41,6 @@ export(log_job_failure)
4041
export(log_job_success)
4142
export(mutate_columns_to_posixct)
4243
export(quit_non_interactive_run)
43-
export(read_project_data)
44-
export(read_project_metadata)
4544
export(scrape_user_api_tokens)
4645
export(send_email)
4746
export(set_package_scope_var)
@@ -59,7 +58,6 @@ export(update_redcap_email_addresses)
5958
export(write_allocations)
6059
export(write_error_log_entry)
6160
export(write_info_log_entry)
62-
export(write_project_data)
6361
export(write_summary_metrics)
6462
export(write_to_sql_db)
6563
importFrom(magrittr,"%>%")

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# redcapcustodian 1.20.0 (released 2024-02-28)
2+
- Add get_redcap_credentials() (@ljwoodley, #149, #151)
3+
- Revert "add redcap wrapper functions" (@ljwoodley, #149, #150)
4+
15
# redcapcustodian 1.19.0 (released 2024-01-30)
26
- Add REDCapR wrapper functions (@ljwoodley, #147, #148)
37

R/get_redcap_credentials.R

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#' Retrieve REDCap Credentials Based on Specified Parameters
2+
#'
3+
#' Fetches REDCap credentials from the CREDENTIALS_DB, allowing filtering based on
4+
#' project ID, server short name, project short name, and username. At least one filtering
5+
#' criterion must be provided.
6+
#'
7+
#' @param project_pid Optional project ID for filtering.
8+
#' @param server_short_name Optional server short name for filtering.
9+
#' @param project_short_name Optional project short name for filtering.
10+
#' @param username Optional username for filtering.
11+
#'
12+
#' @return A dataframe of filtered REDCap credentials, including a 'url' column added for convenience.
13+
#'
14+
#' @examples
15+
#' \dontrun{
16+
#' source_credentials <- get_redcap_credentials(project_pid = "123")
17+
#' prod_credentials <- get_redcap_credentials(server_short_name = "prod")
18+
#' target_credentials <- prod_credentials |>
19+
#' filter(str_detect(project_name, "biospecimens"))
20+
#' }
21+
#'
22+
#' @export
23+
#'
24+
get_redcap_credentials <- function(project_pid = NA,
25+
server_short_name = NA,
26+
project_short_name = NA,
27+
username = NA) {
28+
29+
# Verify that there is at least one parameter
30+
if (
31+
all(is.na(
32+
c(
33+
server_short_name,
34+
username,
35+
project_pid,
36+
project_short_name
37+
)
38+
))
39+
) {
40+
stop("At least one parameter must be defined")
41+
}
42+
43+
credentials_conn <- DBI::dbConnect(RSQLite::SQLite(), Sys.getenv("CREDENTIALS_DB"))
44+
45+
redcap_credentials <- dplyr::tbl(credentials_conn, "credentials") |>
46+
# Filter on any non-NA parameter
47+
# Parameters have to be localized so that will not be seen as columns in the data frame
48+
dplyr::filter(is.na(!!project_pid) | .data$project_id == !!project_pid) |>
49+
dplyr::filter(is.na(!!server_short_name) | .data$server_short_name == !!server_short_name) |>
50+
dplyr::filter(is.na(!!project_short_name) | .data$project_short_name == !!project_short_name) |>
51+
dplyr::filter(is.na(!!username) | .data$username == !!username) |>
52+
dplyr::collect() |>
53+
# Make a copy of redcap_uri to make redcapAPI coding a tiny bit simpler
54+
dplyr::mutate(url = .data$redcap_uri)
55+
56+
DBI::dbDisconnect(credentials_conn)
57+
58+
return(redcap_credentials)
59+
}
60+

R/read_project_data.R

-46
This file was deleted.

R/read_project_metadata.R

-45
This file was deleted.

R/write_project_data.R

-42
This file was deleted.

VERSION

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

man/get_redcap_credentials.Rd

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

man/read_project_data.Rd

-40
This file was deleted.

man/read_project_metadata.Rd

-45
This file was deleted.

0 commit comments

Comments
 (0)