insightsengineering / insightsengineering/teal
[Bug]: `datanames` code and environment don't match under edge case
- Dominant language
- R
- Stars
- 263
- Forks
- 59
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 5
Description
### What happened?
Possible Edge case:
- App developer uses object in pre-processing
- Such as a function
- `datanames ≠ "all"` (is **NOT** set to `all`)
- 🔴 Data passed to module has discrepancy in code / "content of qenv"
- pre-processing objects used to generate `datanames` are not included
In the sample app (code below) we can observe this when comparing `ls(data(), all.names = TRUE)` and `get_code(data())`
note: `cbind` is also not store in `.raw_data`

### Sample App code
```r
pkgload::load_all("teal")
library(teal)
data <- teal_data() |>
within({
iris <- iris
mtcars <- mtcars
new_column <- data.frame(what = "new_column")
cbind2 <- function(lhs, rhs) cbind(lhs, rhs)
iris <- cbind2(iris, data.frame(new_column))
})
app <- init(
data = data,
modules = module(
ui = function(id) {
shiny::tagList(
shiny::tags$h3("Code in module"),
shiny::verbatimTextOutput(shiny::NS(id, "code")),
shiny::tags$h3("Contents of data() in module"),
shiny::verbatimTextOutput(shiny::NS(id, "contents")),
example_module()$ui(id)
)
},
server = function(id, data) {
moduleServer(id, function(input, output, session) {
output$contents <- renderText({
paste(
"Available variables in the qenv env:",
paste(ls(teal.code::get_env(data()), all.names = TRUE), collapse = ", ")
)
})
output$code <- renderText({
teal.code::get_code(data()) |> paste(collapse = "\n")
})
})
example_module()$server(id, data)
},
datanames = "iris"
)
)
shiny::runApp(app)
```
### sessionInfo()
_No response_
### Relevant log output
_No response_
### 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.
Contributor guide
Assessment
This issue has not been assessed yet.