nlmixr2 / rxode2et

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

et() cannot add more 'ID's to this event table #4

Closed frbrz closed 1 year ago

frbrz commented 1 year ago

And hi again...

I think that there is a small bug with et(). I would like to simulate (at the same time) many individuals on different dosing regimens, see reprex below. But I get an error saying that I cannot add more 'ID's to this event table. At first I thought that ID cannot be greater than 10, but in fact it may be a problem with the third element that is piped-in.

rm(list = ls())

library(tidyverse)
library(nlmixr2)
#> Loading required package: nlmixr2data

# Does not work
et(amt = 10, time = 0, evid = 1, id = 1:5) %>% 
  et(amt = 100, time = 0, evid = 1, id = 6:10) %>% 
  et(amt = 1000, time = 0, evid = 1, id = 11)
#> Error in et.default(., amt = 1000, time = 0, evid = 1, id = 11): cannot add more 'ID's to this event table

# One and two-pipes work
et(amt = 10, time = 0, evid = 1, id = 1:11)
#> ── EventTable with 11 records ──
#> 11 dosing records (see x$get.dosing(); add with add.dosing or et)
#> 0 observation times (see x$get.sampling(); add with add.sampling or et)
#> ── First part of x: ──
#> # A tibble: 11 × 4
#>       id  time   amt evid        
#>    <int> <dbl> <dbl> <evid>      
#>  1     1     0    10 1:Dose (Add)
#>  2     2     0    10 1:Dose (Add)
#>  3     3     0    10 1:Dose (Add)
#>  4     4     0    10 1:Dose (Add)
#>  5     5     0    10 1:Dose (Add)
#>  6     6     0    10 1:Dose (Add)
#>  7     7     0    10 1:Dose (Add)
#>  8     8     0    10 1:Dose (Add)
#>  9     9     0    10 1:Dose (Add)
#> 10    10     0    10 1:Dose (Add)
#> 11    11     0    10 1:Dose (Add)

et(amt = 10, time = 0, evid = 1, id = 1:10) %>% 
  et(amt = 100, time = 0, evid = 1, id = 11)
#> ── EventTable with 12 records ──
#> 12 dosing records (see x$get.dosing(); add with add.dosing or et)
#> 0 observation times (see x$get.sampling(); add with add.sampling or et)
#> ── First part of x: ──
#> # A tibble: 12 × 4
#>       id  time   amt evid        
#>    <int> <dbl> <dbl> <evid>      
#>  1     1     0    10 1:Dose (Add)
#>  2     2     0    10 1:Dose (Add)
#>  3     3     0    10 1:Dose (Add)
#>  4     4     0    10 1:Dose (Add)
#>  5     5     0    10 1:Dose (Add)
#>  6     6     0    10 1:Dose (Add)
#>  7     7     0    10 1:Dose (Add)
#>  8     8     0    10 1:Dose (Add)
#>  9     9     0    10 1:Dose (Add)
#> 10    10     0    10 1:Dose (Add)
#> 11    11     0    10 1:Dose (Add)
#> 12    11     0   100 1:Dose (Add)

reprex::reprex(session_info = T)
#> ✖ Install the styler package in order to use `style = TRUE`.
#> ℹ Non-interactive session, setting `html_preview = FALSE`.
#> CLIPR_ALLOW has not been set, so clipr will not run interactively
#> Error in switch(where, expr = stringify_expression(x_expr), clipboard = ingest_clipboard(), : EXPR must be a length 1 vector

