Skip to content

Commit

Permalink
return tibble instead of data.frame
Browse files Browse the repository at this point in the history
ref #415
  • Loading branch information
wibeasley committed Aug 30, 2022
1 parent 0c75c6e commit b9db5de
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 122 deletions.
23 changes: 18 additions & 5 deletions R/redcap-users-export.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@
#' @param config_options A list of options to pass to `POST` method in the
#' `httr` package. See the details below. Optional.
#'
#' @return a [utils::packageDescription].
#' @return Currently, a list is returned with the following elements:
#' * `data_user`: A [tibble::tibble()] of all users associated with the project.
#' One row represents one user.
#' * `data_user_form`: A [tibble::tibble()] of permissions for users and forms.
#' One row represents a unqiue user-by-form combination.
#' * `success`: A boolean value indicating if the operation was apparently
#' successful.
#' * `status_codes`: A collection of
#' [http status codes](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes),
#' separated by semicolons. There is one code for each batch attempted.
#' * `outcome_messages`: A collection of human readable strings indicating the
#' operations' semicolons. There is one code for each batch attempted. In an
#' unsuccessful operation, it should contain diagnostic information.
#' * `elapsed_seconds`: The duration of the function.
#'
#' @note
#' **Documentation in REDCap 8.4.0**
Expand Down Expand Up @@ -159,8 +172,8 @@ redcap_users_export <- function(
} else {
# nocov start
kernel$success <- FALSE # Override the 'success' http status code.
ds_user <- data.frame() # Return an empty data.frame
ds_user_form <- data.frame() # Return an empty data.frame
ds_user <- tibble::tibble() # Return an empty data.frame
ds_user_form <- tibble::tibble() # Return an empty data.frame
outcome_message <- sprintf(
"The REDCap user export failed. The http status code was %i. The 'raw_text' returned was '%s'.",
kernel$status_code,
Expand All @@ -169,8 +182,8 @@ redcap_users_export <- function(
# nocov end
}
} else {
ds_user <- data.frame() # Return an empty data.frame
ds_user_form <- data.frame() # Return an empty data.frame
ds_user <- tibble::tibble() # Return an empty data.frame
ds_user_form <- tibble::tibble() # Return an empty data.frame
outcome_message <- sprintf(
"The REDCap user export failed. The error message was:\n%s",
kernel$raw_text
Expand Down
6 changes: 3 additions & 3 deletions R/redcap-variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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 @@ -109,7 +109,7 @@ redcap_variables <- 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 @@ -119,7 +119,7 @@ redcap_variables <- 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 variables) was empty."
} else {
Expand Down
113 changes: 1 addition & 112 deletions man/redcap_read_oneshot.Rd

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

17 changes: 16 additions & 1 deletion man/redcap_users_export.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_variables.Rd

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

6 changes: 6 additions & 0 deletions tests/testthat/test-users-export.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ test_that("with-dags", {
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_user , "tbl")
expect_s3_class(returned_object$data_user_form , "tbl")
})
test_that("without DAGs", {
testthat::skip_on_cran()
Expand All @@ -61,6 +64,9 @@ test_that("without DAGs", {
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_user , "tbl")
expect_s3_class(returned_object$data_user_form , "tbl")
})
test_that("bad token -Error", {
testthat::skip_on_cran()
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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")
})


Expand Down

0 comments on commit b9db5de

Please sign in to comment.