Skip to content

Commit f843f10

Browse files
averissimogogonzom7pr
authored
{teal} module returns a teal_report object that extends from teal_data (#370)
# Pull Request Fixes: - insightsengineering/teal#1526 Built on top of: - insightsengineering/teal.reporter#307 - _(#307 will be closed once this PR is stable)_ ### Companion PRs: - insightsengineering/teal#1541 - insightsengineering/teal.code#255 - #370 - insightsengineering/teal.reporter#331 - insightsengineering/teal.modules.general#884 ### Changes description - [x] Cleanup of `teal_data` class to allow for `teal_report` extension - [x] Change the `show()` method to remove reference to `teal_data` specifically --------- Co-authored-by: Dawid Kaledkowski <dawid.kaledkowski@gmail.com> Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com>
1 parent 2d98090 commit f843f10

File tree

9 files changed

+23
-27
lines changed

9 files changed

+23
-27
lines changed

.lintr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
linters: linters_with_defaults(
22
line_length_linter = line_length_linter(120),
3-
object_usage_linter = NULL,
4-
cyclocomp_linter = NULL
3+
object_usage_linter = NULL
54
)

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ URL: https://insightsengineering.github.io/teal.data/,
2929
BugReports: https://github.com/insightsengineering/teal.data/issues
3030
Depends:
3131
R (>= 4.0),
32-
teal.code (>= 0.6.0)
32+
teal.code (>= 0.6.1.9002),
3333
Imports:
3434
checkmate (>= 2.1.0),
3535
lifecycle (>= 0.2.0),
@@ -45,6 +45,8 @@ Suggests:
4545
VignetteBuilder:
4646
knitr,
4747
rmarkdown
48+
Remotes:
49+
insightsengineering/teal.code@main
4850
RdMacros:
4951
lifecycle
5052
Config/Needs/verdepcheck: insightsengineering/teal.code, mllg/checkmate,

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# teal.data 0.7.0.9003
22

3+
### Breaking changes
4+
5+
* Print of a `teal_data` object now shows "code (un)verified" instead of "(un)verified teal_data object".
6+
37
# teal.data 0.7.0
48

59
### Breaking changes

R/join_keys-utils.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ assert_compatible_keys <- function(join_key_1, join_key_2) {
3939
}
4040
}
4141

42-
# otherwise they are compatible
43-
return(TRUE)
42+
TRUE # otherwise they are compatible
4443
}
4544

4645
#' Validate parent-child key

R/teal_data-class.R

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ setOldClass("join_keys")
2626
#' Access or modify with [join_keys()].
2727
#' @slot verified (`logical(1)`) flag signifying that code in `@code` has been
2828
#' proven to yield contents of `@.xData`.
29-
#' Used internally. See [`verify()`] for more details.
29+
#' Used internally. See [`teal.data::verify()`] for more details.
3030
#'
3131
#' @inheritSection teal.code::`qenv-class` Code
3232
#'
@@ -35,11 +35,7 @@ setOldClass("join_keys")
3535
setClass(
3636
Class = "teal_data",
3737
contains = "qenv",
38-
slots = c(join_keys = "join_keys", verified = "logical"),
39-
prototype = list(
40-
join_keys = join_keys(),
41-
verified = logical(0)
42-
)
38+
slots = c(join_keys = "join_keys", verified = "logical")
4339
)
4440

4541
#' It initializes the `teal_data` class
@@ -50,13 +46,12 @@ setClass(
5046
setMethod(
5147
"initialize",
5248
"teal_data",
53-
function(.Object, .xData = list(), join_keys = join_keys(), code = list(), ...) { # nolint: object_name.
54-
# Allow .xData to be a list and convert it to an environment
55-
if (!missing(.xData) && inherits(.xData, "list")) {
56-
.xData <- rlang::env_clone(list2env(.xData), parent = parent.env(.GlobalEnv)) # nolint: object_name.
57-
lockEnvironment(.xData, bindings = TRUE)
58-
}
49+
function(.Object, .xData, join_keys, code, ...) { # nolint: object_name.
50+
if (missing(.xData)) .xData <- new.env() # nolint: object_name.
51+
if (missing(join_keys)) join_keys <- teal.data::join_keys()
52+
if (missing(code)) code <- character(0L)
5953
args <- list(...)
54+
6055
checkmate::assert_environment(.xData)
6156
checkmate::assert_class(join_keys, "join_keys")
6257
checkmate::assert_list(args, names = "named")
@@ -67,15 +62,12 @@ setMethod(
6762
if (is.language(code)) {
6863
code <- paste(lang2calls(code), collapse = "\n")
6964
}
70-
if (length(code)) {
71-
code <- paste(code, collapse = "\n")
72-
}
7365

7466
methods::callNextMethod(
7567
.Object,
7668
.xData,
7769
join_keys = join_keys,
78-
verified = (length(args$code) == 0L && length(.xData) == 0L),
70+
verified = (length(code) == 0L && length(.xData) == 0L),
7971
code = code2list(code),
8072
...
8173
)
@@ -97,6 +89,7 @@ code2list <- function(code) {
9789
if (length(code) == 0) {
9890
return(list())
9991
}
92+
code <- paste(code, collapse = "\n")
10093

10194
parsed_code <- parse(text = code, keep.source = TRUE)
10295

R/teal_data-constructor.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,12 @@ teal_data <- function(...,
4848
if (inherits(join_keys, "join_key_set")) {
4949
join_keys <- teal.data::join_keys(join_keys)
5050
}
51-
5251
if (length(data_objects) > 0 && !checkmate::test_names(names(data_objects), type = "named")) {
5352
stop("Dot (`...`) arguments on `teal_data()` must be named.")
5453
}
5554
methods::new(
5655
"teal_data",
57-
.xData = data_objects,
56+
.xData = list2env(data_objects),
5857
code = code,
5958
join_keys = join_keys
6059
)

R/teal_data-show.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#' @export
1313
setMethod("show", signature = "teal_data", function(object) {
1414
if (object@verified) {
15-
cat("\u2705\ufe0e", "verified teal_data object\n")
15+
cat("\u2705\ufe0e", "code verified\n")
1616
} else {
17-
cat("\u2716", "unverified teal_data object\n")
17+
cat("\u2716", "code unverified\n")
1818
}
1919
methods::callNextMethod(object)
2020
invisible(object)

R/topological_sort.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ topological_sort <- function(graph) {
5050
paste0(setdiff(names(in_degrees), sorted), collapse = " ")
5151
)
5252
} else {
53-
return(sorted)
53+
sorted
5454
}
5555
}
5656

man/teal_data.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)