Skip to content

Commit

Permalink
replace sapply with vapply
Browse files Browse the repository at this point in the history
ref #280
  • Loading branch information
wibeasley committed Dec 4, 2019
1 parent 8c1bafa commit 67f1639
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions R/redcap-read-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ redcap_read_oneshot <- function(
if (exists("ds") & inherits(ds, "data.frame")) {
outcome_message <- sprintf(
"%s records and %s columns were read from REDCap in %0.1f seconds. The http status code was %i.",
format( nrow(ds), big.mark = ",", scientific = F, trim = TRUE),
format(length(ds), big.mark = ",", scientific = F, trim = TRUE),
format( nrow(ds), big.mark = ",", scientific = FALSE, trim = TRUE),
format(length(ds), big.mark = ",", scientific = FALSE, trim = TRUE),
kernel$elapsed_seconds,
kernel$status_code
)
Expand Down
2 changes: 1 addition & 1 deletion R/validate.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ validate_for_write <- function(d) {
checkmate::assert_data_frame(d, any.missing = FALSE)

lst_concerns <- list(
validate_no_logical(sapply(d, class)),
validate_no_logical(vapply(d, class, character(1))),
validate_field_names(colnames(d))
)

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-validate.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ test_that("validate_for_write_no_errors", {

test_that("validate_field_names -stop on error", {
expect_error(
validate_no_logical(sapply(ds_bad, class), stop_on_error = TRUE),
validate_no_logical(vapply(ds_bad, class, character(1)), stop_on_error = TRUE),
"1 field\\(s\\) were logical/boolean. The REDCap API does not automatically convert boolean values to 0/1 values. Convert the variable with the `as.integer\\(\\)` function."
)
})

test_that("validate_no_logical -concern dataset", {
ds <- validate_no_logical(sapply(ds_bad, class))
ds <- validate_no_logical(vapply(ds_bad, class, character(1)))
expect_equal(object=nrow(ds), expected=1, info="One logical field should be flagged")
expect_equal(object=ds$field_name, expected="bad_logical")
expect_equal(object=ds$field_index, expected=2)
Expand Down

0 comments on commit 67f1639

Please sign in to comment.