Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation #522

Merged
merged 22 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Suggests:
License: MIT + file LICENSE
VignetteBuilder: knitr
Encoding: UTF-8
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
Config/testthat/edition: 3
Language: en-US
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ This will help extract forms from longitudinal & repeating projects.

* `redcap_event_instruments()` now by default returns mappings for all arms. The previous default was to return the mappings for only the first arm. To recreate the previous behavior use a call like `REDCapR::redcap_event_instruments(uri, token_2, arms = "1")`. (Suggested by @januz, #482)

* `redcap_users_export()` used to return a boolean for `user_rights`, but now it can be 0, 1, or 2. (#523)

### New Features

* New `redcap_metadata_coltypes()` function. Inspects the fields types and validation text of each field to generate a suggested `readr::col_types` object that reflects the project's current data dictionary. The object then can be passed to the `col_types` parameter of `redcap_read()` or `redcap_read_oneshot()`. (Suggested and discussed with @pbchase, @nutterb, @skadauke, & others, #405 & #294)
Expand Down Expand Up @@ -90,6 +92,7 @@ This will help extract forms from longitudinal & repeating projects.
* `validate_no_logical()`
* `redcap_read()` checks the `event` parameter and throws an error if a value is not recognized, or the project is not longitudinal (#493)
* The regex in `regex_named_captures()` is forgiving if there's an unnecessary leading space (@BlairCooper, #495, #501)
* `redcap_log_read()` assumes all columns are character, except for `timestamp` (#525)

Version 1.1.0 (released 2022-08-10)
==========================================================
Expand Down
14 changes: 7 additions & 7 deletions R/REDCapR-package.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#' @docType package
#' @keywords internal
"_PACKAGE"

#' @name REDCapR-package
#' @aliases
#' REDCapR
#'
#' @title R utilities for interacting with a REDCap data system
#' <https://www.project-redcap.org/>
#'

## usethis namespace: start
## usethis namespace: end

#' @description
#' Comprehensive documentation is also available at
#' https://ouhscbbmc.github.io/REDCapR/.
Expand Down
7 changes: 7 additions & 0 deletions R/redcap-log-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ redcap_log_read <- function(
user = user
)

col_types <- readr::cols(
timestamp = readr::col_datetime(),
.default = readr::col_character()
)

# This is the important call that communicates with the REDCap server.
kernel <- kernel_api(
redcap_uri = redcap_uri,
Expand All @@ -155,13 +160,15 @@ redcap_log_read <- function(
readr::read_csv(
file = I(kernel$raw_text),
locale = locale,
col_types = col_types,
show_col_types = FALSE
),

# Don't print the warning in the try block. Print it below,
# where it's under the control of the caller.
silent = TRUE
)
# browser()

if (exists("ds") && inherits(ds, "data.frame")) {
outcome_message <- sprintf(
Expand Down
7 changes: 6 additions & 1 deletion R/redcap-read-oneshot-eav.R
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,12 @@ redcap_read_oneshot_eav <- function(
) %>%
dplyr::full_join(ds_possible_checkbox_rows, by=c("record", "field_name", "field_type", "event_id")) %>%
dplyr::mutate(
value = dplyr::if_else(!is.na(.data$field_type) & (.data$field_type == "checkbox"), as.character(!is.na(.data$value)), .data$value)
value =
dplyr::if_else(
!is.na(.data$field_type) & (.data$field_type == "checkbox"),
as.character(!is.na(.data$value)),
as.character(.data$value)
)
)

. <- NULL # For the sake of avoiding an R CMD check note.
Expand Down
2 changes: 1 addition & 1 deletion R/redcap-users-export.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ redcap_users_export <- function(
data_access_group = readr::col_character(),
data_access_group_id = readr::col_character(),
design = readr::col_logical(),
user_rights = readr::col_logical(),
user_rights = readr::col_integer(),
data_access_groups = readr::col_logical(),
# data_export = readr::col_character(), # dropped sometime between 10.5.1 and 12.5.2
reports = readr::col_logical(),
Expand Down
8 changes: 4 additions & 4 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Test environments
1. Local Ubuntu, R 4.2.2
2. Local Win11, R 4.3.1 patched
3. R-hub
1. [Ubuntu Linux, R-release, GCC](https://builder.r-hub.io/status/REDCapR_1.1.9005.tar.gz-746e237d11914129b4410114fbfa2c83)
2. [Fedora Linux, R-devel, clang, gfortran](https://builder.r-hub.io/status/REDCapR_1.1.9005.tar.gz-e695d8a48601419e8059863cc80964b7)
3. [Windows Server](https://builder.r-hub.io/status/REDCapR_1.1.9005.tar.gz-c30d344462dc43a4b03e68a33be664d9)
4. [win-builder](https://win-builder.r-project.org/0u5J1JiksFZg/), development version.
1. [Ubuntu Linux, R-release, GCC](https://builder.r-hub.io/status/REDCapR_1.1.9005.tar.gz-6f45462d131a4ac49833c0c7c014bad0)
2. [Fedora Linux, R-devel, clang, gfortran](https://builder.r-hub.io/status/REDCapR_1.1.9005.tar.gz-2e9560e6fcdb4467af8e9ea8d22c165d)
3. [Windows Server](https://builder.r-hub.io/status/REDCapR_1.1.9005.tar.gz-3ec1ed8fac734d24a16cc5ecf238cf47)
4. [win-builder](https://win-builder.r-project.org/N3n87tj2ky0v/), development version.
5. [GiHub Actions](https://github.com/OuhscBbmc/REDCapR/actions), Ubuntu 22.04 LTS

R CMD check results
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ NIGMS
NotFound
ODBC
OKDHS
ORCID
OSDH
OUHSC
OUHSC's
Expand Down
41 changes: 27 additions & 14 deletions inst/test-data/specific-redcapr/log-read/2020-08-10.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,32 @@ structure(list(timestamp = structure(c(1597087500, 1597087500,
"export_format: CSV, rawOrLabel: raw", "Download data dictionary (API)",
"export_format: CSV, rawOrLabel: raw", "export_format: CSV, rawOrLabel: raw",
"Download data dictionary (API)", "Export REDCap version (API)",
"Export project information (API)"), record = c(NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), row.names = c(NA,
-96L), spec = structure(list(cols = list(timestamp = structure(list(
format = ""), class = c("collector_datetime", "collector"
)), username = structure(list(), class = c("collector_character",
"collector")), action = structure(list(), class = c("collector_character",
"collector")), details = structure(list(), class = c("collector_character",
"collector")), record = structure(list(), class = c("collector_logical",
"collector"))), default = structure(list(), class = c("collector_guess",
"Export project information (API)"), record = c(NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_
)), row.names = c(NA, -96L), spec = structure(list(cols = list(
timestamp = structure(list(format = ""), class = c("collector_datetime",
"collector")), username = structure(list(), class = c("collector_character",
"collector")), action = structure(list(), class = c("collector_character",
"collector")), details = structure(list(), class = c("collector_character",
"collector")), record = structure(list(), class = c("collector_character",
"collector"))), default = structure(list(), class = c("collector_character",
"collector")), delim = ","), class = "col_spec"), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"))
21 changes: 11 additions & 10 deletions inst/test-data/specific-redcapr/log-read/2021-07-11-record3-user.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ structure(list(timestamp = structure(c(1626044880, 1626044880,
"Download file (API)", "Download file (API)", "Download file (API)",
"Download file (API)", "Download file (API)", "Download file (API)",
"Download file (API)", "Download file (API)", "Download file (API)",
"Download file (API)", "Download file (API)"), record = c(NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), row.names = c(NA,
-12L), spec = structure(list(cols = list(timestamp = structure(list(
format = ""), class = c("collector_datetime", "collector"
)), username = structure(list(), class = c("collector_character",
"collector")), action = structure(list(), class = c("collector_character",
"collector")), details = structure(list(), class = c("collector_character",
"collector")), record = structure(list(), class = c("collector_logical",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = ","), class = "col_spec"), class = c("spec_tbl_df",
"Download file (API)", "Download file (API)"), record = c(NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_)), row.names = c(NA, -12L), spec = structure(list(
cols = list(timestamp = structure(list(format = ""), class = c("collector_datetime",
"collector")), username = structure(list(), class = c("collector_character",
"collector")), action = structure(list(), class = c("collector_character",
"collector")), details = structure(list(), class = c("collector_character",
"collector")), record = structure(list(), class = c("collector_character",
"collector"))), default = structure(list(), class = c("collector_character",
"collector")), delim = ","), class = "col_spec"), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"))
21 changes: 11 additions & 10 deletions inst/test-data/specific-redcapr/users-export/with-dags--user.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ structure(list(username = c("unittestphifree", "wbeasleya"),
), firstname = c("Unit Test", "Will"), lastname = c("PHI Free",
"Beasley_A"), expiration = structure(c(NA_real_, NA_real_
), class = "Date"), data_access_group = c("daga", NA), data_access_group_id = c("331",
NA), design = c(FALSE, TRUE), alerts = c(0, 1), user_rights = c(FALSE,
TRUE), data_access_groups = c(FALSE, TRUE), reports = c(FALSE,
TRUE), stats_and_charts = c(FALSE, TRUE), manage_survey_participants = c(TRUE,
NA), design = c(FALSE, TRUE), alerts = c(0, 1), user_rights = 2:1,
data_access_groups = c(FALSE, TRUE), reports = c(FALSE, TRUE
), stats_and_charts = c(FALSE, TRUE), manage_survey_participants = c(TRUE,
TRUE), calendar = c(FALSE, TRUE), data_import_tool = c(FALSE,
TRUE), data_comparison_tool = c(FALSE, TRUE), logging = c(FALSE,
TRUE), file_repository = c(FALSE, TRUE), data_quality_create = c(FALSE,
TRUE), data_quality_execute = c(FALSE, TRUE), api_export = c(TRUE,
TRUE), api_import = c(FALSE, TRUE), mobile_app = c(FALSE,
TRUE), mobile_app_download_data = c(FALSE, TRUE), record_create = c(FALSE,
TRUE), record_rename = c(FALSE, FALSE), record_delete = c(FALSE,
FALSE), lock_records_all_forms = c(FALSE, FALSE), lock_records = c(FALSE,
FALSE), lock_records_customization = c(FALSE, FALSE), forms_export = c("demographics:1",
"demographics:1")), row.names = c(NA, -2L), class = c("tbl_df",
"tbl", "data.frame"))
TRUE), api_import = c(FALSE, TRUE), api_modules = c(0, 0),
mobile_app = c(FALSE, TRUE), mobile_app_download_data = c(FALSE,
TRUE), record_create = c(FALSE, TRUE), record_rename = c(FALSE,
FALSE), record_delete = c(FALSE, FALSE), lock_records_all_forms = c(FALSE,
FALSE), lock_records = c(FALSE, FALSE), lock_records_customization = c(FALSE,
FALSE), forms_export = c("demographics:1", "demographics:1"
)), row.names = c(NA, -2L), class = c("tbl_df", "tbl", "data.frame"
))
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ structure(list(username = c("unittestphifree", "wbeasleya"),
"Beasley_A"), expiration = structure(c(NA_real_, NA_real_
), class = "Date"), data_access_group = c(NA_character_,
NA_character_), data_access_group_id = c(NA_character_, NA_character_
), design = c(FALSE, TRUE), alerts = c(0, 1), user_rights = c(FALSE,
TRUE), data_access_groups = c(FALSE, TRUE), reports = c(TRUE,
TRUE), stats_and_charts = c(TRUE, TRUE), manage_survey_participants = c(TRUE,
), design = c(FALSE, TRUE), alerts = c(0, 1), user_rights = 2:1,
data_access_groups = c(TRUE, TRUE), reports = c(TRUE, TRUE
), stats_and_charts = c(TRUE, TRUE), manage_survey_participants = c(TRUE,
TRUE), calendar = c(TRUE, TRUE), data_import_tool = c(FALSE,
TRUE), data_comparison_tool = c(FALSE, TRUE), logging = c(TRUE,
TRUE), file_repository = c(TRUE, TRUE), data_quality_create = c(FALSE,
TRUE), data_quality_execute = c(FALSE, TRUE), api_export = c(TRUE,
FALSE), api_import = c(FALSE, FALSE), mobile_app = c(FALSE,
FALSE), mobile_app_download_data = c(FALSE, FALSE), record_create = c(TRUE,
TRUE), record_rename = c(FALSE, FALSE), record_delete = c(FALSE,
FALSE), lock_records_all_forms = c(FALSE, FALSE), lock_records = c(FALSE,
FALSE), lock_records_customization = c(FALSE, FALSE), forms_export = c("demographics:1,health:1,race_and_ethnicity:1",
FALSE), api_import = c(FALSE, FALSE), api_modules = c(0,
0), mobile_app = c(FALSE, FALSE), mobile_app_download_data = c(FALSE,
FALSE), record_create = c(TRUE, TRUE), record_rename = c(FALSE,
FALSE), record_delete = c(FALSE, FALSE), lock_records_all_forms = c(FALSE,
FALSE), lock_records = c(FALSE, FALSE), lock_records_customization = c(FALSE,
FALSE), forms_export = c("demographics:1,health:1,race_and_ethnicity:1",
"demographics:1,health:1,race_and_ethnicity:1")), row.names = c(NA,
-2L), class = c("tbl_df", "tbl", "data.frame"))
45 changes: 42 additions & 3 deletions man/REDCapR-package.Rd

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

7 changes: 4 additions & 3 deletions tests/testthat/test-read-batch-plumbing.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ test_that("repeated", {

credential <- retrieve_credential_testing(3181L)
path_expected <- "test-data/specific-redcapr/read-batch-plumbing/repeated.R"
desired_forms <- c("visit_observed_behavior") # Doesn't include the initial "demographics" form.
# desired_forms <- c("visit_observed_behavior") # Doesn't include the initial "demographics" form.
desired_forms <- c("blood_pressure", "laboratory") # Doesn't include the initial "demographics" form.
expected_outcome_message <- "\\d+ records and 13 columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."

returned_object <-
redcap_read(
batch_size = 2,
redcap_uri = credential$redcap_uri,
token = credential$token,
forms = desired_forms,
# forms = desired_forms,
verbose = FALSE
)

Expand All @@ -82,7 +83,7 @@ test_that("repeated", {
expect_true(returned_object$success)
expect_match(returned_object$status_codes, regexp="200", perl=TRUE)
expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.")
expect_equal(returned_object$fields_collapsed, "record_id")
expect_equal(returned_object$fields_collapsed, "")
expect_true(returned_object$filter_logic=="", "A filter was not specified.")
expect_match(returned_object$outcome_messages, regexp=expected_outcome_message, perl=TRUE)
})
2 changes: 2 additions & 0 deletions tests/testthat/test-read-oneshot-eav.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ test_that("raw", {
expect_s3_class(returned_object$data, "tbl")
})
test_that("raw-and-dag", {
testthat::skip("Temporarily turning off DAG on experimental function")
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-oneshot-eav/raw-and-dag.R"
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."
Expand Down Expand Up @@ -121,6 +122,7 @@ test_that("raw-and-dag", {
expect_s3_class(returned_object$data, "tbl")
})
test_that("label-and-dag", {
testthat::skip("Temporarily turning off DAG on experimental function")
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-oneshot-eav/label-and-dag.R"
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."
Expand Down
Loading