metrumresearchgroup / mrgsolve

Simulate from ODE-based population PK/PD and QSP models in R
https://mrgsolve.org
GNU General Public License v2.0
131 stars 36 forks source link

Fail to detect missing differential equation with autodec and nm-vars plugin #1182

Closed kylebaron closed 1 month ago

kylebaron commented 8 months ago

Looks like you have to be using both

library(mrgsolve)
#> 
#> Attaching package: 'mrgsolve'
#> The following object is masked from 'package:stats':
#> 
#>     filter
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

code <- '
$PLUGIN autodec nm-vars
$CMT D B C2
$DES
dxdt_D = -1; 
dxdt_B = 5;
dxdt_C = 5;
'

mod <- mcode("foo", code)
#> Building foo ...
#> done.

mrgsim(mod)
#> Model:  foo 
#> Dim:    25 x 5 
#> Time:   0 to 24 
#> ID:     1 
#>     ID time  D  B C2
#> 1:   1    0  0  0  0
#> 2:   1    1 -1  5  0
#> 3:   1    2 -2 10  0
#> 4:   1    3 -3 15  0
#> 5:   1    4 -4 20  0
#> 6:   1    5 -5 25  0
#> 7:   1    6 -6 30  0
#> 8:   1    7 -7 35  0

Created on 2024-03-22 with reprex v2.0.2

kylebaron commented 8 months ago

If you drop the plugin:

``` r
library(mrgsolve)
#> 
#> Attaching package: 'mrgsolve'
#> The following object is masked from 'package:stats':
#> 
#>     filter
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

code <- '
$CMT D B C2
$DES
dxdt_D = -1; 
dxdt_B = 5;
dxdt_C = 5;
'

mod <- mcode("foo", code)
#> Warning: Missing differential equation(s):
#> --| missing: C2
#> --| suppress with @!audit block option
#> Building foo ...
#> error.
#> 
#> ---:: stderr ::---------------------------------------------
#> using C++ compiler: ‘Apple clang version 14.0.3 (clang-1403.0.22.14.1)’
#> using SDK: ‘MacOSX13.3.sdk’
#> 17:1: error: use of undeclared identifier 'dxdt_C'
#> dxdt_C = 5;
#> ^
#> 1 error generated.
#> make: *** [foo-mread-source.o] Error 1
#> 
#> ------------------------------------------------------------
#> Error: the model build step failed.

mrgsim(mod)
#> Error in eval(expr, envir, enclos): object 'mod' not found

Created on 2024-03-22 with reprex v2.0.2```