diff --git a/.lintr b/.lintr index 62b3fc4f4..3377b6466 100644 --- a/.lintr +++ b/.lintr @@ -1,5 +1,4 @@ linters: linters_with_defaults( line_length_linter = line_length_linter(120), - object_usage_linter = NULL, - cyclocomp_linter = NULL + object_usage_linter = NULL ) diff --git a/DESCRIPTION b/DESCRIPTION index 86815b6b0..64e17184c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,7 +29,7 @@ URL: https://insightsengineering.github.io/teal.data/, BugReports: https://github.com/insightsengineering/teal.data/issues Depends: R (>= 4.0), - teal.code (>= 0.6.0) + teal.code (>= 0.6.1.9002), Imports: checkmate (>= 2.1.0), lifecycle (>= 0.2.0), @@ -45,6 +45,8 @@ Suggests: VignetteBuilder: knitr, rmarkdown +Remotes: + insightsengineering/teal.code@main RdMacros: lifecycle Config/Needs/verdepcheck: insightsengineering/teal.code, mllg/checkmate, diff --git a/NEWS.md b/NEWS.md index 63d1ec75e..5ca356932 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # teal.data 0.7.0.9003 +### Breaking changes + +* Print of a `teal_data` object now shows "code (un)verified" instead of "(un)verified teal_data object". + # teal.data 0.7.0 ### Breaking changes diff --git a/R/join_keys-utils.R b/R/join_keys-utils.R index 7ace0e74f..da084e972 100644 --- a/R/join_keys-utils.R +++ b/R/join_keys-utils.R @@ -39,8 +39,7 @@ assert_compatible_keys <- function(join_key_1, join_key_2) { } } - # otherwise they are compatible - return(TRUE) + TRUE # otherwise they are compatible } #' Validate parent-child key diff --git a/R/teal_data-class.R b/R/teal_data-class.R index 46baa004b..d571dc321 100644 --- a/R/teal_data-class.R +++ b/R/teal_data-class.R @@ -26,7 +26,7 @@ setOldClass("join_keys") #' Access or modify with [join_keys()]. #' @slot verified (`logical(1)`) flag signifying that code in `@code` has been #' proven to yield contents of `@.xData`. -#' Used internally. See [`verify()`] for more details. +#' Used internally. See [`teal.data::verify()`] for more details. #' #' @inheritSection teal.code::`qenv-class` Code #' @@ -35,11 +35,7 @@ setOldClass("join_keys") setClass( Class = "teal_data", contains = "qenv", - slots = c(join_keys = "join_keys", verified = "logical"), - prototype = list( - join_keys = join_keys(), - verified = logical(0) - ) + slots = c(join_keys = "join_keys", verified = "logical") ) #' It initializes the `teal_data` class @@ -50,13 +46,12 @@ setClass( setMethod( "initialize", "teal_data", - function(.Object, .xData = list(), join_keys = join_keys(), code = list(), ...) { # nolint: object_name. - # Allow .xData to be a list and convert it to an environment - if (!missing(.xData) && inherits(.xData, "list")) { - .xData <- rlang::env_clone(list2env(.xData), parent = parent.env(.GlobalEnv)) # nolint: object_name. - lockEnvironment(.xData, bindings = TRUE) - } + function(.Object, .xData, join_keys, code, ...) { # nolint: object_name. + if (missing(.xData)) .xData <- new.env() # nolint: object_name. + if (missing(join_keys)) join_keys <- teal.data::join_keys() + if (missing(code)) code <- character(0L) args <- list(...) + checkmate::assert_environment(.xData) checkmate::assert_class(join_keys, "join_keys") checkmate::assert_list(args, names = "named") @@ -67,15 +62,12 @@ setMethod( if (is.language(code)) { code <- paste(lang2calls(code), collapse = "\n") } - if (length(code)) { - code <- paste(code, collapse = "\n") - } methods::callNextMethod( .Object, .xData, join_keys = join_keys, - verified = (length(args$code) == 0L && length(.xData) == 0L), + verified = (length(code) == 0L && length(.xData) == 0L), code = code2list(code), ... ) @@ -97,6 +89,7 @@ code2list <- function(code) { if (length(code) == 0) { return(list()) } + code <- paste(code, collapse = "\n") parsed_code <- parse(text = code, keep.source = TRUE) diff --git a/R/teal_data-constructor.R b/R/teal_data-constructor.R index 25a705342..2c308f723 100644 --- a/R/teal_data-constructor.R +++ b/R/teal_data-constructor.R @@ -48,13 +48,12 @@ teal_data <- function(..., if (inherits(join_keys, "join_key_set")) { join_keys <- teal.data::join_keys(join_keys) } - if (length(data_objects) > 0 && !checkmate::test_names(names(data_objects), type = "named")) { stop("Dot (`...`) arguments on `teal_data()` must be named.") } methods::new( "teal_data", - .xData = data_objects, + .xData = list2env(data_objects), code = code, join_keys = join_keys ) diff --git a/R/teal_data-show.R b/R/teal_data-show.R index 4ce54d8b8..96f10acc2 100644 --- a/R/teal_data-show.R +++ b/R/teal_data-show.R @@ -12,9 +12,9 @@ #' @export setMethod("show", signature = "teal_data", function(object) { if (object@verified) { - cat("\u2705\ufe0e", "verified teal_data object\n") + cat("\u2705\ufe0e", "code verified\n") } else { - cat("\u2716", "unverified teal_data object\n") + cat("\u2716", "code unverified\n") } methods::callNextMethod(object) invisible(object) diff --git a/R/topological_sort.R b/R/topological_sort.R index 413878373..7d7f65e54 100644 --- a/R/topological_sort.R +++ b/R/topological_sort.R @@ -50,7 +50,7 @@ topological_sort <- function(graph) { paste0(setdiff(names(in_degrees), sorted), collapse = " ") ) } else { - return(sorted) + sorted } } diff --git a/man/teal_data.Rd b/man/teal_data.Rd index a53804d60..e7cf04588 100644 --- a/man/teal_data.Rd +++ b/man/teal_data.Rd @@ -41,7 +41,7 @@ A \code{teal_data} is meant to be used for reproducibility purposes. The class i \item It inherits from the environment and methods such as \code{\link{$}}, \code{\link[=get]{get()}}, \code{\link[=ls]{ls()}}, \code{\link[=as.list]{as.list()}}, \code{\link[=parent.env]{parent.env()}} work out of the box. \item \code{teal_data} is a locked environment, and data modification is only possible through the -\code{\link[teal.code:eval_code]{teal.code::eval_code()}} and \code{\link[teal.code:eval_code]{within.qenv()}} functions. +\code{\link[teal.code:eval_code]{teal.code::eval_code()}} and \code{\link[teal.code:within.qenv]{within.qenv()}} functions. \item It stores metadata about the code used to create the data (see \code{\link[=get_code,teal_data-method]{get_code()}}). \item It supports slicing (see \code{\link[teal.code:subset-qenv]{teal.code::subset-qenv}}) \item Is immutable which means that each code evaluation does not modify the original \code{teal_data}