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

get_code unexpected behaviour #94

Closed
nikolas-burkoff opened this issue Aug 30, 2022 · 2 comments
Closed

get_code unexpected behaviour #94

nikolas-burkoff opened this issue Aug 30, 2022 · 2 comments
Labels
bug Something isn't working core

Comments

@nikolas-burkoff
Copy link
Contributor

d1 <- data.frame(id = 1:5, pk = c(2, 3, 2, 1, 4), val = 1:5)
d2 <- data.frame(id = 1:5, value = 1:5)

cc <- teal.data:::CodeClass$new()
cc$set_code(c(
  "d1 <- data.frame(id = 1:5, pk = c(2,3,2,1,4), val = 1:5)",
  "d2 <- data.frame(id = 1:5, value = 1:5)"
))

fd <- teal.slice::init_filtered_data(
  x = list(
    d1 = list(dataset = d1, keys = "id"),
    d2 = list(dataset = d2, keys = "id")
  ),
  join_keys = teal.data::join_keys(teal.data::join_key("d1", "d2", c("pk" = "id"))),
  code = cc,
  check = TRUE
)

The code is stored correctly:

fd$.__enclos_env__$private$code$get_code()

But getting code doesn't work as fd$get_code() has default argument dataname = self$datanames() => c("d1", d2") but the code class only gives code if no datanames are given

image

@nikolas-burkoff nikolas-burkoff added bug Something isn't working core labels Aug 30, 2022
@donyunardi
Copy link
Contributor

I feel that the problem may start from here:

https://github.com/insightsengineering/teal.data/blob/1d42d29ef36a2e5381ba2e233488c97eecde1027/R/CodeClass.R#L94-L105

    set_code = function(code, dataname = character(0), deps = character(0)) {
      checkmate::assert_character(code, min.len = 1, any.missing = FALSE)
      checkmate::assert_character(dataname, any.missing = FALSE)
      stopifnot(!(dataname %in% deps))


      code <- pretty_code_string(code)


      for (code_single in code) {
        private$set_code_single(code_single, dataname, deps)
      }
      logger::log_trace("CodeClass$set_code code set.")
      return(invisible(self))

If CodeClass initiated without dataname, then the default value is character(0).
Assertion won't kick in because character(0) is not a missing value.

If I add dataname when calling cc$set_code() method, the code works:

image

@donyunardi
Copy link
Contributor

This issue is no longer relevant after we implemented with the new teal_data object.
Also, init_filtered_data is now deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core
Projects
None yet
Development

No branches or pull requests

2 participants