Skip to content

Commit b3358c1

Browse files
m7prdependabot-preview[bot]github-actions[bot]pawelru
authored
210 depracate datanames in teal.data::get_code (#343)
Part of - insightsengineering/teal.code#210 Companion to - insightsengineering/teal#1388 - insightsengineering/teal.code#214 # Description Deprecates the usage of `datanames` parameter in `teal.data::get_code(datanames)` in favour of `teal.code::get_code(names)`. VBUMP package version locally to something greater than `0.6.1` during testing. ``` r library(teal.data) #> Loading required package: teal.code tdata1 <- within(teal_data(), {a <- 1; b <- 2}) get_code(tdata1) #> [1] "a <- 1\nb <- 2" get_code(tdata1, datanames = "a") #> Warning: The `datanames` argument of `get_code()` is deprecated as of teal.data 0.6.1. #> ℹ Please use the `names` argument of `teal.code::get_code()` instead. #> ℹ The deprecated feature was likely used in the teal.data package. #> Please report the issue at #> <https://github.com/insightsengineering/teal.data/issues>. #> This warning is displayed once every 8 hours. #> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was #> generated. #> [1] "a <- 1" ``` <sup>Created on 2024-10-17 with [reprex v2.1.1](https://reprex.tidyverse.org)</sup> --------- Signed-off-by: Marcin <[email protected]> Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Pawel Rucki <[email protected]>
1 parent 3cfb37d commit b3358c1

File tree

8 files changed

+61
-1369
lines changed

8 files changed

+61
-1369
lines changed

DESCRIPTION

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,5 @@ Collate:
7878
'teal_data.R'
7979
'testhat-helpers.R'
8080
'topological_sort.R'
81-
'utils-get_code_dependency.R'
8281
'verify.R'
8382
'zzz.R'

NEWS.md

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

3+
### Breaking changes
4+
5+
- soft deprecate `datanames` argument of `get_code()`. Use `names` instead.
6+
37
### Enhancements
48

59
- `datanames()`

R/teal_data-get_code.R

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#' Retrieve code from `teal_data` object.
44
#'
55
#' Retrieve code stored in `@code`, which (in principle) can be used to recreate all objects found in `@env`.
6-
#' Use `datanames` to limit the code to one or more of the datasets enumerated in `@datanames`.
6+
#' Use `names` to limit the code to one or more of the datasets enumerated in `@datanames`.
77
#'
88
#' @section Extracting dataset-specific code:
9-
#' When `datanames` is specified, the code returned will be limited to the lines needed to _create_
9+
#' When `names` is specified, the code returned will be limited to the lines needed to _create_
1010
#' the requested datasets. The code stored in the `@code` slot is analyzed statically to determine
1111
#' which lines the datasets of interest depend upon. The analysis works well when objects are created
1212
#' with standard infix assignment operators (see `?assignOps`) but it can fail in some situations.
@@ -23,10 +23,10 @@
2323
#' x <- 0
2424
#' y <- foo(x)
2525
#' })
26-
#' get_code(data, datanames = "y")
26+
#' get_code(data, names = "y")
2727
#' ```
28-
#' `x` has no dependencies, so `get_code(data, datanames = "x")` will return only the second call.\cr
29-
#' `y` depends on `x` and `foo`, so `get_code(data, datanames = "y")` will contain all three calls.
28+
#' `x` has no dependencies, so `get_code(data, names = "x")` will return only the second call.\cr
29+
#' `y` depends on `x` and `foo`, so `get_code(data, names = "y")` will contain all three calls.
3030
#'
3131
#' _Case 2: Some objects are created by a function's side effects._
3232
#' ```r
@@ -39,10 +39,10 @@
3939
#' foo()
4040
#' y <- x
4141
#' })
42-
#' get_code(data, datanames = "y")
42+
#' get_code(data, names = "y")
4343
#' ```
4444
#' Here, `y` depends on `x` but `x` is modified by `foo` as a side effect (not by reassignment)
45-
#' and so `get_code(data, datanames = "y")` will not return the `foo()` call.\cr
45+
#' and so `get_code(data, names = "y")` will not return the `foo()` call.\cr
4646
#' To overcome this limitation, code dependencies can be specified manually.
4747
#' Lines where side effects occur can be flagged by adding "`# @linksto <object name>`" at the end.\cr
4848
#' Note that `within` evaluates code passed to `expr` as is and comments are ignored.
@@ -58,7 +58,7 @@
5858
#' foo() # @linksto x
5959
#' y <- x
6060
#' ")
61-
#' get_code(data, datanames = "y")
61+
#' get_code(data, names = "y")
6262
#' ```
6363
#' Now the `foo()` call will be properly included in the code required to recreate `y`.
6464
#'
@@ -72,7 +72,9 @@
7272
#'
7373
#'
7474
#' @param object (`teal_data`)
75-
#' @param datanames `r lifecycle::badge("experimental")` (`character`) vector of dataset names to return the code for.
75+
#' @param datanames `r lifecycle::badge("deprecated")` (`character`) vector of dataset names to return the code for.
76+
#' For more details see the "Extracting dataset-specific code" section. Use `names` instead.
77+
#' @param names (`character`) Successor of `datanames`. Vector of dataset names to return the code for.
7678
#' For more details see the "Extracting dataset-specific code" section.
7779
#' @param deparse (`logical`) flag specifying whether to return code as `character` (`deparse = TRUE`) or as
7880
#' `expression` (`deparse = FALSE`).
@@ -81,7 +83,7 @@
8183
#' `code` but are passed in `datanames`. To remove the warning, set `check_names = FALSE`.
8284
#'
8385
#' @return
84-
#' Either a character string or an expression. If `datanames` is used to request a specific dataset,
86+
#' Either a character string or an expression. If `names` is used to request a specific dataset,
8587
#' only code that _creates_ that dataset (not code that uses it) is returned. Otherwise, all contents of `@code`.
8688
#'
8789
#' @examples
@@ -92,8 +94,8 @@
9294
#' c <- list(x = 2)
9395
#' })
9496
#' get_code(tdata1)
95-
#' get_code(tdata1, datanames = "a")
96-
#' get_code(tdata1, datanames = "b")
97+
#' get_code(tdata1, names = "a")
98+
#' get_code(tdata1, names = "b")
9799
#'
98100
#' tdata2 <- teal_data(x1 = iris, code = "x1 <- iris")
99101
#' get_code(tdata2)
@@ -103,28 +105,26 @@
103105
#' @aliases get_code,teal_data-method
104106
#'
105107
#' @export
106-
setMethod("get_code", signature = "teal_data", definition = function(object, deparse = TRUE, datanames = NULL, ...) {
107-
checkmate::assert_character(datanames, min.len = 1L, null.ok = TRUE)
108-
checkmate::assert_flag(deparse)
108+
setMethod("get_code",
109+
signature = "teal_data",
110+
definition = function(object, deparse = TRUE, names = NULL, datanames = lifecycle::deprecated(), ...) {
111+
if (lifecycle::is_present(datanames)) {
112+
lifecycle::deprecate_warn(
113+
when = "0.6.1",
114+
what = "teal.data::get_code(datanames)",
115+
with = "teal.code::get_code(names)",
116+
always = TRUE
117+
)
118+
names <- datanames
119+
}
109120

110-
# Normalize in case special it is backticked
111-
if (!is.null(datanames)) {
112-
datanames <- gsub("^`(.*)`$", "\\1", datanames)
113-
}
121+
if (!is.null(names) && lifecycle::is_present(datanames)) {
122+
stop("Please use either 'names' (recommended) or 'datanames' parameter.")
123+
}
114124

115-
code <- if (!is.null(datanames)) {
116-
get_code_dependency(object@code, datanames, ...)
117-
} else {
118-
object@code
119-
}
125+
checkmate::assert_character(names, min.len = 1L, null.ok = TRUE)
126+
checkmate::assert_flag(deparse)
120127

121-
if (deparse) {
122-
if (length(code) == 0) {
123-
code
124-
} else {
125-
paste(code, collapse = "\n")
126-
}
127-
} else {
128-
parse(text = paste(c("{", code, "}"), collapse = "\n"), keep.source = TRUE)
128+
methods::callNextMethod(object = object, deparse = deparse, names = names, ...)
129129
}
130-
})
130+
)

0 commit comments

Comments
 (0)