Skip to content

Commit

Permalink
returning tibbles instead of data.frames
Browse files Browse the repository at this point in the history
ref #415
  • Loading branch information
wibeasley committed Aug 30, 2022
1 parent f722a4a commit 0c75c6e
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 15 deletions.
8 changes: 4 additions & 4 deletions R/redcap-dag-read.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @title Read data access groups from a REDCap project
#'
#' @description This function reads all available data access groups from
#' REDCap an returns them as a [base::data.frame()].
#' REDCap an returns them as a [tibble::tibble()].
#'
#' @param redcap_uri The
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
Expand All @@ -23,7 +23,7 @@
#' `httr` package.
#'
#' @return Currently, a list is returned with the following elements:
#' * `data`: An R [base::data.frame()] of all data access groups of the project.
#' * `data`: A [tibble::tibble()] of all data access groups of the project.
#' * `success`: A boolean value indicating if the operation was apparently
#' successful.
#' * `status_codes`: A collection of
Expand Down Expand Up @@ -117,7 +117,7 @@ redcap_dag_read <- function(
# Override the 'success' determination from the http status code.
# and return an empty data.frame.
kernel$success <- FALSE
ds <- data.frame()
ds <- tibble::tibble()
outcome_message <- sprintf(
"The REDCap read failed. The http status code was %i. The 'raw_text' returned was '%s'.",
kernel$status_code,
Expand All @@ -126,7 +126,7 @@ redcap_dag_read <- function(
# nocov end
}
} else { # kernel fails
ds <- data.frame() #Return an empty data.frame
ds <- tibble::tibble() # Return an empty data.frame
outcome_message <- if (any(grepl(kernel$regex_empty, kernel$raw_text))) {
"The REDCapR read/export operation was not successful. The returned dataset was empty." # nocov
} else {
Expand Down
6 changes: 3 additions & 3 deletions R/redcap-event-instruments.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' `httr` package. See the details below. Optional.
#'
#' @return Currently, a list is returned with the following elements,
#' * `data`: An R [base::data.frame()] where each row represents one column
#' * `data`: A [tibble::tibble()] where each row represents one column
#' in the REDCap dataset.
#' * `success`: A boolean value indicating if the operation was apparently
#' successful.
Expand Down Expand Up @@ -119,7 +119,7 @@ redcap_event_instruments <- function(
} else {
# nocov start
kernel$success <- FALSE # Override the 'success' http status code.
ds <- data.frame() #Return an empty data.frame
ds <- tibble::tibble() # Return an empty data.frame

outcome_message <- sprintf(
"The REDCap variable retrieval failed. The http status code was %i. The 'raw_text' returned was '%s'.",
Expand All @@ -129,7 +129,7 @@ redcap_event_instruments <- function(
# nocov end
}
} else {
ds <- data.frame() #Return an empty data.frame
ds <- tibble::tibble() # Return an empty data.frame
outcome_message <- if (any(grepl(kernel$regex_empty, kernel$raw_text))) {
"The REDCapR read/export operation was not successful. The returned dataset (of instrument-events) was empty."
} else {
Expand Down
6 changes: 3 additions & 3 deletions R/redcap-instruments.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' `httr` package. See the details below. Optional.
#'
#' @return Currently, a list is returned with the following elements,
#' * `data`: An R [base::data.frame()] where each row represents one column
#' * `data`: A [tibble::tibble()] where each row represents one column
#' in the REDCap dataset.
#' * `success`: A boolean value indicating if the operation was apparently
#' successful.
Expand Down Expand Up @@ -118,7 +118,7 @@ redcap_instruments <- function(
} else {
# nocov start
kernel$success <- FALSE # Override the 'success' http status code.
ds <- data.frame() #Return an empty data.frame
ds <- tibble::tibble() # Return an empty data.frame

outcome_message <- sprintf(
"The REDCap variable retrieval failed. The http status code was %i. The 'raw_text' returned was '%s'.",
Expand All @@ -128,7 +128,7 @@ redcap_instruments <- function(
# nocov end
}
} else {
ds <- data.frame() #Return an empty data.frame
ds <- tibble::tibble() # Return an empty data.frame
outcome_message <- if (any(grepl(kernel$regex_empty, kernel$raw_text))) {
"The REDCapR read/export operation was not successful. The returned dataset (of instruments) was empty."
} else {
Expand Down
4 changes: 2 additions & 2 deletions man/redcap_dag_read.Rd

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

2 changes: 1 addition & 1 deletion man/redcap_event_instruments.Rd

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

2 changes: 1 addition & 1 deletion man/redcap_instruments.Rd

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

113 changes: 112 additions & 1 deletion man/redcap_read_oneshot.Rd

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

2 changes: 2 additions & 0 deletions tests/testthat/test-dag-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ test_that("dag-default", {
expect_true( actual$success)
expect_equal(actual$status_code, 200L)
expect_equal(actual$data, expected_data)
expect_s3_class(actual$data, "tbl")
})

test_that("dag-default", {
Expand All @@ -60,6 +61,7 @@ test_that("dag-default", {
expect_true( actual$success)
expect_equal(actual$status_code, 200L)
expect_equal(actual$data, expected_data)
expect_s3_class(actual$data, "tbl")
})

rm(credential_1)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-event-instruments.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ test_that("default", {
expect_equal(returned_object$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object$raw_text)
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_true(returned_object$success)
expect_s3_class(returned_object$data, "tbl")
})

test_that("Bad URI", {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-instruments-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ test_that("default", {
expect_equal(returned_object$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object$raw_text)
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_true(returned_object$success)
expect_s3_class(returned_object$data, "tbl")
})

test_that("Bad URI", {
Expand Down

0 comments on commit 0c75c6e

Please sign in to comment.