Created on 2022-10-25 by the reprex package (v2.0.1)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.2.0 (2022-04-22) #> os Fedora 33 (Container Image) #> system x86_64, linux-gnu #> ui X11 #> language en_US:en #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Europe/Zurich #> date 2022-10-25 #> pandoc 2.17.1.1 @ /usr/lib/rstudio-server/bin/quarto/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.2.0) #> backports 1.4.1 2021-12-13 [2] CRAN (R 4.2.0) #> broom 0.8.0 2022-04-13 [2] CRAN (R 4.2.0) #> cachem 1.0.6 2021-08-19 [2] CRAN (R 4.2.0) #> cellranger 1.1.0 2016-07-27 [2] CRAN (R 4.2.0) #> checkmate 2.1.0 2022-04-21 [2] CRAN (R 4.2.0) #> cli 3.3.0 2022-04-25 [2] CRAN (R 4.2.0) #> clipr 0.8.0 2022-02-22 [2] CRAN (R 4.2.0) #> colorspace 2.0-3 2022-02-21 [2] CRAN (R 4.2.0) #> crayon 1.5.1 2022-03-26 [2] CRAN (R 4.2.0) #> data.table 1.14.2 2021-09-27 [2] CRAN (R 4.2.0) #> DBI 1.1.2 2021-12-20 [2] CRAN (R 4.2.0) #> dbplyr 2.2.1 2022-06-27 [1] CRAN (R 4.2.0) #> digest 0.6.29 2021-12-01 [2] CRAN (R 4.2.0) #> dplyr * 1.0.9 2022-04-28 [2] CRAN (R 4.2.0) #> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.2.0) #> evaluate 0.15 2022-02-18 [2] CRAN (R 4.2.0) #> fansi 1.0.3 2022-03-24 [2] CRAN (R 4.2.0) #> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.2.0) #> forcats * 0.5.1 2021-01-27 [2] CRAN (R 4.2.0) #> fs 1.5.2 2021-12-08 [2] CRAN (R 4.2.0) #> gargle 1.2.0 2021-07-02 [2] CRAN (R 4.2.0) #> generics 0.1.2 2022-01-31 [2] CRAN (R 4.2.0) #> ggplot2 * 3.3.6 2022-05-03 [2] CRAN (R 4.2.0) #> glue 1.6.2 2022-02-24 [2] CRAN (R 4.2.0) #> googledrive 2.0.0 2021-07-08 [2] CRAN (R 4.2.0) #> googlesheets4 1.0.0 2021-07-21 [2] CRAN (R 4.2.0) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.2.0) #> haven 2.5.0 2022-04-15 [2] CRAN (R 4.2.0) #> highr 0.9 2021-04-16 [2] CRAN (R 4.2.0) #> hms 1.1.1 2021-09-26 [2] CRAN (R 4.2.0) #> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.2.0) #> httr 1.4.3 2022-05-04 [2] CRAN (R 4.2.0) #> jsonlite 1.8.0 2022-02-22 [2] CRAN (R 4.2.0) #> knitr 1.39 2022-04-26 [2] CRAN (R 4.2.0) #> lattice 0.20-45 2021-09-22 [2] CRAN (R 4.2.0) #> lbfgsb3c 2020-3.2 2020-03-03 [1] CRAN (R 4.2.0) #> lifecycle 1.0.1 2021-09-24 [2] CRAN (R 4.2.0) #> lotri 0.4.2 2022-06-18 [1] CRAN (R 4.2.0) #> lubridate 1.8.0 2021-10-07 [2] CRAN (R 4.2.0) #> magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.2.0) #> memoise 2.0.1 2021-11-26 [2] CRAN (R 4.2.0) #> modelr 0.1.8 2020-05-19 [2] CRAN (R 4.2.0) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.2.0) #> n1qn1 6.0.1-10 2020-11-17 [1] CRAN (R 4.2.0) #> nlme 3.1-157 2022-03-25 [2] CRAN (R 4.2.0) #> nlmixr2 * 2.0.7 2022-06-27 [1] CRAN (R 4.2.0) #> nlmixr2data * 2.0.7 2022-04-22 [1] CRAN (R 4.2.0) #> nlmixr2est 2.0.8 2022-06-22 [1] CRAN (R 4.2.0) #> nlmixr2plot 2.0.6 2022-05-23 [1] CRAN (R 4.2.0) #> pillar 1.7.0 2022-02-01 [2] CRAN (R 4.2.0) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.2.0) #> PreciseSums 0.5 2022-04-22 [1] CRAN (R 4.2.0) #> purrr * 0.3.4 2020-04-17 [2] CRAN (R 4.2.0) #> qs 0.25.4 2022-08-09 [1] CRAN (R 4.2.0) #> R6 2.5.1 2021-08-19 [2] CRAN (R 4.2.0) #> RApiSerialize 0.1.2 2022-08-25 [1] CRAN (R 4.2.0) #> Rcpp 1.0.8.3 2022-03-17 [2] CRAN (R 4.2.0) #> RcppParallel 5.1.5 2022-01-05 [2] CRAN (R 4.2.0) #> readr * 2.1.2 2022-01-30 [2] CRAN (R 4.2.0) #> readxl 1.4.0 2022-03-28 [2] CRAN (R 4.2.0) #> reprex 2.0.1 2021-08-05 [2] CRAN (R 4.2.0) #> rlang 1.0.2 2022-03-04 [2] CRAN (R 4.2.0) #> rmarkdown 2.14 2022-04-25 [2] CRAN (R 4.2.0) #> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.2.0) #> rvest 1.0.2 2021-10-16 [2] CRAN (R 4.2.0) #> rxode2 2.0.7 2022-05-17 [1] CRAN (R 4.2.0) #> scales 1.2.0 2022-04-13 [2] CRAN (R 4.2.0) #> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.2.0) #> stringfish 0.15.7 2022-04-13 [1] CRAN (R 4.2.0) #> stringi 1.7.6 2021-11-29 [2] CRAN (R 4.2.0) #> stringr * 1.4.0 2019-02-10 [2] CRAN (R 4.2.0) #> symengine 0.2.1 2022-04-28 [1] CRAN (R 4.2.0) #> sys 3.4 2020-07-23 [2] CRAN (R 4.2.0) #> tibble * 3.1.7 2022-05-03 [2] CRAN (R 4.2.0) #> tidyr * 1.2.0 2022-02-01 [2] CRAN (R 4.2.0) #> tidyselect 1.1.2 2022-02-21 [2] CRAN (R 4.2.0) #> tidyverse * 1.3.2 2022-07-18 [1] CRAN (R 4.2.0) #> tzdb 0.3.0 2022-03-28 [2] CRAN (R 4.2.0) #> units 0.8-0 2022-02-05 [2] CRAN (R 4.2.0) #> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.2.0) #> vctrs 0.4.1 2022-04-13 [2] CRAN (R 4.2.0) #> vpc 1.2.2 2021-01-11 [1] CRAN (R 4.2.0) #> withr 2.5.0 2022-03-03 [2] CRAN (R 4.2.0) #> xfun 0.30 2022-03-02 [2] CRAN (R 4.2.0) #> xml2 1.3.3 2021-11-30 [2] CRAN (R 4.2.0) #> yaml 2.3.5 2022-02-21 [2] CRAN (R 4.2.0) #> #> [1] /home/brizzif/R/x86_64-pc-linux-gnu-library/4.2.0-foss #> [2] /apps/rocs/2020.08/cascadelake/software/R/4.2.0-foss-2020a/lib64/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
mattfidler commented 1 year ago

This comes from:

https://github.com/nlmixr2/rxode2et/blob/bb7751e6bada63843576d1bd08603c5081e9d0c9/src/et.cpp#L2057

In this:

It is programmed this way, but it could be fixed so that it will add IDs that are new to the event table.

mattfidler commented 1 year ago

In the mean time you can use %>% as.data.frame() to each and then rbind them together.

mattfidler commented 1 year ago

This was fixed by another merge somewhere, but I added a test so it won't occur again

frbrz commented 1 year ago

Thank you - happy new year :)

mattfidler commented 1 year ago

No problem. Happy New Year 😄