Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

210 depracate datanames in teal.data::get_code #343

Merged
merged 29 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
59a103d
deprecated datanames for teal.data::get_code
m7pr Oct 16, 2024
8d61ecc
do not add a call to the warning message
m7pr Oct 16, 2024
7a69582
update vignettes
m7pr Oct 16, 2024
3942fec
use lifecyclfe::deprecate_warn instead of warning
m7pr Oct 17, 2024
2e756e3
update documentation
m7pr Oct 17, 2024
50d02d9
remove teal.data::get_code bones (remove get_code_dependency0
m7pr Oct 17, 2024
5ca6190
update documentation to use `names` and no prefixes for teal.code
m7pr Oct 17, 2024
0c05b87
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 17, 2024
c3942cd
spelling
m7pr Oct 18, 2024
6753dc8
lintr
m7pr Oct 18, 2024
45b1d41
Merge branch '218_deprecate_get_code@main' of https://github.com/insi…
m7pr Oct 18, 2024
91f5c7c
[skip style] [skip vbump] Restyle files
github-actions[bot] Oct 18, 2024
b9773d1
overwrite the class
m7pr Oct 18, 2024
8b7110e
lintr
m7pr Oct 18, 2024
530b7ba
[skip style] [skip vbump] Restyle files
github-actions[bot] Oct 18, 2024
5318d38
Update NEWS.md
m7pr Oct 18, 2024
7d1c6ee
use callNextMethod instead of setting up the class manually to qenv
m7pr Oct 18, 2024
be3a13c
Merge branch '218_deprecate_get_code@main' of https://github.com/insi…
m7pr Oct 18, 2024
d2cec0e
rename chapters in NEWS
m7pr Oct 18, 2024
c12c983
change the order of names and datanames so names is used instead of d…
m7pr Oct 18, 2024
185db46
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 18, 2024
36e0a33
use lifecycle::deprecate() and lifecycle::is_present() for datanames …
m7pr Oct 18, 2024
568035d
merge
m7pr Oct 18, 2024
345f398
change the bade from experimental to deprecated
m7pr Oct 18, 2024
4ce5c54
move if before the asserts
m7pr Oct 18, 2024
c9074a3
add methods:: prefix and extract the deprecation message outside the …
m7pr Oct 18, 2024
5aa5a7f
move back to the version where only datanames is deprecated, not the …
m7pr Oct 21, 2024
dbf3c29
[skip style] [skip vbump] Restyle files
github-actions[bot] Oct 21, 2024
ff7cc1d
merge main
m7pr Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,5 @@ Collate:
'teal_data.R'
'testhat-helpers.R'
'topological_sort.R'
'utils-get_code_dependency.R'
'verify.R'
'zzz.R'
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# teal.data 0.6.0.9012

### Breaking changes

- soft deprecate `datanames` argument of `get_code()`. Use `names` instead.

### Enhancements

- `datanames()`
Expand Down
61 changes: 31 additions & 30 deletions R/teal_data-get_code.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#' Get code from `teal_data` object
#'
#' Retrieve code from `teal_data` object.
#' `r lifecycle::badge("deprecated")` Use [`teal.code::get_code()`]. Retrieve code from `teal_data` object.
m7pr marked this conversation as resolved.
Show resolved Hide resolved
#'
#' Retrieve code stored in `@code`, which (in principle) can be used to recreate all objects found in `@env`.
#' Use `datanames` to limit the code to one or more of the datasets enumerated in `@datanames`.
#' Use `names` to limit the code to one or more of the datasets enumerated in `@datanames`.
#'
#' @section Extracting dataset-specific code:
#' When `datanames` is specified, the code returned will be limited to the lines needed to _create_
#' When `names` is specified, the code returned will be limited to the lines needed to _create_
#' the requested datasets. The code stored in the `@code` slot is analyzed statically to determine
#' which lines the datasets of interest depend upon. The analysis works well when objects are created
#' with standard infix assignment operators (see `?assignOps`) but it can fail in some situations.
Expand All @@ -23,10 +23,10 @@
#' x <- 0
#' y <- foo(x)
#' })
#' get_code(data, datanames = "y")
#' get_code(data, names = "y")
#' ```
#' `x` has no dependencies, so `get_code(data, datanames = "x")` will return only the second call.\cr
#' `y` depends on `x` and `foo`, so `get_code(data, datanames = "y")` will contain all three calls.
#' `x` has no dependencies, so `get_code(data, names = "x")` will return only the second call.\cr
#' `y` depends on `x` and `foo`, so `get_code(data, names = "y")` will contain all three calls.
#'
#' _Case 2: Some objects are created by a function's side effects._
#' ```r
Expand All @@ -39,10 +39,10 @@
#' foo()
#' y <- x
#' })
#' get_code(data, datanames = "y")
#' get_code(data, names = "y")
#' ```
#' Here, `y` depends on `x` but `x` is modified by `foo` as a side effect (not by reassignment)
#' and so `get_code(data, datanames = "y")` will not return the `foo()` call.\cr
#' and so `get_code(data, names = "y")` will not return the `foo()` call.\cr
#' To overcome this limitation, code dependencies can be specified manually.
#' Lines where side effects occur can be flagged by adding "`# @linksto <object name>`" at the end.\cr
#' Note that `within` evaluates code passed to `expr` as is and comments are ignored.
Expand All @@ -58,7 +58,7 @@
#' foo() # @linksto x
#' y <- x
#' ")
#' get_code(data, datanames = "y")
#' get_code(data, names = "y")
#' ```
#' Now the `foo()` call will be properly included in the code required to recreate `y`.
#'
Expand All @@ -72,7 +72,9 @@
#'
#'
#' @param object (`teal_data`)
#' @param datanames `r lifecycle::badge("experimental")` (`character`) vector of dataset names to return the code for.
#' @param datanames `r lifecycle::badge("deprecated")` (`character`) vector of dataset names to return the code for.
#' For more details see the "Extracting dataset-specific code" section.
#' @param names (`character`) Successor of `datanames`. Vector of dataset names to return the code for.
#' For more details see the "Extracting dataset-specific code" section.
#' @param deparse (`logical`) flag specifying whether to return code as `character` (`deparse = TRUE`) or as
#' `expression` (`deparse = FALSE`).
Expand All @@ -81,7 +83,7 @@
#' `code` but are passed in `datanames`. To remove the warning, set `check_names = FALSE`.
#'
#' @return
#' Either a character string or an expression. If `datanames` is used to request a specific dataset,
#' Either a character string or an expression. If `names` is used to request a specific dataset,
#' only code that _creates_ that dataset (not code that uses it) is returned. Otherwise, all contents of `@code`.
#'
#' @examples
Expand All @@ -92,8 +94,8 @@
#' c <- list(x = 2)
#' })
#' get_code(tdata1)
#' get_code(tdata1, datanames = "a")
#' get_code(tdata1, datanames = "b")
#' get_code(tdata1, names = "a")
#' get_code(tdata1, names = "b")
#'
#' tdata2 <- teal_data(x1 = iris, code = "x1 <- iris")
#' get_code(tdata2)
Expand All @@ -103,23 +105,22 @@
#' @aliases get_code,teal_data-method
#'
#' @export
setMethod("get_code", signature = "teal_data", definition = function(object, deparse = TRUE, datanames = NULL, ...) {
checkmate::assert_character(datanames, min.len = 1L, null.ok = TRUE)
checkmate::assert_flag(deparse)
setMethod("get_code",
signature = "teal_data",
definition = function(object, deparse = TRUE, names = NULL, datanames = lifecycle::deprecated(), ...) {
if (lifecycle::is_present(datanames)) {
lifecycle::deprecate_warn(
when = "0.6.1",
what = "teal.data::get_code(datanames = )",
with = "teal.code::get_code(names = )",
always = TRUE
)
names <- datanames
}

code <- if (!is.null(datanames)) {
get_code_dependency(object@code, datanames, ...)
} else {
object@code
}
checkmate::assert_character(names, min.len = 1L, null.ok = TRUE)
checkmate::assert_flag(deparse)

if (deparse) {
if (length(code) == 0) {
code
} else {
paste(code, collapse = "\n")
}
} else {
parse(text = paste(c("{", code, "}"), collapse = "\n"), keep.source = TRUE)
callNextMethod(object = object, deparse = deparse, names = names, ...)
}
})
)
Loading
Loading