nlmixr2 / rxode2et

https://nlmixr2.github.io/rxode2et/
1 stars 1 forks source link

et() piping with evid = 0 and evid = 1 does not work #3

Closed frbrz closed 1 year ago

frbrz commented 2 years ago

Hi,

Thanks for the great package!

I may have caught an unexpected behavior with et() and piping. See the minimal example below Basically I get an error saying that I cannot use zero evid with amt when piping dosing and observation information. The amt specification is not with evid = 0, but comes from the pipe with evid = 1. A quick fix is using add.sampling() instead of et(..., evid = 0). Definitely a low fix priority, but you may want to have a look.

library(nlmixr2)
#> Loading required package: nlmixr2data

et(amt = 10, cmt = 1, time = 0, evid = 1, id = 1) %>% 
  et(time = c(0, 10, 20), evid = 0)
#> Error in et.default(., time = c(0, 10, 20), evid = 0): zero 'evid' cannot be used with 'amt'

sessionInfo()
#> R version 4.2.0 (2022-04-22)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Fedora 33 (Container Image)
#> 
#> Matrix products: default
#> BLAS/LAPACK: /apps/rocs/2020.08/cascadelake/software/OpenBLAS/0.3.9-GCC-9.3.0/lib/libopenblas_skylakexp-r0.3.9.so
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] nlmixr2_2.0.7     nlmixr2data_2.0.7
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.8.3        lattice_0.20-45     vpc_1.2.2          
#>  [4] assertthat_0.2.1    digest_0.6.29       utf8_1.2.2         
#>  [7] R6_2.5.1            backports_1.4.1     sys_3.4            
#> [10] reprex_2.0.1        evaluate_0.15       ggplot2_3.3.6      
#> [13] highr_0.9           pillar_1.7.0        rlang_1.0.2        
#> [16] rstudioapi_0.13     data.table_1.14.2   checkmate_2.1.0    
#> [19] rmarkdown_2.14      qs_0.25.4           stringr_1.4.0      
#> [22] PreciseSums_0.5     nlmixr2plot_2.0.6   munsell_0.5.0      
#> [25] symengine_0.2.1     compiler_4.2.0      xfun_0.30          
#> [28] pkgconfig_2.0.3     htmltools_0.5.2     tidyselect_1.1.2   
#> [31] tibble_3.1.7        fansi_1.0.3         crayon_1.5.1       
#> [34] dplyr_1.0.9         withr_2.5.0         grid_4.2.0         
#> [37] nlme_3.1-157        gtable_0.3.0        lifecycle_1.0.1    
#> [40] DBI_1.1.2           magrittr_2.0.3      units_0.8-0        
#> [43] scales_1.2.0        RcppParallel_5.1.5  cli_3.3.0          
#> [46] stringi_1.7.6       cachem_1.0.6        n1qn1_6.0.1-10     
#> [49] rxode2_2.0.7        fs_1.5.2            ellipsis_0.3.2     
#> [52] generics_0.1.2      vctrs_0.4.1         stringfish_0.15.7  
#> [55] lotri_0.4.2         RApiSerialize_0.1.2 tools_4.2.0        
#> [58] glue_1.6.2          purrr_0.3.4         fastmap_1.1.0      
#> [61] yaml_2.3.5          colorspace_2.0-3    lbfgsb3c_2020-3.2  
#> [64] nlmixr2est_2.0.8    memoise_2.0.1       knitr_1.39

Thanks a lot!

mattfidler commented 2 years ago

Thanks; We will have a look.

mattfidler commented 2 years ago

Note that if you don't specify evid=0 the piping also works

library(rxode2)
#> rxode2 2.0.7 using 4 threads (see ?getRxThreads)
#>   no cache: create with `rxCreateCache()`
et(amt = 10, cmt = 1, time = 0, evid = 1, id = 1) %>% 
  et(time = c(0, 10, 20))
#> ── EventTable with 4 records ──
#> 1 dosing records (see x$get.dosing(); add with add.dosing or et)
#> 3 observation times (see x$get.sampling(); add with add.sampling or et)
#> ── First part of x: ──
#> # A tibble: 4 × 5
#>      id  time   cmt   amt evid         
#>   <int> <dbl> <int> <dbl> <evid>       
#> 1     1     0    NA    NA 0:Observation
#> 2     1     0     1    10 1:Dose (Add) 
#> 3     1    10    NA    NA 0:Observation
#> 4     1    20    NA    NA 0:Observation

Created on 2022-10-12 with reprex v2.0.2

billdenney commented 1 year ago

FYI, this is fixed with the GitHub version:

# remotes::install_github("nlmixr2/rxode2et")
library(rxode2et)
et(time = c(0, 10, 20), evid = 0)
#> ── EventTable with 3 records ──
#> 0 dosing records (see x$get.dosing(); add with add.dosing or et)
#> 3 observation times (see x$get.sampling(); add with add.sampling or et)
#> ── First part of x: ──
#> # A tibble: 3 × 2
#>    time evid         
#>   <dbl> <evid>       
#> 1     0 0:Observation
#> 2    10 0:Observation
#> 3    20 0:Observation

Created on 2022-10-25 with reprex v2.0.2