Skip to content

[Bug]: Improper code dependency #262

@m7pr

Description

@m7pr

Originally discovered in insightsengineering/teal.gallery#218

For such an example

data <- teal_data()
data <- within(data, {
  library(random.cdisc.data)
  library(nestcolor)

  ADSL <- radsl(seed = 1)
  ADMH <- radmh(ADSL, seed = 1)
  ADVS <- radvs(ADSL, seed = 1)
  teal.data::col_labels(ADMH[c("MHDISTAT")]) <- c("Status of Disease")

  ADVS <- dplyr::inner_join(x = ADVS, y = ADSL[, c("STUDYID", "USUBJID"), drop = FALSE], by = c("STUDYID", "USUBJID"))

})

The code for ADVS should be independent from ADMH, however if you look at the @code slot, you can see:

> data@code
$`1571107062`
[1] "library(random.cdisc.data)"
attr(,"dependency")
[1] "<-"                "library"           "random.cdisc.data"

$`1741714077`
[1] "library(nestcolor)"
attr(,"dependency")
[1] "<-"        "library"   "nestcolor"

$`592546423`
[1] "ADSL <- radsl(seed = 1)"
attr(,"dependency")
[1] "ADSL"  "<-"    "radsl"

$`762969284`
[1] "ADMH <- radmh(ADSL, seed = 1)"
attr(,"dependency")
[1] "ADMH"  "<-"    "radmh" "ADSL"

$`1761929557`
[1] "ADVS <- radvs(ADSL, seed = 1)"
attr(,"dependency")
[1] "ADVS"  "<-"    "radvs" "ADSL"

$`1170376272`
[1] "teal.data::col_labels(ADMH[c(\"MHDISTAT\")]) <- c(\"Status of Disease\")"
attr(,"dependency")
[1] "col_labels" "ADMH"       "c"          "<-"         "c"

$`893635413`
[1] "ADVS <- dplyr::inner_join(x = ADVS, y = ADSL[, c(\"STUDYID\", \"USUBJID\"), drop = FALSE], by = c(\"STUDYID\", \"USUBJID\"))"
attr(,"dependency")
[1] "ADVS"       "<-"         "inner_join" "ADVS"       "ADSL"
[6] "c"          "c"

which means

ADVS is dependent on c (element named893635413), and c is dependent on c (element named 1170376272), so in the end

[1] "teal.data::col_labels(ADMH[c(\"MHDISTAT\")]) <- c(\"Status of Disease\")"

gets extracted for the code

> cat(get_code(data, names = 'ADVS'))
library(random.cdisc.data)
library(nestcolor)
ADSL <- radsl(seed = 1)
ADVS <- radvs(ADSL, seed = 1)
teal.data::col_labels(ADMH[c("MHDISTAT")]) <- c("Status of Disease")
ADVS <- dplyr::inner_join(x = ADVS, y = ADSL[, c("STUDYID", "USUBJID"), drop = FALSE], by = c("STUDYID", "USUBJID"))

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcore

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions