Skip to content

Commit

Permalink
288 allow ellipsis in get_code (#290)
Browse files Browse the repository at this point in the history
Close #288 

Allows to pass more parameters in `get_code` through `...`. For example
you can now pass `check_names`

```r
code <- c(
  "a <- 1",
  "b <- identity(x = a)",
  "a <- 2"
)
tdata <- eval_code(teal_data(), code)
get_code(tdata, datanames = "c", check_names = TRUE)
#> character(0)
Warning message:
In get_code_dependency(object@code, datanames, ...) :
  Object(s) not found in code: c
  

get_code(tdata, datanames = "c", check_names = FALSE)
#> character(0)
```

---------

Signed-off-by: Marcin <[email protected]>
Co-authored-by: Dony Unardi <[email protected]>
  • Loading branch information
m7pr and donyunardi authored Feb 12, 2024
1 parent f2f4325 commit a9d02e4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# teal.data 0.4.0.9004

### Enhancements
* Extended `get_code.teal_data()` with a possibility to steer internal methods with `...` parameter.

# teal.data 0.4.0

### Enhancements
Expand Down
7 changes: 5 additions & 2 deletions R/teal_data-get_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
#' 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`).
#' @param ... Parameters passed to internal methods. Currently, the only supported parameter is `check_names`
#' (`logical(1)`) flag, which is `TRUE` by default. Function warns about missing objects, if they do not exist in
#' `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,
Expand All @@ -101,12 +104,12 @@
#' @aliases get_code,teal_data-method
#'
#' @export
setMethod("get_code", signature = "teal_data", definition = function(object, deparse = TRUE, datanames = NULL) {
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)

code <- if (!is.null(datanames)) {
get_code_dependency(object@code, datanames)
get_code_dependency(object@code, datanames, ...)
} else {
object@code
}
Expand Down
6 changes: 5 additions & 1 deletion man/get_code.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a9d02e4

Please sign in to comment.