diff --git a/R/teal_data-class.R b/R/teal_data-class.R index 0fc0dd487..1a3efbee0 100644 --- a/R/teal_data-class.R +++ b/R/teal_data-class.R @@ -44,14 +44,17 @@ setClass( #' @param data (`named list`) List of data. #' @param code (`character` or `language`) code to reproduce the `data`. #' Accepts and stores comments also. -#' @param keys (`JoinKeys`) object +#' @param join_keys (`JoinKeys`) object #' @param datanames (`character`) names of datasets passed to `data`. #' Needed when non-dataset objects are needed in the `env` slot. #' @rdname new_teal_data #' @keywords internal -new_teal_data <- function(data, code = character(0), keys = join_keys(), datanames = names(data)) { +new_teal_data <- function(data, + code = character(0), + join_keys = join_keys(), + datanames = union(names(data), names(join_keys$get()))) { checkmate::assert_list(data) - checkmate::assert_class(keys, "JoinKeys") + checkmate::assert_class(join_keys, "JoinKeys") checkmate::assert_character(datanames) if (!any(is.language(code), is.character(code))) { stop("`code` must be a character or language object.") @@ -68,7 +71,7 @@ new_teal_data <- function(data, code = character(0), keys = join_keys(), datanam warnings = "", messages = "", id = sample.int(.Machine$integer.max, size = 1L), - join_keys = keys, + join_keys = join_keys, datanames = datanames ) } diff --git a/R/teal_data.R b/R/teal_data.R index 3bfbd9137..594f435e0 100644 --- a/R/teal_data.R +++ b/R/teal_data.R @@ -40,7 +40,11 @@ teal_data <- function(..., join_keys <- teal.data::join_keys(join_keys) } if ( - checkmate::test_list(data_objects, types = c("TealDataConnector", "TealDataset", "TealDatasetConnector")) + checkmate::test_list( + data_objects, + types = c("TealDataConnector", "TealDataset", "TealDatasetConnector"), + min.len = 1 + ) ) { lifecycle::deprecate_warn( when = "0.3.1", @@ -59,13 +63,13 @@ teal_data <- function(..., x$check_metadata() x } else { - if (!checkmate::test_names(names(data_objects), type = "named")) { + if (length(data_objects) > 0 && !checkmate::test_names(names(data_objects), type = "named")) { stop("Dot (`...`) arguments on `teal_data()` must be named.") } new_teal_data( data = data_objects, code = code, - keys = join_keys + join_keys = join_keys ) } } diff --git a/man/new_teal_data.Rd b/man/new_teal_data.Rd index 47ec8027f..1191cebc5 100644 --- a/man/new_teal_data.Rd +++ b/man/new_teal_data.Rd @@ -7,8 +7,8 @@ new_teal_data( data, code = character(0), - keys = join_keys(), - datanames = names(data) + join_keys = join_keys(), + datanames = union(names(data), names(join_keys$get())) ) } \arguments{ @@ -17,7 +17,7 @@ new_teal_data( \item{code}{(\code{character} or \code{language}) code to reproduce the \code{data}. Accepts and stores comments also.} -\item{keys}{(\code{JoinKeys}) object} +\item{join_keys}{(\code{JoinKeys}) object} \item{datanames}{(\code{character}) names of datasets passed to \code{data}. Needed when non-dataset objects are needed in the \code{env} slot.} diff --git a/tests/testthat/helper-get_join_keys.R b/tests/testthat/helper-get_join_keys.R index 8b55e5091..34bca8a9e 100644 --- a/tests/testthat/helper-get_join_keys.R +++ b/tests/testthat/helper-get_join_keys.R @@ -9,7 +9,7 @@ helper_generator_teal_data <- function() { ds2 = iris2 ), code = "ds1 <- iris2; ds2 <- iris2", - keys = helper_generator_JoinKeys("ds1", keys = c("id")) + join_keys = helper_generator_JoinKeys("ds1", keys = c("id")) ) } diff --git a/tests/testthat/test-TealDatasetConnector.R b/tests/testthat/test-TealDatasetConnector.R index c26744e02..cc66f6e92 100644 --- a/tests/testthat/test-TealDatasetConnector.R +++ b/tests/testthat/test-TealDatasetConnector.R @@ -564,7 +564,7 @@ testthat::test_that("code_dataset_connector - library calls", { label = "ADRS dataset" ) - data <- cdisc_data(adsl, adtte, adrs, check = TRUE) + expect_warning(data <- cdisc_data(adsl, adtte, adrs, check = TRUE), "deprecated") expect_silent( lapply( data$get_items(),