teal icon indicating copy to clipboard operation
teal copied to clipboard

[Bug]: functions in `data` raise warnings

Open chlebowa opened this issue 1 year ago • 4 comments

What happened?

When data contains a function, a warning is logged when running init:

[WARN] 2024-09-26 11:08:10.5918 pid:6800 token:[] teal In 'rlang::hash(list(data = data, modules = modules))': 'package:teal' may not be available when loading

A similar one is logged when the app is run:

[WARN] 2024-09-26 11:48:19.3963 pid:21388 token:[4e453302] teal In 'rlang::hash(data[[dataname]])': 'package:teal' may not be available when loading  

It looks like it's happening in create_app_id. I modified the function so that data is also passed through defunction and that removed the warning raised when running init but not the one raised when runninng the app.

example app
devtools::load_all("teal")

options("teal.bs_theme" = bslib::bs_theme(version = "5"))

data <- teal_data() |>
  within(iris <- iris) |>
  within(foo <- function(x) cat("hello\n"))
modules <- modules(
  example_module()
)

app <- init(data = data, modules = modules)

runApp(app)

sessionInfo()

No response

Relevant log output

> packageVersion("teal")
[1] '0.15.2.9064'

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • [X] I agree to follow this project's Contribution Guidelines.

Security Policy

  • [X] I agree to follow this project's Security Policy.

chlebowa avatar Sep 26 '24 09:09 chlebowa

Update: The second warning occurs in .get_hashes_code.

chlebowa avatar Sep 26 '24 09:09 chlebowa

With the improvements that we've done here, we could prevent the function object to be returned from the environment by prefixing the object's name with a dot (.).

Once I changed foo to .foo, I no longer see the warning.

The function object will still be in Show R Code for reproducibility.

donyunardi avatar Sep 27 '24 05:09 donyunardi

I hadn't noticed the change to the rules. I can't say I like it but I'll accept it.

However, if one leaves a function in on purpose, one will get the warnings so the problem remains.

chlebowa avatar Sep 27 '24 07:09 chlebowa

However, if one leaves a function in on purpose, one will get the warnings so the problem remains.

Fair point and I agree. Thanks for raising the PR, we'll look into this.

donyunardi avatar Sep 30 '24 15:09 donyunardi

Acceptance criteria:

  • filter panel should ignore objects which are clearly unfilterable: currently all objects except data.frame, matrix, MAE
  • summary table should list all datanames - filterable should have obs/subjects while unfilterable probably should be hidden in collapsible panel under summary-table.

gogonzo avatar Oct 15 '24 10:10 gogonzo