diff --git a/DESCRIPTION b/DESCRIPTION index b84997409..a66d74618 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: rxode2 -Version: 3.0.0 +Version: 3.0.1 Title: Facilities for Simulating from ODE-Based Models Authors@R: c( person("Matthew L.","Fidler", role = c("aut", "cre"), email = "matthew.fidler@gmail.com", comment=c(ORCID="0000-0001-8538-6691")), diff --git a/NEWS.md b/NEWS.md index 3071a368b..b906176f9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# rxode2 3.0.1 + +- explicitly initialize the order vector to stop valgrind warning (requested from CRAN) + # rxode2 3.0.0 ## Breaking Changes diff --git a/cran-comments.md b/cran-comments.md index 45bee1034..cf7878ccc 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,3 +1,3 @@ -- This works with the new dparser, PreciseSums and lotri to reduce abi linkages -- This rxode2 combines the rxode2parse rxode2random and rxode2et (as - requested by CRAN) +- explicitly initialized C integer vector `ordS` in rxode2 code to + avoid valgrind warning (as requested by CRAN). +- all other warnings come from the `units` package diff --git a/man/reexports.Rd b/man/reexports.Rd index 8cba3d62e..2857ff16d 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -38,3 +38,4 @@ below to see their documentation. \item{magrittr}{\code{\link[magrittr:pipe]{\%>\%}}} }} +\value{ Inherited from parent routine } diff --git a/man/rmdhunks/rxode2-create-models.Rmd b/man/rmdhunks/rxode2-create-models.Rmd index d71ccf870..17e6c3fdf 100644 --- a/man/rmdhunks/rxode2-create-models.Rmd +++ b/man/rmdhunks/rxode2-create-models.Rmd @@ -1,8 +1,8 @@ -The ODE-based model specification may be coded inside four places: +The ODE-based model specification may be coded inside four places: - Inside a `rxode2({})` block statements: -```{r modBracket} +``` r library(rxode2) mod <- rxode2({ # simple assignment @@ -15,7 +15,7 @@ mod <- rxode2({ - Inside a `rxode2("")` string statement: -```{r modString} +``` r mod <- rxode2(" # simple assignment C2 <- centr/V2 @@ -27,7 +27,7 @@ mod <- rxode2(" - In a file name to be loaded by rxode2: -```{r modFile} +``` r writeLines(" # simple assignment C2 <- centr/V2 @@ -38,10 +38,10 @@ writeLines(" mod <- rxode2(filename='modelFile.rxode2') unlink("modelFile.rxode2") ``` - + - In a model function which can be parsed by `rxode2`: -```{r modFun} +``` r mod <- function() { model({ # simple assignment @@ -94,10 +94,10 @@ For the last type of model (a model function), a call to `rxode2` creates a parsed `rxode2` ui that can be translated to the `rxode2` compilation model. -```{r} +``` r mod$simulationModel -# or +# or mod$simulationIniModel ``` diff --git a/src/genModelVars.h b/src/genModelVars.h index e44a90bb8..2395c2634 100644 --- a/src/genModelVars.h +++ b/src/genModelVars.h @@ -227,6 +227,9 @@ static inline int sortStateVectorsErrHandle(int prop, int pass, int i) { static inline SEXP sortStateVectors(SEXP ordS) { int *ord = INTEGER(ordS); + for (int i = 0; i < Rf_length(ordS); i++) { + ord[i] = 0; // explicitly initialize to avoid valgrind warning + } sbt.o = 0; // we can use sbt.o since all the code has already been output sbt.s[0] = 0; for (int i = 0; i < tb.de.n; i++) { diff --git a/tests/testthat/test-000-modelVars.R b/tests/testthat/test-000-modelVars.R index c2fa41864..bdb8e078e 100644 --- a/tests/testthat/test-000-modelVars.R +++ b/tests/testthat/test-000-modelVars.R @@ -20,6 +20,7 @@ d/dt(y3) = a3*y1*y2 et <- eventTable() et$add.sampling(seq(0, 20, by = 0.01)) + out <- solve(rigid, et) expect_equal(rxModelVars(rigid), rxModelVars(rigid$cmpMgr$rxDll())) diff --git a/tests/testthat/test-phi.R b/tests/testthat/test-phi.R index ea40e15c7..ce8c85591 100644 --- a/tests/testthat/test-phi.R +++ b/tests/testthat/test-phi.R @@ -1,106 +1,104 @@ rxTest({ - rxTest({ - test_that("phi/pnorm/qnorm", { - expect_equal(phi(1:3), pnorm(1:3)) - expect_equal(phi(as.double(1:3)), pnorm(as.double(1:3))) - - o <- rxode2({ - o <- phi(a) - }) - - expect_equal( - rxSolve(o, data.frame(a = 1:3), et(0))$o, - pnorm(as.double(1:3)) - ) - - o <- rxode2({ - o <- pnorm(a) - }) - - expect_equal( - rxSolve(o, data.frame(a = 1:3), et(0))$o, - pnorm(as.double(1:3)) - ) - - o <- rxode2({ - o <- pnorm(a, 0.5) - }) - - expect_equal( - rxSolve(o, data.frame(a = 1:3), et(0))$o, - pnorm(as.double(1:3), 0.5) - ) - - o <- rxode2({ - o <- pnorm(a, 0.5, 2) - }) - - expect_equal( - rxSolve(o, data.frame(a = 1:3), et(0))$o, - pnorm(as.double(1:3), 0.5, 2) - ) - - suppressMessages(expect_error(rxode2({ - o <- pnorm() - }))) - - suppressMessages(expect_error(rxode2({ - o <- pnorm(a, b, c, d) - }))) - - o <- rxode2({ - o <- qnorm(a) - }) - - expect_equal( - rxSolve(o, data.frame(a = 1:3), et(0))$o, - suppressWarnings(qnorm(as.double(1:3))) - ) - - o <- rxode2({ - o <- qnorm(a, 0.5) - }) - - expect_equal( - rxSolve(o, data.frame(a = 1:3), et(0))$o, - suppressWarnings(qnorm(as.double(1:3), 0.5)) - ) - - o <- rxode2({ - o <- qnorm(a, 0.5, 2) - }) - - expect_equal( - rxSolve(o, data.frame(a = 1:3), et(0))$o, - suppressWarnings(qnorm(as.double(1:3), 0.5, 2)) - ) - - suppressMessages(expect_error(rxode2({ - o <- qnorm() - }))) - - suppressMessages(expect_error(rxode2({ - o <- qnorm(a, b, c, d) - }))) - - m <- rxode2({ - o <- pnorm(a) - }) - - skip_if_not_installed("units") - expect_error(rxS(m), NA) - - m <- rxode2({ - o <- pnorm(a, b) - }) - - expect_error(rxS(m), NA) - - m <- rxode2({ - o <- pnorm(a, b, c) - }) - - expect_error(rxS(m), NA) + test_that("phi/pnorm/qnorm", { + expect_equal(phi(1:3), pnorm(1:3)) + expect_equal(phi(as.double(1:3)), pnorm(as.double(1:3))) + + o <- rxode2({ + o <- phi(a) }) + + expect_equal( + rxSolve(o, data.frame(a = 1:3), et(0))$o, + pnorm(as.double(1:3)) + ) + + o <- rxode2({ + o <- pnorm(a) + }) + + expect_equal( + rxSolve(o, data.frame(a = 1:3), et(0))$o, + pnorm(as.double(1:3)) + ) + + o <- rxode2({ + o <- pnorm(a, 0.5) + }) + + expect_equal( + rxSolve(o, data.frame(a = 1:3), et(0))$o, + pnorm(as.double(1:3), 0.5) + ) + + o <- rxode2({ + o <- pnorm(a, 0.5, 2) + }) + + expect_equal( + rxSolve(o, data.frame(a = 1:3), et(0))$o, + pnorm(as.double(1:3), 0.5, 2) + ) + + suppressMessages(expect_error(rxode2({ + o <- pnorm() + }))) + + suppressMessages(expect_error(rxode2({ + o <- pnorm(a, b, c, d) + }))) + + o <- rxode2({ + o <- qnorm(a) + }) + + expect_equal( + rxSolve(o, data.frame(a = 1:3), et(0))$o, + suppressWarnings(qnorm(as.double(1:3))) + ) + + o <- rxode2({ + o <- qnorm(a, 0.5) + }) + + expect_equal( + rxSolve(o, data.frame(a = 1:3), et(0))$o, + suppressWarnings(qnorm(as.double(1:3), 0.5)) + ) + + o <- rxode2({ + o <- qnorm(a, 0.5, 2) + }) + + expect_equal( + rxSolve(o, data.frame(a = 1:3), et(0))$o, + suppressWarnings(qnorm(as.double(1:3), 0.5, 2)) + ) + + suppressMessages(expect_error(rxode2({ + o <- qnorm() + }))) + + suppressMessages(expect_error(rxode2({ + o <- qnorm(a, b, c, d) + }))) + + m <- rxode2({ + o <- pnorm(a) + }) + + skip_if_not_installed("units") + expect_error(rxS(m), NA) + + m <- rxode2({ + o <- pnorm(a, b) + }) + + expect_error(rxS(m), NA) + + m <- rxode2({ + o <- pnorm(a, b, c) + }) + + expect_error(rxS(m), NA) }) }) diff --git a/vignettes/rxode2-syntax.Rmd b/vignettes/rxode2-syntax.Rmd index 3583a590f..026a6a1f2 100644 --- a/vignettes/rxode2-syntax.Rmd +++ b/vignettes/rxode2-syntax.Rmd @@ -13,11 +13,12 @@ vignette: > knitr::opts_chunk$set( collapse = TRUE, comment = "#>") +library(rxode2) ``` ## Introduction -This briefly describes the syntax used to define models +This briefly describes the syntax used to define models that `rxode2` will translate into R-callable compiled code. It also describes the communication of variables between `R` and the `rxode2` modeling specification. @@ -35,7 +36,7 @@ describes the communication of variables between `R` and the ## Bugs and/or deficiencies -- The modulo operator `%%` is currently unsupported. +- The modulo operator `%%` is currently unsupported. ## Note @@ -49,10 +50,10 @@ Below is a commented example to quickly show the capabilities of ## Example -```{r} +``` r f <- function() { ini({ - + }) model({ # An rxode2 model specification (this line is a comment). @@ -86,18 +87,18 @@ via the `d/dt(identifier)` operator as part of the model specification, and which are model parameters via the `params=` argument in `rxode2` `solve()` method: -``` +``` r m1 <- rxode2(model = ode, modName = "m1") # model parameters -- a named vector is required -theta <- +theta <- c(KA=0.29, CL=18.6, V2=40.2, Q=10.5, V3=297, Kin=1, Kout=1, EC50=200) # state variables and their amounts at time 0 (the use of names is # encouraged, but not required) inits <- c(depot=0, centr=0, peri=0, eff=1) -# qd1 is an eventTable specification with a set of dosing and sampling +# qd1 is an eventTable specification with a set of dosing and sampling # records (code not shown here) solve(theta, event = qd1, inits = inits)