Closed mattfidler closed 5 years ago
In general nlmixr functions can have more arbitrary lhs
experssions than typical R.
One other question, do you run R with keep.source=TRUE
or is this even possible?
And drake
assumes all your commands and functions are typical R code. A temporary workaround is to wrap the offending bits in ignore()
. The downside is that drake
does not react to changes inside ignore()
blocks. I will add a special DSL function to tell drake
to track changes in the code but not look for dependencies, something like no_deps()
.
library(drake)
# library(nlmixr)
# It is best to define functions outside the plan.
# Targets are for long-ish computations that produce data.
model_fn <- function() {
ini({
tka <- 0.45 # Log Ka
tcl <- 1 # Log Cl
tv <- 3.45 # Log V
eta.ka ~ 0.6
eta.cl ~ 0.3
eta.v ~ 0.1
add.err <- 0.7
})
ignore(
model({
ka <- exp(tka + eta.ka)
cl <- exp(tcl + eta.cl)
v <- exp(tv + eta.v)
d/dt(depot) = -ka * depot
depot(0) = 3
d/dt(center) = ka * depot - cl / v * center
cp = center / v
cp ~ add(add.err)
})
)
}
# Take shortcuts for the sake of demonstration:
run_nlmixr <- function(...) {NULL}
your_data <- NULL
plan <- drake_plan(analysis = run_nlmixr(model_fn, your_data))
make(plan)
#> target analysis
# Change the contents of the `ignore()` block:
model_fn <- function() {
ini({
tka <- 0.45 # Log Ka
tcl <- 1 # Log Cl
tv <- 3.45 # Log V
eta.ka ~ 0.6
eta.cl ~ 0.3
eta.v ~ 0.1
add.err <- 0.7
})
ignore(
model({
ka <- exp(tka + eta.ka)
cl <- exp(tcl + eta.cl)
})
)
}
# make() does not update the analysis.
make(plan)
#> All targets are already up to date.
Created on 2019-06-17 by the reprex package (v0.3.0)
That would be great. I can confirm the first code works, though.
library(nlmixr)
#> Registered S3 methods overwritten by 'ggplot2':
#> method from
#> [.quosures rlang
#> c.quosures rlang
#> print.quosures rlang
library(drake)
model <- function() {
ini({
tka <- 0.45 # Log Ka
tcl <- 1 # Log Cl
tv <- 3.45 # Log V
eta.ka ~ 0.6
eta.cl ~ 0.3
eta.v ~ 0.1
add.err <- 0.7
})
ignore(model({
ka <- exp(tka + eta.ka)
cl <- exp(tcl + eta.cl)
v <- exp(tv + eta.v)
d/dt(depot) = -ka * depot
depot(0) = 3
d/dt(center) = ka * depot - cl / v * center
cp = center / v
cp ~ add(add.err)
}))
}
m <- nlmixr(model)
print(m)
#> __ RxODE-based ODE model __________________________________________________
#> -- Initialization: --------------------------------------------------------
#> Fixed Effects ($theta):
#> tka tcl tv
#> 0.45 1.00 3.45
#>
#> Omega ($omega):
#> eta.ka eta.cl eta.v
#> eta.ka 0.6 0.0 0.0
#> eta.cl 0.0 0.3 0.0
#> eta.v 0.0 0.0 0.1
#> -- mu-referencing ($muRefTable): ------------------------------------------
#> +-------------------+
#> ¦ theta ¦ eta ¦
#> +---------+---------¦
#> ¦ tka ¦ eta.ka ¦
#> +---------+---------¦
#> ¦ tcl ¦ eta.cl ¦
#> +---------+---------¦
#> ¦ tv ¦ eta.v ¦
#> +-------------------+
#> -- Model: -----------------------------------------------------------------
#> ka <- exp(tka + eta.ka)
#> cl <- exp(tcl + eta.cl)
#> v <- exp(tv + eta.v)
#> d/dt(depot) = -ka * depot
#> depot(0) = 3
#> d/dt(center) = ka * depot - cl / v * center
#> cp = center / v
#> cp ~ add(add.err)
#> ___________________________________________________________________________
Created on 2019-06-17 by the reprex package (v0.3.0)
I haven't been able to successfully run a simple model with drake
+nlmixr
yet, though.
Is there a way to inject the property in the parsing so users of drake
+ nlmixr
will not have to add extra code?
Also does drake
track package versions as well as data files? I couldn't immediately tell from the documentation.
Thank you for you work.
Added no_deps()
in #911.
Is there a way to inject the property in the parsing so users of drake + nlmixr will not have to add extra code?
Sorry, nlmixr
is too much of a niche use case to build into drake
directly.
Also does drake track package versions as well as data files? I couldn't immediately tell from the documentation.
It does not. I recommend renv
or packrat
for this.
I can confirm the first code works, though.
ignore(model({...}))
prevents the error, but it prevents drake
from seeing changes to the model, so the target will not rebuild in make()
if the model changes. On the other hand, if you write no_deps(model({...}))
, make()
detects changes to the model and automatically rebuilds downstream targets as necessary.
Prework
drake
's code of conduct.remotes::install_github("ropensci/drake")
) and mention the SHA-1 hash of the Git commit you install.From
devtools::session_info()
Description
drake
does not parse nlmixr model functions correctly. nlmixr has its own domain specific language to specify nonlinear mixed effects models, which breaksdrake
's DSL (as mentioned as a possibility by #717)Reproducible example
Created on 2019-06-17 by the reprex package (v0.3.0)
Session info
``` r devtools::session_info() #> - Session info ---------------------------------------------------------- #> setting value #> version R version 3.6.0 (2019-04-26) #> os Windows 10 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.1252 #> ctype English_United States.1252 #> tz America/Chicago #> date 2019-06-17 #> #> - Packages -------------------------------------------------------------- #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0) #> backports 1.1.4 2019-04-10 [1] CRAN (R 3.6.0) #> base64url 1.4 2018-05-14 [1] CRAN (R 3.6.0) #> callr 3.2.0 2019-03-15 [1] CRAN (R 3.6.0) #> cli 1.1.0 2019-03-19 [1] CRAN (R 3.6.0) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0) #> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0) #> devtools 2.0.2 2019-04-08 [1] CRAN (R 3.6.0) #> digest 0.6.19 2019-05-20 [1] CRAN (R 3.6.0) #> drake * 7.4.0.9000 2019-06-17 [1] Github (ropensci/drake@da7d2ab) #> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0) #> fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.0) #> glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.0) #> highr 0.8 2019-03-20 [1] CRAN (R 3.6.0) #> htmltools 0.3.6 2017-04-28 [1] CRAN (R 3.6.0) #> igraph 1.2.4.1 2019-04-22 [1] CRAN (R 3.6.0) #> knitr 1.23 2019-05-18 [1] CRAN (R 3.6.0) #> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.0) #> pillar 1.4.1 2019-05-28 [1] CRAN (R 3.6.0) #> pkgbuild 1.0.3 2019-03-20 [1] CRAN (R 3.6.0) #> pkgconfig 2.0.2 2018-08-16 [1] CRAN (R 3.6.0) #> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.0) #> prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.6.0) #> processx 3.3.1 2019-05-08 [1] CRAN (R 3.6.0) #> ps 1.3.0 2018-12-21 [1] CRAN (R 3.6.0) #> R6 2.4.0 2019-02-14 [1] CRAN (R 3.6.0) #> Rcpp 1.0.1 2019-03-17 [1] CRAN (R 3.6.0) #> remotes 2.0.4 2019-04-10 [1] CRAN (R 3.6.0) #> rlang 0.3.4 2019-04-07 [1] CRAN (R 3.6.0) #> rmarkdown 1.13 2019-05-22 [1] CRAN (R 3.6.0) #> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0) #> storr 1.2.1 2018-10-18 [1] CRAN (R 3.6.0) #> stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0) #> testthat 2.1.1 2019-04-23 [1] CRAN (R 3.6.0) #> tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.0) #> usethis 1.5.0 2019-04-07 [1] CRAN (R 3.6.0) #> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0) #> xfun 0.7 2019-05-14 [1] CRAN (R 3.6.0) #> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.6.0) #> #> [1] c:/R/nlmixr_1.1.0-9/R/library ```Provide a minimal reproducible example with code and output that demonstrates the bug. The
reprex
package is extremely helpful for this.Session info
End the reproducible example with a call to
sessionInfo()
in the same session (e.g.reprex(si = TRUE)
) and include the output.Expected output
What output would the correct behavior have produced?
Just the complete plan