Skip to content

Commit

Permalink
dag returns a tibble
Browse files Browse the repository at this point in the history
ref #415
  • Loading branch information
wibeasley committed Aug 28, 2022
1 parent 6147117 commit 31cb13e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Upcoming Release
==========================================================

### Possibly Breaking Changes

* `redcap_read()`, `redcap_read_oneshot()`, `redcap_dag_read()`, `redcap_log_read()` and `redcap_report()` return a tibble instead of a data.frame. (#415)

This should affect client code only if you expect a call like `ds[, 3]` to return a vector instead of a single-column data.frame/tibble. One solution is to upcast the tibble to a data.frame (with something like `as.data.frame()`). We recommend using an approach that works for both data.frames and tibbles, such as `ds[[3]]` or `dplyr::pull(ds, "gender")`.

### New Features

* New `redcap_log_read()` function. Exports a project's log. (Thanks @joundso, #383, #320)
Expand Down
3 changes: 1 addition & 2 deletions R/redcap-dag-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ redcap_dag_read <- function(
file = I(kernel$raw_text),
locale = locale,
show_col_types = FALSE
) %>%
as.data.frame(),
),

# Don't print the warning in the try block. Print it below,
# where it's under the control of the caller.
Expand Down
19 changes: 14 additions & 5 deletions tests/testthat/test-dag-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ test_that("smoke", {
test_that("dag-default", {
testthat::skip_on_cran()
expected_data <-
structure(list(data_access_group_name = c("dag_1", "dag_2"),
structure(
list(data_access_group_name = c("dag_1", "dag_2"),
unique_group_name = c("dag_1", "dag_2")), row.names = c(NA,
-2L), class = "data.frame"
-2L), spec = structure(list(cols = list(data_access_group_name = structure(list(), class = c("collector_character",
"collector")), unique_group_name = structure(list(), class = c("collector_character",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = ","), class = "col_spec"), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame")
)
expect_message(
actual <- redcap_dag_read(
Expand All @@ -36,9 +41,13 @@ test_that("dag-default", {
test_that("dag-default", {
testthat::skip_on_cran()
expected_data <-
structure(list(data_access_group_name = character(0),
unique_group_name = character(0)), row.names = integer(0),
class = "data.frame"
structure(
list(data_access_group_name = character(0), unique_group_name = character(0)), row.names = integer(0), spec = structure(list(
cols = list(data_access_group_name = structure(list(), class = c("collector_character",
"collector")), unique_group_name = structure(list(), class = c("collector_character",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = ","), class = "col_spec"), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame")
)

expect_message(
Expand Down

0 comments on commit 31cb13e

Please sign in to comment.