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

Additional (unnecessary?) attached libraries in get r code #593

Closed
kpagacz opened this issue Mar 24, 2022 · 3 comments
Closed

Additional (unnecessary?) attached libraries in get r code #593

kpagacz opened this issue Mar 24, 2022 · 3 comments
Labels
bug Something isn't working core research
Milestone

Comments

@kpagacz
Copy link
Contributor

kpagacz commented Mar 24, 2022

When running this example:

library(scda)
library(dplyr)
library(teal.modules.clinical)

adsl <- synthetic_cdisc_data("latest")$adsl
adex <- synthetic_cdisc_data("latest")$adex

set.seed(1, kind = "Mersenne-Twister")
adex <- adex %>%
  distinct(USUBJID, .keep_all = TRUE) %>%
  mutate(
    PARAMCD = "TDURD",
    PARAM = "Overall duration (days)",
    AVAL = sample(x = seq(1, 200), size = n(), replace = TRUE),
    AVALU = "Days"
  ) %>%
  bind_rows(adex)

app <- init(
  data = cdisc_data(
    cdisc_dataset("ADSL", adsl, code = 'ADSL <- synthetic_cdisc_data("latest")$adsl'),
    cdisc_dataset("ADEX", adex, code = 'ADEX <- synthetic_cdisc_data("latest")$adex
  set.seed(1, kind = "Mersenne-Twister")
  ADEX <- ADEX %>%
  distinct(USUBJID, .keep_all = TRUE) %>%
  mutate(PARAMCD = "TDURD",
         PARAM = "Overall duration (days)",
         AVAL = sample(x = seq(1, 200), size = n(), replace = TRUE),
         AVALU = "Days") %>%
  bind_rows(ADEX)'),
    check = TRUE
  ),
  modules = modules(
    tm_t_exposure(
      label = "Duration of Exposure Table",
      dataname = "ADEX",
      paramcd = choices_selected(
        choices = value_choices(adex, "PARAMCD", "PARAM"),
        selected = "TDURD"
      ),
      col_by_var = choices_selected(
        choices = variable_choices(adex, subset = c("ARM")),
        selected = NULL
      ),
      row_by_var = choices_selected(
        choices = variable_choices(adex, subset = c("ETHNIC", "SEX")),
        selected = "ETHNIC"
      ),
      parcat = choices_selected(
        choices = value_choices(adex, "PARCAT2"),
        selected = "Drug A"
      ),
      add_total = FALSE
    )
  ),
  filter = list(
    ADSL = list(SAFFL = "Y")
  )
)

shinyApp(app$ui, app$server)

I noticed show r code attaches all the behind-the-scenes libraries which might not be needed
image

@kpagacz kpagacz added the bug Something isn't working label Mar 24, 2022
@Polkas
Copy link
Contributor

Polkas commented Mar 28, 2022

This comes from the design of how we recognize dependencies, utils::sessionInfo()$otherPkgs.

get_rcode_libraries <- function() {

I think we should leave it if there is no clever move to reduce the list of dependencies.
The static removal of packages which we think are not needed do not have to be stable as we could change sth in the future. teal.data could be used e.g. to rise the connection.
On the other hand I could imagine that teal.slice/shiny/testthat/... will be never used in the show R code.

dependencies <- utils::sessionInfo()$otherPkgs
# this process is dangerous
setdiff(dependencies, c("teal.X", "testthat"))

For sure there could be more advanced solutions, like specifying dependencies when chunks are built.

@gogonzo
Copy link
Contributor

gogonzo commented Nov 24, 2022

From @mhallal1

Please refer to the comments by @Polkas in #752 (comment)

We should not add blindly all library calls for each SHow R Code call.
We have many options to add only needed dependencies, for each module.

linked to insightsengineering/teal.code#93

@gogonzo
Copy link
Contributor

gogonzo commented May 24, 2024

Closing this one. We can't separate output-related and app-related libraries. We moving to the solution where we provide library calls by evaluating them in teal_data object.

teal_data() |> within({library(...)})

@gogonzo gogonzo closed this as completed May 24, 2024
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 research
Projects
None yet
Development

No branches or pull requests

4 participants