Skip to content

Commit

Permalink
Merge pull request #795 from nlmixr2/795-cran-issue
Browse files Browse the repository at this point in the history
CRAN issues
  • Loading branch information
mattfidler authored Sep 26, 2024
2 parents 096e100 + ad80998 commit b1fd587
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 121 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", comment=c(ORCID="0000-0001-8538-6691")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions man/reexports.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions man/rmdhunks/rxode2-create-models.Rmd
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,7 +15,7 @@ mod <- rxode2({

- Inside a `rxode2("")` string statement:

```{r modString}
``` r
mod <- rxode2("
# simple assignment
C2 <- centr/V2
Expand All @@ -27,7 +27,7 @@ mod <- rxode2("

- In a file name to be loaded by rxode2:

```{r modFile}
``` r
writeLines("
# simple assignment
C2 <- centr/V2
Expand All @@ -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
Expand Down Expand Up @@ -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
```

Expand Down
3 changes: 3 additions & 0 deletions src/genModelVars.h
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-000-modelVars.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
202 changes: 100 additions & 102 deletions tests/testthat/test-phi.R
Original file line number Diff line number Diff line change
@@ -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)
})
})
15 changes: 8 additions & 7 deletions vignettes/rxode2-syntax.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand All @@ -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).
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b1fd587

Please sign in to comment.