insightsengineering / teal

Exploratory Web Apps for Analyzing Clinical Trial Data
https://insightsengineering.github.io/teal/
Other
167 stars 32 forks source link

Adds unfiltered data in teal_data passed to modules #1256

Closed averissimo closed 6 days ago

averissimo commented 1 week ago

Pull Request

Fixes #1229

Changes description

Notes

Alternative approach would create expression and convert it to character vector

paste(
  vapply(
    datanames,
    function(x) {
      deparse1(
        substitute(
          raw_var <- original_var,
          list(raw_var = as.name(sprintf("%s_raw", x)), original_var = as.name(x)
          )
        )
      )
    },
    character(1L)
  ),
  collapse = "\n"
)

Test

pkgload::load_all("../teal")

data <- teal.data::teal_data() |> 
  eval_code("
    IRIS <- iris
    IRIS <- IRIS[IRIS$Species != \"setosa\", ] # @linksto IRIS
    MTCARS <- mtcars
  ")
teal.data::datanames(data) <- c("IRIS", "MTCARS")

teal.code::get_code(data, datanames = "IRIS")

app <- teal::init(
  data = data,
  modules = list(
    teal.modules.general::tm_data_table("Data Table"),
    example_module("Example Module"),
    example_module("Example Module (iris only)", datanames = "IRIS")
  ),
  filter = teal::teal_slices(
    teal.slice::teal_slice("IRIS", "Species", selected = c("setosa", "virginica"))
    # module_specific = TRUE,
    # mapping = list(
    #   global_filters = "IRIS Species",
    #   `Example Module` = "IRIS Species"
    # )
  )
)

runApp(app)
averissimo commented 1 week ago

I placed the raw copying below the data integrity check and after the unchanged code from teal.data / teal_data_module

Adds function .get_raw_code to keep the same convention of calling function to generate code (although the function body is very simple).