You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Confirm that your issue is a genuine bug in the targets package itself and not a user error, known limitation, or issue from another package that targets depends on. For example, if you get errors running tar_make_clustermq(), try isolating the problem in a reproducible example that runs clustermq and not targets. And for miscellaneous troubleshooting, please post to discussions instead of issues.
If there is already a relevant issue, whether open or closed, comment on the existing thread instead of posting a new issue.
When using the {survminer} package to plot survival curves with the ggsurvplot()function, {targets} cannot find the data if it is a data.frame/tibble created within a notebook (specified in _targets.R with tar_render()). This is not an issue when the notebook is knit normally. There is a workaround by using a modified plotting function that takes a summary data.frame (see example 3 below). I don't believe this is expected behavior with regards to the way {targets} accesses data.frames in memory, but please close if it is.
Reproducible example
library(survival)
library(survminer)
attach(lung)
# Create a data.frame in the notebook
test <- filter(lung, sex == 1)
# This works in a targets pipeline
reprex_survival_1 <- survfit(Surv(time, status) ~ 1, data = lung)
ggsurvplot(reprex_survival_1)
# This doesn't work in a targets pipeline
reprex_survival_2 <- survfit(Surv(time, status) ~ 1, data = test)
ggsurvplot(reprex_survival_2)
# This also works in a targets pipeline - presumably because the `surv_summary()`
# function creates a data.frame
reprex_survival_3 <- survfit(Surv(time, status) ~ 1, data = test)
ggsurvplot_df(surv_summary(reprex_survival_1))
Expected result
It should create the survival plot, as it does with examples 1 and 3 above.
Diagnostic information
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.1.0 (2021-05-18)
#> os macOS Big Sur 10.16
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz America/Toronto
#> date 2021-07-01
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> cli 2.5.0 2021-04-26 [1] standard (@2.5.0)
#> digest 0.6.27 2020-10-24 [1] standard (@0.6.27)
#> evaluate 0.14 2019-05-28 [1] standard (@0.14)
#> fs 1.5.0 2020-07-31 [1] standard (@1.5.0)
#> glue 1.4.2 2020-08-27 [1] standard (@1.4.2)
#> highr 0.9 2021-04-16 [1] standard (@0.9)
#> htmltools 0.5.1.1 2021-01-22 [1] standard (@0.5.1.1)
#> knitr 1.33 2021-04-24 [1] standard (@1.33)
#> magrittr 2.0.1 2020-11-17 [1] standard (@2.0.1)
#> reprex 2.0.0 2021-04-02 [1] standard (@2.0.0)
#> rlang 0.4.11 2021-04-30 [1] standard (@0.4.11)
#> rmarkdown 2.8 2021-05-07 [1] standard (@2.8)
#> rstudioapi 0.13 2020-11-12 [1] standard (@0.13)
#> sessioninfo 1.1.1 2018-11-05 [1] standard (@1.1.1)
#> stringi 1.6.2 2021-05-17 [1] standard (@1.6.2)
#> stringr 1.4.0 2019-02-10 [1] standard (@1.4.0)
#> withr 2.4.2 2021-04-18 [1] standard (@2.4.2)
#> xfun 0.23 2021-05-15 [1] standard (@0.23)
#> yaml 2.2.1 2020-02-01 [1] standard (@2.2.1)
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library
This is an instance of #160 and not a bug in targets. For reproducibility purposes, targets runs each target in a non-global environment that inherits from globalenv(). Some packages like lme4 and apparently survminer/survival expect data to be in globalenv() despite claims in the docs that data = NULL means the data is taken from the fit object. I can reproduce this error without targets, so I recommend following up with an issue in the survminer or survival.
library(survival)
library(survminer)
#> Loading required package: ggplot2#> Loading required package: ggpubrenvir<- new.env(parent= globalenv())
evalq({
test<-lungsurvival<- survfit(Surv(time, status) ~1, data=test)
ggsurvplot(survival)
}, envir=envir)
#> Error in eval(fit$call$data): object 'test' not found
Prework
targets
package itself and not a user error, known limitation, or issue from another package thattargets
depends on. For example, if you get errors runningtar_make_clustermq()
, try isolating the problem in a reproducible example that runsclustermq
and nottargets
. And for miscellaneous troubleshooting, please post to discussions instead of issues.Description
When using the {survminer} package to plot survival curves with the
ggsurvplot()
function,{targets}
cannot find the data if it is a data.frame/tibble created within a notebook (specified in_targets.R
withtar_render()
). This is not an issue when the notebook is knit normally. There is a workaround by using a modified plotting function that takes a summary data.frame (see example 3 below). I don't believe this is expected behavior with regards to the way{targets}
accesses data.frames in memory, but please close if it is.Reproducible example
Expected result
It should create the survival plot, as it does with examples 1 and 3 above.
Diagnostic information
The text was updated successfully, but these errors were encountered: