Skip to content

Commit

Permalink
return tibble instead of a 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 2561267 commit d9a5013
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
8 changes: 4 additions & 4 deletions R/redcap-log-read.R
@@ -1,7 +1,7 @@
#' @title Get the logging of a project.
#'
#' @description This function reads the available logging messages from
#' REDCap an returns them as a [base::data.frame()].
#' REDCap as a [tibble::tibble()].
#'
#' @param redcap_uri The
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
Expand Down Expand Up @@ -39,7 +39,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`: An R [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 @@ -168,7 +168,7 @@ redcap_log_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 log export failed. The http status code was %i. The 'raw_text' returned was '%s'.",
kernel$status_code,
Expand All @@ -177,7 +177,7 @@ redcap_log_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 log export operation was not successful. The returned dataset was empty." # nocov
} else {
Expand Down
6 changes: 3 additions & 3 deletions R/redcap-report.R
Expand Up @@ -39,7 +39,7 @@
#' `httr` package. See the details below. Optional.
#'
#' @return Currently, a list is returned with the following elements:
#' * `data`: An R [base::data.frame()] of the desired records and columns.
#' * `data`: A [tibble::tibble()] of the desired records and columns.
#' * `success`: A boolean value indicating if the operation was apparently
#' successful.
#' * `status_code`: The
Expand Down Expand Up @@ -202,7 +202,7 @@ redcap_report <- 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() # Return an empty data.frame
outcome_message <- sprintf(
"The REDCap report failed. The http status code was %i. The 'raw_text' returned was '%s'.",
kernel$status_code,
Expand All @@ -211,7 +211,7 @@ redcap_report <- 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 report operation was not successful. The returned dataset was empty." # nocov
} else {
Expand Down
4 changes: 2 additions & 2 deletions man/redcap_log_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_report.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-log-read.R
Expand Up @@ -38,6 +38,8 @@ test_that("2020-08-10", {
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("2020-08-10-api-export", {
Expand All @@ -64,6 +66,8 @@ test_that("2020-08-10-api-export", {
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("2021-07-11-record3-user", {
testthat::skip_on_cran()
Expand Down Expand Up @@ -91,6 +95,8 @@ test_that("2021-07-11-record3-user", {
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")
})

rm(credential)
10 changes: 10 additions & 0 deletions tests/testthat/test-report.R
Expand Up @@ -37,6 +37,8 @@ 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("col_types", {
testthat::skip_on_cran()
Expand Down Expand Up @@ -70,6 +72,8 @@ test_that("col_types", {
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("force-character-type", {
testthat::skip_on_cran()
Expand All @@ -95,6 +99,8 @@ test_that("force-character-type", {
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("raw", {
testthat::skip_on_cran()
Expand All @@ -120,6 +126,8 @@ test_that("raw", {
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")
})
# This test is removed because the vroom version adds digits to make the columns unique
# test_that("label-header", {
Expand Down Expand Up @@ -173,6 +181,8 @@ test_that("export_checkbox_label", {
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 token -Error", {
Expand Down

0 comments on commit d9a5013

Please sign in to comment.