diff --git a/.Rbuildignore b/.Rbuildignore index d797a4dad..dc84e5147 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,5 @@ +Doxygen +doxyfile man/figures/README-.*\.png$ README.html DOCS/ diff --git a/.gitignore b/.gitignore index 823d4d287..833bab4dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +Doxygen DOCS mrgsolve.Rcheck .DS_store @@ -11,3 +12,4 @@ Rchecks *.tar.gz !package/*.tar.gz *00_pkg_src +inst/maintenance/unit/tests.md diff --git a/DESCRIPTION b/DESCRIPTION index 0a1c3239f..57d8dd161 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,22 +1,39 @@ -Package: mrgsolve Type: Package -Version: 0.10.0 +Package: mrgsolve Title: Simulate from ODE-Based Models -Authors@R: c( - person("Kyle T", "Baron", email = "kyleb@metrumrg.com", role=c("aut", "cre"), comment=c(ORCID="0000-0001-7252-5656")), - person("Bill", "Gillespie", role = "ctb"), - person("Charles", "Margossian", role = "ctb"), - person("Devin", "Pastoor", role = "ctb"), - person("Bill", "Denney", role = "ctb", comment=c(ORCID="0000-0002-5759-428X")), - person("Dilawar", "Singh", role = "ctb"), - person("Metrum Research Group", role = "cph") - ) -Maintainer: Kyle T Baron -URL: https://github.com/metrumresearchgroup/mrgsolve -BugReports: https://github.com/metrumresearchgroup/mrgsolve/issues -Description: Fast simulation from ordinary differential equation (ODE) based - models typically employed in quantitative pharmacology and systems biology. +Version: 0.10.1 +Authors@R: + c(person(given = "Kyle T", + family = "Baron", + role = c("aut", "cre"), + email = "kyleb@metrumrg.com", + comment = c(ORCID = "0000-0001-7252-5656")), + person(given = "Bill", + family = "Gillespie", + role = "ctb"), + person(given = "Charles", + family = "Margossian", + role = "ctb"), + person(given = "Devin", + family = "Pastoor", + role = "ctb"), + person(given = "Bill", + family = "Denney", + role = "ctb", + comment = c(ORCID = "0000-0002-5759-428X")), + person(given = "Dilawar", + family = "Singh", + role = "ctb"), + person(given = "Metrum Research Group", + role = "cph")) +Maintainer: Kyle T Baron +Description: Fast simulation from ordinary differential equation + (ODE) based models typically employed in quantitative pharmacology and + systems biology. License: GPL (>=2) +URL: https://github.com/metrumresearchgroup/mrgsolve +BugReports: + https://github.com/metrumresearchgroup/mrgsolve/issues Depends: R (>= 3.1.2), methods @@ -26,23 +43,28 @@ Imports: magrittr (>= 1.5), RcppArmadillo (>= 0.7.900.2.0), tibble (>= 2.1.1), - rlang (>= 0.3.4), - tidyselect (>= 0.2.5) -LinkingTo: - Rcpp (>= 0.12.12), - RcppArmadillo (>= 0.7.900.2.0), - BH (>= 1.62.0-1) + rlang (>= 0.3.4), + tidyselect (>= 0.2.5), + lifecycle, + glue Suggests: lattice, testthat, xml2 (>= 1.2.0), - rmarkdown, - yaml, + rmarkdown, + yaml, knitr -LazyLoad: yes -NeedsCompilation: yes +LinkingTo: + Rcpp (>= 0.12.12), + RcppArmadillo (>= 0.7.900.2.0), + BH (>= 1.62.0-1) +RdMacros: + lifecycle Encoding: UTF-8 Language: en-US +LazyLoad: yes +NeedsCompilation: yes +RoxygenNote: 7.0.2 SystemRequirements: C++11 Collate: 'RcppExports.R' @@ -92,4 +114,3 @@ Collate: 'render.R' 'update.R' 'workflows.R' -RoxygenNote: 6.1.1 diff --git a/Makefile b/Makefile index 76a1e0f83..e68eb29f5 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,7 @@ doc: Rscript inst/maintenance/doc_mrgsolve.R build: - R CMD build --md5 $(PKGDIR) + R CMD build --md5 $(PKGDIR) --no-manual install: R CMD INSTALL --install-tests ${TARBALL} -l ~/Rlibs @@ -83,7 +83,7 @@ check: make house make doc make build - R CMD check ${TARBALL} -o ${CHKDIR} + R CMD check ${TARBALL} -o ${CHKDIR} --no-manual make unit qcheck: @@ -134,4 +134,7 @@ check-win: check-winhub: Rscript -e 'rhub::check_on_windows()' +.PHONY: doxygen +doxygen: + doxygen doxyfile diff --git a/NAMESPACE b/NAMESPACE index 0ec53e067..93cc07f53 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,8 +1,11 @@ # Generated by roxygen2: do not edit by hand +S3method(.DollarNames,mrgmod) +S3method(.DollarNames,mrgsims) S3method(Req,mrgmod) S3method(all,equal.mrgmod) S3method(as.data.frame,ev) +S3method(as.environment,mrgmod) S3method(as.matrix,ev) S3method(as.tbl,mrgsims) S3method(as_tibble,mrgsims) @@ -59,6 +62,7 @@ S3method(summarise,each) S3method(summarise,mrgsims) S3method(summary,mrgmod) S3method(summary,mrgsims) +S3method(within,mrgmod) export("%>%") export("%then%") export(Req) @@ -104,6 +108,7 @@ export(expand_observations) export(file_show) export(filter) export(filter_sims) +export(house) export(idata_set) export(init) export(inventory) @@ -137,6 +142,7 @@ export(numerics_only) export(obsaug) export(obsonly) export(omat) +export(outvars) export(parse_rx) export(plot_sims) export(qsim) @@ -146,6 +152,7 @@ export(req) export(revar) export(s_) export(see) +export(select_sims) export(simargs) export(smat) export(soloc) @@ -235,11 +242,14 @@ importFrom(dplyr,summarise) importFrom(dplyr,summarise_at) importFrom(dplyr,summarise_each) importFrom(dplyr,ungroup) +importFrom(glue,glue) +importFrom(lifecycle,deprecate_soft) importFrom(magrittr,"%>%") importFrom(magrittr,"%T>%") importFrom(rlang,"!!!") importFrom(rlang,"!!") importFrom(rlang,enquo) +importFrom(rlang,enquos) importFrom(rlang,eval_tidy) importFrom(rlang,quo_name) importFrom(rlang,quos) @@ -250,6 +260,7 @@ importFrom(stats,setNames) importFrom(tibble,as_tibble) importFrom(tibble,tibble) importFrom(tidyselect,vars_select) +importFrom(utils,.DollarNames) importFrom(utils,assignInMyNamespace) importFrom(utils,capture.output) importFrom(utils,example) diff --git a/NEWS.md b/NEWS.md index 28de83d60..54b5f5101 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,26 @@ +# mrgsolve 0.10.1 + +- Add `select_sims` method for selecting columns in `mrgsims` object #585 +- Fix bug where system was improperly advanced on steady state dosing record + with a lag time when the system failed to reach steady state #596 +- Add better compartment level control for advancing system to steady state #598 +- Allow user to set `CXX_FLAGS` in `$ENV` block #603 +- Add `N_CMT` plugin so that the number (index) of every compartment is available + by name (e.g. `N_CENT` for the number index of the central compartment) #606 +- Fix bug where `blocks()` failed when the model was defined in `Rmd` file #608 +- Call ODE block every time the system tries to advance so that variables + calculated in ODE are properly calculated in output #613 +- Add `within` method for mrgmod #616 +- Access initial compartment values and other model object items with `$` + operator for `mrgmod` #620 +- Add plot method for signature `c("mrgsims", "character")`; pass in a character + vector of outputs to plot #630 +- The house model, previously accessible by `mrgsolve:::house()` is now an + exported function #625 +- Exporting outvars function to extract names of current output variables from + the model object +- Now importing lifecycle and glue packages + # mrgsolve 0.10.0 - Remove `qsim` and all associated functions diff --git a/R/Aaaa.R b/R/Aaaa.R index 84c4664cc..9fdd93c56 100644 --- a/R/Aaaa.R +++ b/R/Aaaa.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -15,43 +15,46 @@ # You should have received a copy of the GNU General Public License # along with mrgsolve. If not, see . -##' @import methods -##' -##' @importFrom utils capture.output example str type.convert -##' @importFrom utils packageVersion assignInMyNamespace read.table -##' @importFrom stats as.formula setNames rnorm -##' @importFrom dplyr filter -##' @importFrom dplyr mutate slice as.tbl pull -##' @importFrom dplyr bind_rows arrange summarise summarise_at -##' @importFrom dplyr intersect select rename slice distinct do -##' @importFrom dplyr distinct first select_vars_ -##' @importFrom dplyr select_vars everything -##' @importFrom dplyr if_else mutate_at summarise_each is.tbl select -##' @importFrom dplyr mutate_all group_by ungroup n -##' @importFrom dplyr data_frame as_data_frame -##' @importFrom tidyselect vars_select -##' @importFrom magrittr %>% %T>% -##' @importFrom Rcpp evalCpp -##' @importFrom RcppArmadillo armadillo_version -##' @importFrom tibble tibble as_tibble -##' @importFrom rlang quos enquo quo_name syms !!! !! eval_tidy -##' -##' @include Aaaa.R -##' @include class_mrgsims.R -##' @include class_mrgmod.R -##' @include class_derived.R -##' @include class_ev.R -##' @include class_matlist.R -##' @include class_numericlist.R -##' @include class_tgrid.R -##' @include generics.R -##' @include package.R -##' @include utils.R -##' @include RcppExports.R -##' +#' @import methods +#' +#' @importFrom utils capture.output example str type.convert +#' @importFrom utils packageVersion assignInMyNamespace read.table +#' @importFrom utils .DollarNames +#' @importFrom stats as.formula setNames rnorm +#' @importFrom dplyr filter +#' @importFrom dplyr mutate slice as.tbl pull +#' @importFrom dplyr bind_rows arrange summarise summarise_at +#' @importFrom dplyr intersect select rename slice distinct do +#' @importFrom dplyr distinct first select_vars_ +#' @importFrom dplyr select_vars everything +#' @importFrom dplyr if_else mutate_at summarise_each is.tbl select +#' @importFrom dplyr mutate_all group_by ungroup n +#' @importFrom dplyr data_frame as_data_frame +#' @importFrom tidyselect vars_select +#' @importFrom magrittr %>% %T>% +#' @importFrom Rcpp evalCpp +#' @importFrom RcppArmadillo armadillo_version +#' @importFrom tibble tibble as_tibble +#' @importFrom rlang quos enquo enquos quo_name syms !!! !! eval_tidy +#' @importFrom lifecycle deprecate_soft +#' @importFrom glue glue +#' +#' @include Aaaa.R +#' @include class_mrgsims.R +#' @include class_mrgmod.R +#' @include class_derived.R +#' @include class_ev.R +#' @include class_matlist.R +#' @include class_numericlist.R +#' @include class_tgrid.R +#' @include generics.R +#' @include package.R +#' @include utils.R +#' @include RcppExports.R +#' NULL -##' @export +#' @export dplyr::filter GLOBALS <- new.env() diff --git a/R/annot.R b/R/annot.R index 245b34e39..89822dd78 100644 --- a/R/annot.R +++ b/R/annot.R @@ -47,12 +47,16 @@ parse_annot_line <- function(x, novalue=FALSE, noname=FALSE,context="not given") x <- mytriml(x) if(nchar(x)==0) return(NULL) - + col <- charcount(x,":")[1] if(col != (2-noname-novalue)) { - stop("improper annotation format ", x,"\n", - " Context: ", context, call.=FALSE) + stop( + "improper annotation format\n", + " input: ", x, "\n", + " context: ", context, + call.=FALSE + ) } ## Fix up line if not name : value : other @@ -100,7 +104,7 @@ parse_annot_line <- function(x, novalue=FALSE, noname=FALSE,context="not given") ##' with \code{mrgsolve:::details()}. ##' ##' @examples -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' ##' mrgsolve:::details(mod) ##' diff --git a/R/chain.R b/R/chain.R index 52883f63e..b60a3f36f 100644 --- a/R/chain.R +++ b/R/chain.R @@ -39,7 +39,7 @@ ##' strictly for compartments. ##' ##' @examples -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' ##' mod %>% Req(CP,RESP) %>% ev(amt=1000) %>% mrgsim ##' @@ -108,7 +108,7 @@ carry.out <- function(x,...) { ##' ##' @examples ##' # The model is in hours: -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' ##' # The output is in days: ##' mod %>% tscale(1/24) %>% mrgsim @@ -187,7 +187,7 @@ obsaug <- function(x,value=TRUE,...) { ##' ##' idata <- data[,c("ID", "amt")] ##' -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' ##' mod %>% ##' omat(dmat(1,1,1,1)) %>% diff --git a/R/class_mrgmod.R b/R/class_mrgmod.R index 7533ca4f3..60bf7b81a 100644 --- a/R/class_mrgmod.R +++ b/R/class_mrgmod.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -138,7 +138,8 @@ protomod <- list(model=character(0), code = character(0), annot = list(), envir = new.env(), - plugin = character(0) + plugin = character(0), + ss_cmt = integer(0) ) slot.names <- names(protomod) @@ -172,69 +173,71 @@ valid.mrgmod <- function(object) { -##' S4 class for mrgsolve model object +#' S4 class for mrgsolve model object ##' -##' @section Notes: -##' \itemize{ -##' \item Spaces in paths (\code{project} and \code{soloc}) are prohibited. +#' @section Notes: +#' \itemize{ +#' \item Spaces in paths (\code{project} and \code{soloc}) are prohibited. ##' -##' } +#' } ##' -##' @slot model model name \code{} -##' @slot modfile source model specification file name \code{} -##' @slot package the shared object file name \code{character>} -##' @slot project working directory; must be writeable with no spaces -##' \code{} -##' @slot start simulation start time \code{} -##' @slot end simulation end time \code{} -##' @slot delta simulation time interval \code{} -##' @slot add additional simulation times \code{} -##' @slot param \code{} -##' @slot fixed a \code{} of fixed value parameters; -##' these are not updatable from \code{R} -##' @slot init \code{} -##' @slot digits significant digits in simulated output; negative integer means -##' ignore \code{} -##' @slot hmin passed to \code{\link[=solversettings]{dlsoda}} \code{} -##' @slot hmax passed to \code{\link[=solversettings]{dlsoda}} \code{} -##' @slot mxhnil passed to \code{\link[=solversettings]{dlsoda}} -##' \code{} -##' @slot ixpr passed to \code{\link[=solversettings]{dlsoda}} \code{} -##' @slot atol passed to \code{\link[=solversettings]{dlsoda}} \code{} -##' @slot rtol passed to \code{\link[=solversettings]{dlsoda}} \code{} -##' @slot maxsteps passed to \code{\link[=solversettings]{dlsoda}} -##' \code{} -##' @slot preclean passed to R CMD SHLIB during compilation \code{} -##' @slot verbose print run information to screen \code{} -##' @slot quiet print various information to screen \code{} -##' @slot debug not used -##' @slot tscale used to scale time in simulated output \code{} -##' @slot omega \code{\link{matlist}} for simulating individual-level random -##' effects -##' @slot sigma \code{\link{matlist}} for simulating residual error variates -##' @slot args \code{} of arguments to be passed to \code{\link{mrgsim}} -##' @slot advan either 2, 4, or 13 \code{} -##' @slot trans either 1, 2, 4, or 11 \code{} -##' @slot request vector of compartments to request \code{} -##' @slot soloc directory path for storing the model shared object -##' \code{} -##' @slot code a character vector of the model code -##' @slot capture a character vector of variables that are captured from -##' the simulation \code{} -##' @slot mindt minimum time between simulation records \code{} -##' @slot envir internal model environment \code{} -##' @slot shlib a list of data related to build outcome \code{} -##' @slot funs symbol names for model functions in the shared object -##' @slot annot model annotations \code{} -##' @slot plugin model plugins \code{} -##' @slot Icap capture indices to recover in the simulation -##' @slot capL labels for \code{Icap} -##' @slot Icmt compartment indices to recover in the simulation -##' @slot cmtL labels for \code{Icmt} -##' -##' @seealso \code{\link[mrgsolve]{update}}, \code{\link{solversettings}} -##' @keywords internal -##' @export +#' @slot model model name \code{} +#' @slot modfile source model specification file name \code{} +#' @slot package the shared object file name \code{character>} +#' @slot project working directory; must be writeable with no spaces +#' \code{} +#' @slot start simulation start time \code{} +#' @slot end simulation end time \code{} +#' @slot delta simulation time interval \code{} +#' @slot add additional simulation times \code{} +#' @slot param \code{} +#' @slot fixed a \code{} of fixed value parameters; +#' these are not updatable from \code{R} +#' @slot init \code{} +#' @slot digits significant digits in simulated output; negative integer means +#' ignore \code{} +#' @slot hmin passed to \code{\link[=solversettings]{dlsoda}} \code{} +#' @slot hmax passed to \code{\link[=solversettings]{dlsoda}} \code{} +#' @slot mxhnil passed to \code{\link[=solversettings]{dlsoda}} +#' \code{} +#' @slot ixpr passed to \code{\link[=solversettings]{dlsoda}} \code{} +#' @slot atol passed to \code{\link[=solversettings]{dlsoda}} \code{} +#' @slot rtol passed to \code{\link[=solversettings]{dlsoda}} \code{} +#' @slot maxsteps passed to \code{\link[=solversettings]{dlsoda}} +#' \code{} +#' @slot preclean passed to R CMD SHLIB during compilation \code{} +#' @slot verbose print run information to screen \code{} +#' @slot quiet print various information to screen \code{} +#' @slot debug not used +#' @slot tscale used to scale time in simulated output \code{} +#' @slot omega \code{\link{matlist}} for simulating individual-level random +#' effects +#' @slot sigma \code{\link{matlist}} for simulating residual error variates +#' @slot args \code{} of arguments to be passed to \code{\link{mrgsim}} +#' @slot advan either 2, 4, or 13 \code{} +#' @slot trans either 1, 2, 4, or 11 \code{} +#' @slot request vector of compartments to request \code{} +#' @slot soloc directory path for storing the model shared object +#' \code{} +#' @slot code a character vector of the model code +#' @slot capture a character vector of variables that are captured from +#' the simulation \code{} +#' @slot mindt minimum time between simulation records \code{} +#' @slot envir internal model environment \code{} +#' @slot shlib a list of data related to build outcome \code{} +#' @slot funs symbol names for model functions in the shared object +#' @slot annot model annotations \code{} +#' @slot plugin model plugins \code{} +#' @slot Icap capture indices to recover in the simulation \code{} +#' @slot capL labels for \code{Icap}; \code{} +#' @slot Icmt compartment indices to recover in the simulation \code{} +#' @slot cmtL labels for \code{Icmt}; \code{} +#' @slot ss_cmt compartments numbers to be considered when advancing the system +#' to steady state \code{} +#' +#' @seealso \code{\link[mrgsolve]{update}}, \code{\link{solversettings}} +#' @keywords internal +#' @export setClass("mrgmod",slots=slots, validity=valid.mrgmod, prototype=protomod) setClass("packmod", @@ -255,25 +258,28 @@ initialize_mrgmod <- function(.Object, ...) { .Object@shlib[["neq"]] <- length(.Object@shlib[["cmt"]]) .Object@shlib[["version"]] <- GLOBALS[["version"]] .Object <- default_outputs(.Object) + .Object@ss_cmt <- seq_along(Cmt(.Object)) - 1L .Object } setMethod("initialize", "mrgmod", initialize_mrgmod) -##' Return a pre-compiled, PK/PD model -##' -##' @param ... passed to \code{\link[mrgsolve]{update}} -##' -##' @return -##' A \code{packmod} object, ready to simulate. -##' -##' @examples -##' -##' mod <- mrgsolve:::house() -##' -##' see(mod) -##' -##' mod %>% ev(amt=100) %>% mrgsim %>% plot -##' +#' Return a pre-compiled, PK/PD model +#' +#' @param ... passed to \code{\link[mrgsolve]{update}} +#' +#' @return +#' A \code{packmod} object, ready to simulate. +#' +#' @examples +#' +#' mod <- mrgsolve::house() +#' +#' see(mod) +#' +#' mod %>% ev(amt=100) %>% mrgsim %>% plot +#' +#' @keywords internal +#' @export house <- function(...) { project <- mrgsolve_file("project") att <- as_pack_mod("housemodel", project, "mrgsolve") @@ -307,14 +313,14 @@ as_pack_mod <- function(model, project, PACKAGE) { return(list(mod=x, soloc=soloc, source=source)) } -##' Check if an object is a model object -##' -##' The function checks to see if the object is either -##' \code{mrgmod} or \code{packmod}. -##' -##' @param x any object -##' @return \code{TRUE} if \code{x} inherits \code{mrgsims}. -##' @export +#' Check if an object is a model object +#' +#' The function checks to see if the object is either +#' \code{mrgmod} or \code{packmod}. +#' +#' @param x any object +#' @return \code{TRUE} if \code{x} inherits \code{mrgsims}. +#' @export is.mrgmod <- function(x) inherits(x,c("mrgmod","packmod")) see_compfile <- function(x) { @@ -333,9 +339,9 @@ setMethod("project", "packmod", function(x,...) { return(file.path(path.package(x@package),"project")) }) -##' @rdname cmtn -##' @param tag compartment name -##' @export +#' @rdname cmtn +#' @param tag compartment name +#' @export setMethod("cmtn", "mrgmod", function(x,tag,...) { return(which(cmt(x)==tag)) }) @@ -357,19 +363,19 @@ Cmti <- function(x) x@Icmt Capturei <- function(x) x@Icap CAPTUREI <- function(x) c(length(x@capture),x@Icap-1L) -##' Return the location of the model shared object +#' Return the location of the model shared object ##' -##' @param x model object -##' @param short logical; if \code{TRUE}, \code{soloc} will -##' be rendered with a short path name -##' -##' @rdname soloc -##' -##' @examples -##' mod <- mrgsolve:::house() -##' soloc(mod) -##' -##' @export +#' @param x model object +#' @param short logical; if \code{TRUE}, \code{soloc} will +#' be rendered with a short path name +#' +#' @rdname soloc +#' +#' @examples +#' mod <- mrgsolve::house() +#' soloc(mod) +#' +#' @export soloc <- function(x,short=FALSE) { if(short) return(build_path(x@soloc)) return(x@soloc) @@ -387,17 +393,17 @@ setMethod("sodll", "packmod", function(x,...) { return(pathfun(getLoadedDLLs()[[x@package]][["path"]])) }) -##' Get all names from a model object -##' -##' @param x the model object -##' -##' @aliases names,mrgmod-method -##' -##' @examples -##' mod <- mrgsolve:::house() -##' names(mod) -##' -##' @export +#' Get all names from a model object +#' +#' @param x the model object +#' +#' @aliases names,mrgmod-method +#' +#' @examples +#' mod <- mrgsolve::house() +#' names(mod) +#' +#' @export setMethod("names", "mrgmod", function(x) { ans <- list() ans$param <- Pars(x) @@ -410,66 +416,68 @@ setMethod("names", "mrgmod", function(x) { return(ans) }) -##' Coerce a model object to list -##' -##' @param x mrgmod object -##' @param deep if `TRUE`, extra information is returned -##' (see details). -##' @param ... not used -##' -##' @details -##' If `deep` is `TRUE`, then the values for -##' `trans`,`advan`, and `mindt` are -##' returned as well as a summary of internal model -##' functions (with a call to `mrgsolve:::funset`). -##' -##' @section Slots: -##' - `npar`: number of parameters -##' - `neq`: number of compartments or differential equations -##' - `pars`: names of model parameters -##' - `covariates`: names of parameters identified as covariates -##' - `cmt`: names of model compartments -##' - `param`: the parameter list -##' - `init`: initial condition list -##' - `omega`: `$OMEGA` matrices, as a `matlist` object -##' - `sigma`: `$SIGMA` matrices, as a `matlist` object -##' - `fixed`: named list of `$FIXED` values -##' - `model`: model name -##' - `project`: model project directory -##' - `soloc`: directory where the model is being built -##' - `sodll`: complete path to the model shared object -##' - `cfile`: path for the model source code file -##' - `shlib`: list of compilation information -##' - `start`: simulation start time -##' - `end`: simulation end time -##' - `delta`: simulation time step -##' - `add`: additional simulation times -##' - `capture`: names of captured data items -##' - `request`: compartments requested upon simulation -##' - `cmti`: named indices for current output compartments -##' - `capturei`: named indices for current output capture -##' - `random`: names and labels of `$OMEGA` and `$SIGMA` -##' - `code`: model source code from `cfile` -##' - `details`: model details data frame -##' - `atol`: see [solversettings] -##' - `rtol`: see [solversettings] -##' - `maxsteps`: see [solversettings] -##' - `hmin`: see [solversettings] -##' - `hmax`: see [solversettings] -##' - `envir`: the model environment -##' - `plugins`: plugins invoked in the model -##' - `digits`: number of digits to request in simulated data - -##' - `tscale`: multiplicative scalar for time in results only -##' - `mindt`: simulation output time below which there model will assume to -##' have not advanced -##' - `preclean`: logical indicating to clean up compilation artifacts prior -##' to compiling -##' - `debug`: print debugging information during simulation run -##' - `verbose`: print extra information during setup for model run -##' -##' @md -##' @export + + +#' Coerce a model object to list +#' +#' @param x mrgmod object +#' @param deep if `TRUE`, extra information is returned +#' (see details). +#' @param ... not used +#' +#' @details +#' If `deep` is `TRUE`, then the values for +#' `trans`,`advan`, and `mindt` are +#' returned as well as a summary of internal model +#' functions (with a call to `mrgsolve:::funset`). +#' +#' @section Slots: +#' - `npar`: number of parameters +#' - `neq`: number of compartments or differential equations +#' - `pars`: names of model parameters +#' - `covariates`: names of parameters identified as covariates +#' - `cmt`: names of model compartments +#' - `param`: the parameter list +#' - `init`: initial condition list +#' - `omega`: `$OMEGA` matrices, as a `matlist` object +#' - `sigma`: `$SIGMA` matrices, as a `matlist` object +#' - `fixed`: named list of `$FIXED` values +#' - `model`: model name +#' - `project`: model project directory +#' - `soloc`: directory where the model is being built +#' - `sodll`: complete path to the model shared object +#' - `cfile`: path for the model source code file +#' - `shlib`: list of compilation information +#' - `start`: simulation start time +#' - `end`: simulation end time +#' - `delta`: simulation time step +#' - `add`: additional simulation times +#' - `capture`: names of captured data items +#' - `request`: compartments requested upon simulation +#' - `cmti`: named indices for current output compartments +#' - `capturei`: named indices for current output capture +#' - `random`: names and labels of `$OMEGA` and `$SIGMA` +#' - `code`: model source code from `cfile` +#' - `details`: model details data frame +#' - `atol`: see [solversettings] +#' - `rtol`: see [solversettings] +#' - `maxsteps`: see [solversettings] +#' - `hmin`: see [solversettings] +#' - `hmax`: see [solversettings] +#' - `envir`: the model environment +#' - `plugins`: plugins invoked in the model +#' - `digits`: number of digits to request in simulated data + +#' - `tscale`: multiplicative scalar for time in results only +#' - `mindt`: simulation output time below which there model will assume to +#' have not advanced +#' - `preclean`: logical indicating to clean up compilation artifacts prior +#' to compiling +#' - `debug`: print debugging information during simulation run +#' - `verbose`: print extra information during setup for model run +#' +#' @md +#' @export setMethod("as.list", "mrgmod", function(x, deep = FALSE, ...) { within(list(), { @@ -524,56 +532,65 @@ setMethod("as.list", "mrgmod", function(x, deep = FALSE, ...) { }) -##' Select parameter values from a model object -##' -##' The \code{$} and \code{[[} operators get the value -##' of a single parameter in the model. The -##' \code{[} gets several values, returning a -##' named list. -##' -##' @param x mrgmod object -##' @param name parameter to take -##' @param i an element to select -##' @param exact not used -##' @rdname mrgmod_extract -##' @export -setMethod("$", "mrgmod", function(x, name){ - if(! name %in% Pars(x)) { - stop( - "Parameter ", name, " not found in the parameter list.", - call.=FALSE - ) - } - unname(as.numeric(allparam(x))[name]) +#' Select parameter values from a model object +#' +#' The \code{$} and \code{[[} operators get the value +#' of a single parameter in the model. The +#' \code{[} gets several values, returning a +#' named list. +#' +#' @param x mrgmod object +#' @param name parameter to take +#' @param i an element to select +#' @param exact not used +#' @rdname mrgmod_extract +#' @export +setMethod("$", "mrgmod", function(x, name) { + x[[name]] }) -##' @rdname mrgmod_extract -##' @export +#' @rdname mrgmod_extract +#' @export setMethod("[[", "mrgmod", function(x, i, exact=TRUE) { - if(!i %in% Pars(x)) { - stop( - "Parameter ", i, " not found in the parameter list.", - call.=FALSE - ) + if(i %in% Pars(x)) { + return(unname(as.numeric(allparam(x))[i])) + } + if(i %in% Cmt(x)) { + return(unname(as.numeric(init(x))[i])) + } + l <- as.list(x) + if(exists(i,l)) { + return(unname(l[[i]])) } - unname(as.list(allparam(x))[[i]]) + wstop( + "item '", i, "' not found or not extractable with $ or [[ operator." + ) }) -##' @rdname mrgmod_extract -##' @export +#' @rdname mrgmod_extract +#' @export setMethod("[", "mrgmod", function(x, i) { - if(!all(i %in% Pars(x))) { - wrong <- paste0(setdiff(i, Pars(x)),collapse=',') - stop( - "Parameter(s) ", wrong, " not found in the parameter list.", - call.=FALSE - ) + env <- c(as.list(param(x)),as.list(init(x))) + if(!all(i %in% names(env))) { + env <- c(env,as.list(x)) } - as.list(allparam(x))[i] + if(!all(i %in% names(env))) { + wrong <- shQuote(setdiff(i, names(env))) + for(j in seq_along(wrong)) { + message(" Problem: item ", wrong[j], " not found") + } + wstop("requested items(s) not found or not extractable with [ operator.") + } + env[i] }) -##' @rdname see -##' @export +#' @export +as.environment.mrgmod <- function(x) { + list2env(c(as.list(param(x)),as.list(init(x)),as.list(x))) +} + +#' @rdname see +#' @export setMethod("see", "mrgmod", function(x,raw=FALSE, ...) { if(raw) return(x@code) what <- x@code @@ -589,8 +606,8 @@ setMethod("see", "mrgmod", function(x,raw=FALSE, ...) { return(invisible(NULL)) }) -##' @rdname loadso -##' @export +#' @rdname loadso +#' @export loadso.mrgmod <- function(x,...) { if(.Platform$OS.type!="unix") { try(dyn.unload(sodll(x)),silent=TRUE) @@ -613,27 +630,27 @@ unloadso.mrgmod <- function(x, ...) { return(invisible(NULL)) } -##' @rdname tgrid -##' @export +#' @rdname tgrid +#' @export setMethod("stime", "mrgmod", function(x,...) { render_time(x) }) -##' @rdname revar -##' @export +#' @rdname revar +#' @export setMethod("revar", "mrgmod", function(x,...) { return(list(omega=x@omega,sigma=x@sigma)) }) -##' @rdname blocks -##' @export +#' @rdname blocks +#' @export setMethod("blocks", "mrgmod", function(x,...) { what <- as.character(match.call()[-1])[-1] blocks_(cfile(x),what) }) -##' @rdname blocks -##' @export +#' @rdname blocks +#' @export setMethod("blocks", "character", function(x,...) { what <- as.character(match.call()[-1])[-1] blocks_(x,what) @@ -669,8 +686,12 @@ summary.mrgmod <- function(object,...) { blocks_ <- function(file,what) { if(length(what)==0) what <- c("PARAM","MAIN", "ODE","DES", "TABLE") - if(!file_exists(file)) stop("Can't find model file", call.=FALSE) - bl <- modelparse(readLines(file, warn=FALSE)) + if(!file_exists(file)) wstop("can't find model file.") + if(grepl("\\.Rmd$", file)) { + bl <- modelparse_rmd(readLines(file, warn=FALSE)) + } else { + bl <- modelparse(readLines(file, warn=FALSE)) + } if(!any(what == "all")) bl <- bl[names(bl) %in% what] if(length(bl)==0) { message("No blocks found.") @@ -691,18 +712,19 @@ parin <- function(x) { verbose=as.integer(x@verbose),debug=x@debug, digits=x@digits, tscale=x@tscale, mindt=x@mindt, advan=x@advan, - ss_n = 500, ss_fixed = FALSE + ss_n = 500, ss_fixed = FALSE, + ss_cmt = x@ss_cmt ) } -##' Show model specification and C++ files -##' -##' @param x model object -##' @param spec logical; show the model specification file -##' @param source logical; show the C++ file that is actually compiled -##' @param ... not used -##' @export -##' @keywords internal +#' Show model specification and C++ files +#' +#' @param x model object +#' @param spec logical; show the model specification file +#' @param source logical; show the C++ file that is actually compiled +#' @param ... not used +#' @export +#' @keywords internal file_show <- function(x,spec=TRUE,source=TRUE,...) { stopifnot(is.mrgmod(x)) what <- list() @@ -712,7 +734,7 @@ file_show <- function(x,spec=TRUE,source=TRUE,...) { } -##' @export +#' @export all.equal.mrgmod <- function(target, current,...) { target.env <- as.list(target@envir) current.env <- as.list(current@envir) @@ -721,3 +743,32 @@ all.equal.mrgmod <- function(target, current,...) { t2 <- identical(target.env, current.env) all(t1,t2) } + +#' @export +.DollarNames.mrgmod <- function(x, pattern){ + grep(pattern, names(param(x)), value=TRUE) +} + +#' Show names of current output variables +#' +#' @param x mrgmod object +#' @param unlist if `TRUE` then a character vector (rather than list) is +#' returned +#' +#' @return +#' When `unlist` is `FALSE` (default) : a named list, with `cmt` showing names +#' of output compartments and `capture` giving names of output variables in +#' capture. When `unlist` is `TRUE`, then a single, unnamed character vector +#' of outvar names is returned. +#' +#' @examples +#' +#' outvars(mrgsolve::house()) +#' +#' @md +#' @export +outvars <- function(x, unlist = FALSE) { + ans <- list(cmt = x@cmtL, capture = x@capL) + if(unlist) unlist(ans, use.names=FALSE) + ans +} diff --git a/R/class_mrgsims.R b/R/class_mrgsims.R index b710738d4..4f5b19601 100644 --- a/R/class_mrgsims.R +++ b/R/class_mrgsims.R @@ -69,4 +69,7 @@ setMethod("as.list", "mrgsims", function(x, ...) { structure(out, class = "mrgsims_list") }) - +#' @export +.DollarNames.mrgsims <- function(x, pattern){ + grep(pattern, names(x), value=TRUE) +} diff --git a/R/class_tgrid.R b/R/class_tgrid.R index 71caa94ae..0ee3dc01f 100644 --- a/R/class_tgrid.R +++ b/R/class_tgrid.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -134,7 +134,7 @@ as_deslist <- function(data, descol="ID") { ##' design <- c(day1, day1+72, day1+240) ##' ##' \dontrun{ -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' ##' out <- mod %>% ev(amt=1000, ii=24, addl=10) %>% mrgsim(tgrid=design) ##' diff --git a/R/compile.R b/R/compile.R index 4f9e714a8..4e87a1f38 100644 --- a/R/compile.R +++ b/R/compile.R @@ -22,7 +22,9 @@ generate_rdefs <- function(pars, table_fun="", config_fun="", model="",omats,smats, - set=list(), dbsyms = FALSE, ...) { + set=list(), + plugin = NULL, + dbsyms = FALSE, ...) { npar <- length(pars) ncmt <- length(cmt) @@ -69,7 +71,9 @@ generate_rdefs <- function(pars, Fdef <- Adef <- Ddef <- Rdef <- cmtndef <- NULL cmtn <- unique(intersect(cvec_cs(set$CMTN),cmt)) - + + if(!is.null(plugin[["N_CMT"]])) cmtn <- cmt + if(length(cmtn) > 0) { cmtnindex <- match(cmtn,cmt)-1 cmtndef <- paste0("#define ", paste0("N_", cmtn), " ", cmtnindex+1) diff --git a/R/data_set.R b/R/data_set.R index 5ef482467..f2f7297c6 100644 --- a/R/data_set.R +++ b/R/data_set.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -88,7 +88,7 @@ ##' ##' @examples ##' -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' ##' data <- expand.ev(ID=1:3, amt=c(10,20)) ##' diff --git a/R/datasets.R b/R/datasets.R index 285fa3370..d497c92c6 100644 --- a/R/datasets.R +++ b/R/datasets.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -36,7 +36,7 @@ ##' ##' @examples ##' -##' mod <- mrgsolve:::house() %>% update(end=240) %>% Req(CP) +##' mod <- mrgsolve::house() %>% update(end=240) %>% Req(CP) ##' ##' ## Full data set ##' data(exTheoph) diff --git a/R/events.R b/R/events.R index ae75d087a..bca003b72 100644 --- a/R/events.R +++ b/R/events.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -65,7 +65,7 @@ ##' \code{\link{as.ev}}, \code{\link{ev_methods}} ##' ##' @examples -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' ##' mod <- mod %>% ev(amt=1000, time=0, cmt=1) ##' diff --git a/R/funset.R b/R/funset.R index 6190d1a9d..cc87dfe6c 100644 --- a/R/funset.R +++ b/R/funset.R @@ -19,12 +19,14 @@ FUNSET_ERROR__ <- ' There was a problem accessing the model shared object. - Either the model object is corrupted or - the model was not properly compiled and/or loaded. -Check mrgsolve:::funset(mod) for more information. + Either the model object is corrupted or the model was + not properly compiled and/or loaded. If the model is + not loaded, use loadso(mod) to do so. This is usually + required for parallel simuilation on a worker node that + was not forked (e.g. when using future::multisession). + Also check mrgsolve:::funset(mod) for more information. ' - main_func <- function(x) x@funs["main"] ode_func <- function(x) x@funs["ode"] table_func <- function(x) x@funs["table"] diff --git a/R/generics.R b/R/generics.R index 48d536b0b..f35d7b1a4 100644 --- a/R/generics.R +++ b/R/generics.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -21,7 +21,7 @@ ##' @param ... passed along ##' ##' @examples -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' mod %>% cmtn("CENT") ##' @export setGeneric("cmtn", function(x,...) standardGeneric("cmtn")) @@ -86,7 +86,7 @@ unloadso <- function(x,...) UseMethod("unloadso") ##' ##' ## example("stime", package="mrgsolve") ##' -##' mod <- mrgsolve:::house(end=12, delta=2, add=c(11,13,15)) +##' mod <- mrgsolve::house(end=12, delta=2, add=c(11,13,15)) ##' ##' stime(mod) ##' @@ -108,7 +108,7 @@ setGeneric("revar", function(x,...) standardGeneric("revar")) ##' @param ... passed along ##' ##' @examples -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' mod %>% blocks ##' mod %>% blocks(PARAM,TABLE) ##' diff --git a/R/handle_spec_block.R b/R/handle_spec_block.R index 0235d4a62..d4fbb91c7 100644 --- a/R/handle_spec_block.R +++ b/R/handle_spec_block.R @@ -199,7 +199,8 @@ PARAM <- function(x,env,annotated=FALSE,covariates=FALSE,pos=1,as_object=FALSE,. } if(annotated) { - l <- parse_annot(x,block="PARAM",envir=env$ENV) + context <- glue("parse annotated parameter block ({pos})") + l <- parse_annot(x,block="PARAM",envir=env$ENV,context = context) env[["param"]][[pos]] <- l[["v"]] env[["annot"]][[pos]] <- l[["an"]] } else { @@ -227,7 +228,8 @@ FIXED <- function(x,env,annotated=FALSE,pos=1,...) { check_block_data(x,env$ENV,pos) if(annotated) { - l <- parse_annot(x,block="FIXED",envir=env$ENV) + context <- glue("parse annotated fixed block ({pos})") + l <- parse_annot(x,block="FIXED",envir=env$ENV,context=context) env[["fixed"]][[pos]] <- l[["v"]] env[["annot"]][[pos]] <- l[["an"]] } else { @@ -291,7 +293,8 @@ INIT <- function(x,env,annotated=FALSE,pos=1,as_object=FALSE,...) { } if(annotated) { - l <- parse_annot(x,block="INIT",envir=env$ENV) + context <- glue("parse annotated init block ({pos})") + l <- parse_annot(x,block="INIT",envir=env$ENV,context=context) env[["init"]][[pos]] <- l[["v"]] env[["annot"]][[pos]] <- l[["an"]] } else { @@ -316,7 +319,8 @@ CMT <- function(x,env,annotated=FALSE,pos=1, as_object = FALSE, ...) { return(NULL) } if(annotated) { - l <- parse_annot(x,novalue=TRUE,block="CMT",envir=env$ENV) + context <- glue("parse annotated compartment block ({pos})") + l <- parse_annot(x,novalue=TRUE,block="CMT",envir=env$ENV,context=context) env[["annot"]][[pos]] <- l[["an"]] x <- names(l[["v"]]) } else { @@ -372,7 +376,8 @@ handle_spec_block.specCAPTURE <- function(x,...) { CAPTURE <- function(x,env,annotated=FALSE,pos=1,...) { if(annotated) { - l <- parse_annot(x,novalue=TRUE,block="CAPTURE",envir=env$ENV) + context <- glue("parse annotated capture block ({pos})") + l <- parse_annot(x,novalue=TRUE,block="CAPTURE",envir=env$ENV,context=context) env[["annot"]][[pos]] <- l[["an"]] x <- names(l[["v"]]) } else { diff --git a/R/idata_set.R b/R/idata_set.R index 54a29a156..919a50868 100644 --- a/R/idata_set.R +++ b/R/idata_set.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -65,7 +65,7 @@ ##' input idata set contain \code{NA}. ##' ##' @examples -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' ##' data(exidata) ##' diff --git a/R/init.R b/R/init.R index 4ca59ef90..f586522e9 100644 --- a/R/init.R +++ b/R/init.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -42,7 +42,7 @@ ##' ##' @examples ##' ## example("init") -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' ##' init(mod) ##' init(mod, .pat="^C") ## may be useful for large models diff --git a/R/inven.R b/R/inven.R index d17881443..31f5ed78f 100644 --- a/R/inven.R +++ b/R/inven.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # diff --git a/R/knobs.R b/R/knobs.R index cf8c77102..a560b60c4 100644 --- a/R/knobs.R +++ b/R/knobs.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -41,7 +41,7 @@ moving <- function(x) x@moving #nocov ##' @examples ##' ## example("knobs") ##' -##' mod <- mrgsolve:::house(end=72) +##' mod <- mrgsolve::house(end=72) ##' ##' events <- ev(amt=1000, cmt=1, addl=3, ii=12) ##' diff --git a/R/matlist.R b/R/matlist.R index 97138c645..d58d4516c 100644 --- a/R/matlist.R +++ b/R/matlist.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -44,7 +44,7 @@ ##' omat(mat1, mat2, mat3) ##' omat(A=mat1, B=mat2, C=mat3) ##' -##' mod <- mrgsolve:::house() %>% omat(mat4) +##' mod <- mrgsolve::house() %>% omat(mat4) ##' ##' omat(mod) ##' omat(mod, make=TRUE) @@ -147,7 +147,7 @@ setMethod("omat", "mrgsims", function(.x,make=FALSE,...) { ##' smat(mat1, mat2, mat3) ##' smat(A=mat1, B=mat2, C=mat3) ##' -##' mod <- mrgsolve:::house() %>% smat(mat1) +##' mod <- mrgsolve::house() %>% smat(mat1) ##' ##' smat(mod) ##' smat(mod, make=TRUE) @@ -233,20 +233,35 @@ setMethod("zero.re", "mrgmod", function(.x,...,.drop=FALSE) { ##' @export zero_re <- function(...) zero.re(...) -##' @rdname matlist -##' @export +#' Deprecated: drop random effect matrices from model object +#' +#' +#' @param .x not used +#' @param ... not used +#' +#' @details +#' Users are no longer allowed to remove random effect matrices from the model +#' object. Use [zero_re] instead to convert the matrix to all zeros. +#' +#' +#' @seealso [zero_re] +#' @md +#' @export drop_re <- function(.x,...) { - .Deprecated(msg="drop.re and drop_re are deprecated. Use zero_re instead.") - what <- as.character(eval(substitute(alist(...)))) - if(length(what)==0) what <- c("omega", "sigma") - if(is.element("omega", what)) .x@omega <- new("omegalist") - if(is.element("sigma", what)) .x@sigma <- new("sigmalist") - return(.x) + lifecycle::deprecate_stop("0.10.1", "drop_re()", "zero_re()") + # .Deprecated(msg="drop.re and drop_re are deprecated. Use zero_re instead.") + # what <- as.character(eval(substitute(alist(...)))) + # if(length(what)==0) what <- c("omega", "sigma") + # if(is.element("omega", what)) .x@omega <- new("omegalist") + # if(is.element("sigma", what)) .x@sigma <- new("sigmalist") + # return(.x) } -##' @rdname matlist -##' @export -drop.re <- function(...) drop_re(...) +#' @rdname drop_re +#' @export +drop.re <- function(...) { + lifecycle::deprecate_stop("0.10.1", "drop.re()", "zero_re()") +} ##' @export ##' @rdname matlist diff --git a/R/model_include.R b/R/model_include.R index 4363225e4..356a1bb0e 100644 --- a/R/model_include.R +++ b/R/model_include.R @@ -39,7 +39,7 @@ get_depends <- function(what) { get_plugin <- function(what) { if(!exists(what,plugins)) { - stop("Plugin ", what, " could not be found.") + wstop("plugin ", what, " could not be found.") } plugins[[what]] } @@ -67,14 +67,14 @@ make_clink <- function(x,clink) { paste(paste0("-I\"",unique(link), "\""),collapse=" ") } -set_clink <- function(x,clink=NULL) { +set_clink <- function(x,clink=NULL,...) { if(is.null(x) & is.null(clink)) return(invisible(NULL)) Sys.setenv(CLINK_CPPFLAGS = make_clink(x,clink)) } -set_pkg_cxxflags <- function(x) { +set_pkg_cxxflags <- function(x,CXX = NULL,...) { if(is.null(x)) return(NULL) - cxx <- s_pick(x, "pkg_cxxflags") + cxx <- c(s_pick(x, "pkg_cxxflags"),CXX) if(is.null(cxx)) return(NULL) Sys.setenv(PKG_CXXFLAGS = paste0(cxx, collapse=" ")) } @@ -100,7 +100,7 @@ set_up_env <- function(x,...) { if(!is.null(x)) { set_clink(x,...) set_libs(x) - set_pkg_cxxflags(x) + set_pkg_cxxflags(x,...) } return(restore) } @@ -149,10 +149,10 @@ plugins[["CXX11"]] <- list( pkg_cxxflags = "-std=c++11", name="CXX11" ) -plugins[["TAD"]] <- list( - name = "TAD", - code = "#define __MRGSOLVE_USE_PLUGIN_TAD__" +plugins[["N_CMT"]] <- list( + all = TRUE, name = "N_CMT" ) + # nocov end # read_lines_from_base <- function(file) { diff --git a/R/modspec.R b/R/modspec.R index 640f9723d..63e1cfffe 100644 --- a/R/modspec.R +++ b/R/modspec.R @@ -416,12 +416,13 @@ scrape_opts <- function(x,envir=list(),def=list(),all=TRUE,marker="=", ## Get lines starting with >> opts <- grepl("^\\s*>>",x,perl=TRUE) + + has_at <- grepl("^\\s*@", x, perl=TRUE) - if(!narrow) { + if((!narrow) && (!any(has_at))) { opts <- opts | grepl(marker,x,fixed=TRUE) } - - has_at <- grepl("^\\s*@", x, perl=TRUE) + at <- parse_ats(x[has_at]) data <- x[!(opts | has_at)] @@ -430,7 +431,6 @@ scrape_opts <- function(x,envir=list(),def=list(),all=TRUE,marker="=", opts <- merge.list(def, tolist(opts,envir=envir), open=all,warn=FALSE,context="opts") - opts <- c(opts,at) if(allow_multiple) { diff --git a/R/mread.R b/R/mread.R index 4b9bcce4f..55da30c8a 100644 --- a/R/mread.R +++ b/R/mread.R @@ -205,7 +205,7 @@ mread <- function(model, project = getOption("mrgsolve.project", getwd()), # Each code block can contribute to / occupy one # slot for each of param/fixed/init/omega/sigma mread.env <- parse_env(spec,project=build$project,ENV) - + ## The main sections that need R processing: spec <- move_global(spec,mread.env) @@ -232,13 +232,13 @@ mread <- function(model, project = getOption("mrgsolve.project", getwd()), init <- as.list(do.call("c",unname(mread.env$init))) ode <- do.call("c", unname(mread.env$ode)) annot_list_maybe <- nonull.list(mread.env$annot) - + if (!length(annot_list_maybe)) { annot <- tibble() } else { annot <- dplyr::bind_rows(annot_list_maybe) } - + omega <- omat(do.call("c", nonull.list(mread.env$omega))) sigma <- smat(do.call("c", nonull.list(mread.env$sigma))) namespace <- do.call("c", mread.env$namespace) @@ -341,6 +341,9 @@ mread <- function(model, project = getOption("mrgsolve.project", getwd()), args <- list(...) x <- update(x, data=args, open=TRUE, strict = FALSE) + ## Modify SS compartments + x <- set_ss_cmt(x,SET[["ss_cmt"]]) + ## lock some of this down so we can check order later x@code <- readLines(build$modfile, warn=FALSE) x@shlib[["covariates"]] <- mread.env[["covariates"]] @@ -364,13 +367,18 @@ mread <- function(model, project = getOption("mrgsolve.project", getwd()), smats = smat(x), set = SET, check.bounds = check.bounds, + plugin = plugin, dbsyms = args[["dbsyms"]] ) - + ## IN soloc directory cwd <- getwd() setwd(build$soloc) - to_restore <- set_up_env(plugin,clink=c(project(x),SET$clink)) + to_restore <- set_up_env( + x=plugin, + clink=c(project(x),SET$clink), + CXX = ENV$PKG_CXXFLAGS + ) on.exit({ setwd(cwd) do_restore(to_restore) @@ -378,7 +386,7 @@ mread <- function(model, project = getOption("mrgsolve.project", getwd()), incl <- function(x) paste0('#include "', x, '"') header_file <- paste0(build$model, "-mread-header.h") - + dbs <- NULL if(isTRUE(args[["dbsyms"]])) { dbs <- debug_symbols(names(init(x))) diff --git a/R/mrgindata.R b/R/mrgindata.R index bea43a28f..421e1a03e 100644 --- a/R/mrgindata.R +++ b/R/mrgindata.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -103,7 +103,7 @@ convert_character_cmt <- function(data, mod) { ##' ##' @examples ##' -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' ##' data(exTheoph) ##' diff --git a/R/mrgsim_q.R b/R/mrgsim_q.R index 4748c2d0f..92e0995ad 100644 --- a/R/mrgsim_q.R +++ b/R/mrgsim_q.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -76,7 +76,7 @@ ##' ##' @examples ##' -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' ##' data <- expand.ev(amt = c(100,300,1000)) ##' diff --git a/R/mrgsims.R b/R/mrgsims.R index 85044ceed..0d8bf0d42 100644 --- a/R/mrgsims.R +++ b/R/mrgsims.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -56,7 +56,7 @@ ##' ##' ## example("mrgsims") ##' -##' mod <- mrgsolve:::house() %>% init(GUT=100) +##' mod <- mrgsolve::house() %>% init(GUT=100) ##' ##' out <- mrgsim(mod) ##' @@ -146,6 +146,14 @@ NULL ##' @param .keep_all passed to \code{dplyr::distinct} ##' @param funs passed to \code{dplyr::summarise_each} ##' @param ... passed to other methods +##' +##' @details +##' +##' For the \code{select_sims} function, the dots \code{...} must be either +##' compartment names or variables in \code{$CAPTURE}. An error will be +##' generated if no valid names are selected or the names for selection are +##' not found in the simulated output. +##' ##' @rdname mrgsims_dplyr ##' @export as.tbl.mrgsims <- function(x,...) { @@ -222,6 +230,24 @@ select.mrgsims <- function(.data,...) { dplyr::select(as_tibble.mrgsims(.data),...) } +#' @rdname mrgsims_dplyr +#' @export +select_sims <- function(.data, ...) { + all_names <- names(.data) + outputs <- c(.data@request,.data@outnames) + retain <- setdiff(all_names,outputs) + vars <- vars_select(all_names, !!!enquos(...)) + vars <- intersect(vars,outputs) + if(length(vars)==0) { + wstop("no output variables (compartments or captures) were selected.") + } + vars <- unique(c(retain,vars)) + .data@data <- dplyr::select(.data@data,vars) + .data@request <- intersect(.data@request,names(.data)) + .data@outnames <- intersect(.data@outnames,names(.data)) + return(.data) +} + ##' @rdname mrgsims_dplyr ##' @export slice.mrgsims <- function(.data,...) { @@ -308,7 +334,7 @@ setMethod("show", "mrgsims", function(object) { ##' ##' @examples ##' -##' mod <- mrgsolve:::house(end=48, delta=0.2) %>% init(GUT=1000) +##' mod <- mrgsolve::house(end=48, delta=0.2) %>% init(GUT=1000) ##' ##' out <- mrgsim(mod) ##' @@ -320,6 +346,10 @@ setMethod("show", "mrgsims", function(object) { ##' ##' plot(out, CP+RESP~time, col="black", scales="same", lty=2) ##' +##' \dontrun{ +##' plot(out, "CP RESP, GUT") +##' } +##' ##' @md ##' @export setMethod("plot", c("mrgsims","missing"), function(x,limit=16,...) { @@ -410,6 +440,17 @@ setMethod("plot", c("mrgsims","formula"), function(x,y, ans }) +#' @rdname plot_mrgsims +#' @aliases plot,mrgsims,formula-method +#' @export +setMethod("plot", c("mrgsims","character"), function(x,y,...) { + y <- gsub("\n+", " ", y) + y <- cvec_cs(y) + time <- timename(x@data) + lhs <- paste0(y,collapse="+") + fm <- as.formula(paste0(lhs,"~",time)) + plot(x,fm,...) +}) ##' Plot data as an mrgsims object ##' @@ -424,7 +465,7 @@ setMethod("plot", c("mrgsims","formula"), function(x,y, ##' ##' @examples ##' -##' mod <- mrgsolve:::house() %>% ev(amt = 100) +##' mod <- mrgsolve::house() %>% ev(amt = 100) ##' ##' out <- mrgsim(mod) ##' out_df <- dplyr::mutate(out, time <= 72) diff --git a/R/mrgsolve.R b/R/mrgsolve.R index f5971f706..994667706 100644 --- a/R/mrgsolve.R +++ b/R/mrgsolve.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -140,7 +140,7 @@ validate_idata <- function(idata) { ##' ##' e <- ev(amt = 1000) ##' -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' ##' out <- mod %>% ev(e) %>% mrgsim() ##' @@ -680,7 +680,7 @@ do_mrgsim <- function(x, #' #' @examples #' -#' mod <- mrgsolve:::house() +#' mod <- mrgsolve::house() #' #' dose <- ev(amt = 100) #' diff --git a/R/package.R b/R/package.R index 63b74f295..799cf104b 100644 --- a/R/package.R +++ b/R/package.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -54,7 +54,7 @@ #' #' ## example("mrgsolve") #' -#' mod <- mrgsolve:::house(delta=0.1) %>% param(CL=0.5) +#' mod <- mrgsolve::house(delta=0.1) %>% param(CL=0.5) #' #' events <- ev(amt=1000, cmt=1, addl=5, ii=24) #' diff --git a/R/param.R b/R/param.R index e757e96d3..e13395b73 100644 --- a/R/param.R +++ b/R/param.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -50,7 +50,7 @@ ##' @examples ##' ## example("param") ##' -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' ##' param(mod) ##' diff --git a/R/render.R b/R/render.R index df3fd2841..f09fe14a1 100644 --- a/R/render.R +++ b/R/render.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -66,7 +66,7 @@ document <- function(number_sections = TRUE, highlight = "pygments", ##' ##' @examples ##' \dontrun{ -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' mrgsolve:::render(mod) ##' mrgsolve:::render("irm2", modlib()) ##' } diff --git a/R/update.R b/R/update.R index 527dd0889..bb94b12d5 100644 --- a/R/update.R +++ b/R/update.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -26,66 +26,67 @@ other_val <- c("param", "init", "omega", "sigma", "outvars") all_updatable <- c(sval,other_val) -##' Update the model object +#' Update the model object +#' +#' After the model object is created, update various attributes. +#' +#' @param object a model object +#' @param ... named items to update +#' @param merge logical indicating to merge (rather than replace) +#' new and existing attributes +#' @param open logical; used only when merge is \code{TRUE} and +#' parameter list or initial conditions +#' list is being updated; if \code{FALSE}, no new items will be +#' added; if \code{TRUE}, the parameter list may expand. +#' @param data a list of items to update; this list is combined +#' with any items passed in via \code{...} +#' @param strict if \code{TRUE}, then an error will be generated if there is +#' attempt to update a non-existent item +#' +#' @return The updated model object is returned. +#' +#' @details +#' Slots that can be updated: +#' +#' \itemize{ +#' \item verbose +#' \item debug +#' \item preclean +#' \item mindt +#' \item digits +#' \item atol - absolute solver tolerance; see \code{\link{solversettings}} +#' \item rtol - relative solver tolerance; see \code{\link{solversettings}} +#' \item ixpr - see \code{IXPR} in \code{\link{solversettings}} +#' \item mxhnil - see \code{MXHNIL} in \code{\link{solversettings}} +#' \item hmin - see \code{HMIN} in \code{\link{solversettings}} +#' \item hmax - see \code{HMAX} in \code{\link{solversettings}} +#' \item maxsteps - see \code{MXSTEP} in \code{\link{solversettings}} +#' \item start, end, delta, add +#' \item tscale +#' \item request +#' \item param +#' \item init +#' \item omega +#' \item sigma +#' \item outvars +#' } +#' +#' @name update +#' +#' @aliases update,mrgmod-method +#' +#' @examples +#' \dontrun{ +#' mod <- mrgsolve::house() ##' -##' After the model object is created, update various attributes. -##' -##' @param object a model object -##' @param ... named items to update -##' @param merge logical indicating to merge (rather than replace) -##' new and existing attributes -##' @param open logical; used only when merge is \code{TRUE} and -##' parameter list or initial conditions -##' list is being updated; if \code{FALSE}, no new items will be -##' added; if \code{TRUE}, the parameter list may expand. -##' @param data a list of items to update; this list is combined -##' with any items passed in via \code{...} -##' @param strict if \code{TRUE}, then an error will be generated if there is -##' attempt to update a non-existent item -##' -##' @return The updated model object is returned. -##' -##' @details -##' Slots that can be updated: -##' -##' \itemize{ -##' \item verbose -##' \item debug -##' \item preclean -##' \item mindt -##' \item digits -##' \item atol - absolute solver tolerance; see \code{\link{solversettings}} -##' \item rtol - relative solver tolerance; see \code{\link{solversettings}} -##' \item ixpr - see \code{IXPR} in \code{\link{solversettings}} -##' \item mxhnil - see \code{MXHNIL} in \code{\link{solversettings}} -##' \item hmin - see \code{HMIN} in \code{\link{solversettings}} -##' \item hmax - see \code{HMAX} in \code{\link{solversettings}} -##' \item maxsteps - see \code{MXSTEP} in \code{\link{solversettings}} -##' \item start, end, delta, add -##' \item tscale -##' \item request -##' \item param -##' \item init -##' \item omega -##' \item sigma -##' \item outvars -##' } -##' -##' @name update -##' -##' @aliases update,mrgmod-method -##' -##' @examples -##' \dontrun{ -##' mod <- mrgsolve:::house() -##' -##' mod <- update(mod, end=120, delta=4, param=list(CL=19.1)) -##' } -##' -##' @seealso \code{\link{update}}, \code{\link{mrgmod-class}} -##' -##' @export -##' +#' mod <- update(mod, end=120, delta=4, param=list(CL=19.1)) +#' } +#' +#' @seealso \code{\link{update}}, \code{\link{mrgmod-class}}, +#' \code{\link{within}} +#' +#' @export +#' setMethod("update", "mrgmod", function(object, ..., merge=TRUE, open=FALSE, data=NULL, strict=TRUE) { @@ -283,22 +284,22 @@ update_matlist <- function(x,y,open=FALSE,context="update_matlist",...) { return(x) } -##' @rdname update -##' @export -##' @param y another object involved in update +#' @rdname update +#' @export +#' @param y another object involved in update setMethod("update", "omegalist", function(object,y,...) { update_matlist(object, omat(y),context="omat",...) }) -##' @rdname update -##' @export +#' @rdname update +#' @export setMethod("update", "sigmalist", function(object,y,...) { update_matlist(object, smat(y),context="smat",...) }) -##' @rdname update -##' @param .y data to update -##' @export +#' @rdname update +#' @param .y data to update +#' @export setMethod("update", "parameter_list", function(object,.y,...) { object <- as.param( merge.list( @@ -308,8 +309,77 @@ setMethod("update", "parameter_list", function(object,.y,...) { object }) -##' @export -##' @rdname update -setMethod("update", "ev", function(object,y,...) { - -}) + +#' Update parameters, initials, and settings within a model object +#' +#' The main use case for using [within] rather than [update] or [param] or +#' [init] is when you want to update to a new value that is calculated from +#' the existing value. See the example in details +#' +#' Other model object slots that can be updated: `start`, `end`, `delta`, +#' `add`, `rtol`, `atol`, `hmax`, `maxsteps`. These are include for convenience, +#' but we expect that most of the time these will get updated through the +#' update method. +#' +#' @param data an object with class mrgmod +#' @param expr expressions evaluated in an environment containing various model +#' object components, including parameters, initial conditions, and others +#' (see details) +#' @param ... not used +#' +#' @examples +#' mod <- mrgsolve::house() +#' +#' mod2 <- within(mod, {CL <- CL * 1.5}) +#' +#' mod$CL +#' mod2$CL +#' +#' @seealso [update] +#' @name within +#' @aliases within,mrgmod-method +#' @md +#' @export +within.mrgmod <- function(data,expr,...) { + p <- as.list(param(data)) + i <- as.list(init(data)) + up <- list( + start = data@start, end = data@end, delta = data@delta, + atol = data@atol, rtol = data@rtol, hmax = data@hmax, + maxsteps = data@maxsteps + ) + up <- up[which(!(names(up) %in% c(names(p),names(i))))] + parent <- parent.frame() + env <- list2env(c(p,i,up),parent = parent) + eval(substitute(expr),env) + if(length(up) > 0) { + data <- update(data,data = mget(names(up),env)) + } + if(length(p) > 0) { + data <- param(data,mget(names(p),env)) + } + if(length(i) > 0) { + data <- init(data,mget(names(i),env)) + } + data +} + +set_ss_cmt <- function(x,ss_cmt) { + if(!is.character(ss_cmt)) return(x) + ss_cmt <- cvec_cs(ss_cmt) + if(length(ss_cmt)==0) return(x) + ss_exclude <- grepl("^-", ss_cmt[1]) + ss_cmt[1] <- gsub("^-", "", ss_cmt[1]) + ss_cmt <- ss_cmt[nzchar(ss_cmt)] + if(length(ss_cmt)==0) return(x) + if(any(!is.element(ss_cmt, Cmt(x)))) { + diff <- setdiff(ss_cmt, Cmt(x)) + diff <- paste0(" - ", diff, "\n") + stop("invalid cmt names found in ss_cmt\n", diff, call.=FALSE) + } + if(ss_exclude) ss_cmt <- setdiff(Cmt(x),ss_cmt) + x@ss_cmt <- match(ss_cmt, Cmt(x)) - 1L + ss_cmt_check <- range(x@ss_cmt) + stopifnot(ss_cmt_check[1] >= 0 && ss_cmt_check[2] < neq(x)) + x +} diff --git a/R/utils.R b/R/utils.R index 080a9bcbc..5b79ee43a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -283,7 +283,7 @@ s_ <- function(...) as.character(match.call(expand.dots=TRUE))[-1] #nocov ##' list is returned. ##' ##' @examples -##' mod <- mrgsolve:::house() +##' mod <- mrgsolve::house() ##' mod %>% Req(CP,RESP) %>% carry_out(evid,WT,FLAG) %>% simargs ##' ##' @md diff --git a/R/workflows.R b/R/workflows.R index 83bdeb941..1d1d0e547 100644 --- a/R/workflows.R +++ b/R/workflows.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -33,7 +33,7 @@ ##' value. ##' ##' @examples -##' mod <- mrgsolve:::house() %>% zero_re() +##' mod <- mrgsolve::house() %>% zero_re() ##' ##' mod %>% ##' ev(amt = 100) %>% diff --git a/doxyfile b/doxyfile new file mode 100644 index 000000000..98b5c3c63 --- /dev/null +++ b/doxyfile @@ -0,0 +1,11 @@ +PROJECT_NAME = mrgsolve +DOXYFILE_ENCODING = UTF-8 +OUTPUT_DIRECTORY = Doxygen +INPUT = src/ inst/include inst/base +FILE_PATTERNS = *.c *.cpp *.h +FULL_PATH_NAMES = YES +TAB_SIZE = 8 +EXTRACT_ALL = YES +EXTRACT_PRIVATE = YES +WARN_IF_UNDOCUMENTED = YES +INPUT_ENCODING = UTF-8 diff --git a/inst/base/databox_cpp.h b/inst/base/databox_cpp.h index b430ef4e3..f82935cac 100644 --- a/inst/base/databox_cpp.h +++ b/inst/base/databox_cpp.h @@ -1,4 +1,4 @@ -// Copyright (C) 2013 - 2019 Metrum Research Group, LLC +// Copyright (C) 2013 - 2020 Metrum Research Group // // This file is part of mrgsolve. // @@ -26,6 +26,13 @@ double databox::mtime(double time) { return time; } +/** + * Calculates time after dose. + * + * @return the calculated time after dose; if no dose has been given for the + * current individual, then -1 is returned. + * + */ double databox::tad() { static double told = -1.; if(newind <= 1) told = -1.0; diff --git a/inst/base/modelheader.h b/inst/base/modelheader.h index 9f88d5bb8..1d8d704c2 100644 --- a/inst/base/modelheader.h +++ b/inst/base/modelheader.h @@ -82,6 +82,8 @@ typedef double capture; #define AMT self.amt // Data set cmt #define CMT self.cmt +// Bool flag indicating that the system is advancing to steady-state +#define SS_ADVANCE _ss_flag_ // These are the fundamental macros for // bioavailability, infusion rate, infusion duration diff --git a/inst/base/mrgsolv.h b/inst/base/mrgsolv.h index cec43561d..a60697cbf 100644 --- a/inst/base/mrgsolv.h +++ b/inst/base/mrgsolv.h @@ -76,6 +76,14 @@ template void report(type1 a, type2 b) { namespace mrg = mrgsolve; //! member functions mevent and tad come in via housemodel; see inst/base/databox.cpp + +/** + * Model data passed to the model. + * + * This data is passed to PREAMBLE, MAIN, and TABLE but not ODE. + * + * + */ class databox { public: std::vector ETA; ///< vector of ETA values @@ -93,13 +101,13 @@ class databox { int rown; ///< current output row number bool CFONSTOP; ///< carry forward on stop indicator void* envir; ///< model environment - void stop() {SYSTEMOFF=9;} - void stop_id() {SYSTEMOFF=1;} - void stop_id_cf(){SYSTEMOFF=2;} - std::vector mevector; - void mevent(double time, int evid); - double mtime(double time); - double tad(); + void stop() {SYSTEMOFF=9;}///< stops the problem when the next record is started + void stop_id() {SYSTEMOFF=1;}///< stops solving for the current id, filling with NA + void stop_id_cf(){SYSTEMOFF=2;}///< stops solving for the current id, filling last value + std::vector mevector;///< a collection of model events to pass back + void mevent(double time, int evid);///< constructor for evdata objects + double mtime(double time);///< creates evdata object for simple model event time + double tad();///< calculates time after dose }; //! vector of doubles @@ -114,8 +122,8 @@ typedef std::vector dvec; #define MRGSOLVE_TABLE_SIGNATURE_N 9 //! signature for $ODE -#define MRGSOLVE_ODE_SIGNATURE const double* _ODETIME_, const double* _A_, double* _DADT_, const dvec& _A_0_, const dvec& _THETA_ -#define MRGSOLVE_ODE_SIGNATURE_N 5 +#define MRGSOLVE_ODE_SIGNATURE const double* _ODETIME_, const double* _A_, double* _DADT_, const dvec& _A_0_, const dvec& _THETA_, const bool _ss_flag_ +#define MRGSOLVE_ODE_SIGNATURE_N 6 //! signature for $PREAMBLE #define MRGSOLVE_CONFIG_SIGNATURE databox& self, const dvec& _THETA_, const double neq, const double npar diff --git a/inst/include/odeproblem.h b/inst/include/odeproblem.h index 319738aae..d2003a332 100644 --- a/inst/include/odeproblem.h +++ b/inst/include/odeproblem.h @@ -85,6 +85,12 @@ template void tofunptr(T b, type2 a) { void dosimeta(void*); void dosimeps(void*); + +/** + * + * + * + */ class odeproblem { public: @@ -102,6 +108,7 @@ class odeproblem { void init_call(const double& time); void init_call_record(const double& time); + void init_derivs(double time); void y_init(int pos, double value); void y_init(Rcpp::NumericVector init); @@ -168,14 +175,15 @@ class odeproblem { void neta(const int n); void neps(const int n); - void nid(int n) {d.nid = n;} - void nrow(int n) {d.nrow = n;} - void idn(int n) {d.idn = n;} - void rown(int n) {d.rown=n;} + void nid(int n) {d.nid = n;}///< sets the number of IDs + void nrow(int n) {d.nrow = n;}///< sets the number of data set rows + void idn(int n) {d.idn = n;}///< sets the current ID number + void rown(int n) {d.rown=n;}///< sets the currenw data set row number dvec& get_capture() {return Capture;} double capture(int i) {return Capture[i];} + /// copies items passed in through parin into the odeproblem object void copy_parin(const Rcpp::List& parin); void copy_funs(const Rcpp::List& funs); @@ -187,21 +195,28 @@ class odeproblem { int istate(){return Istate;} void istate(int value){Istate = value;} void lsoda_init(){Istate=1;} + /// returns the number of parameters int npar() {return Npar;} + /// returns the number of state variables int neq() {return Neq;} + /// sets the absolute and relative tolerances void tol(double atol, double rtol); - std::vector Y; - std::vector Ydot; - std::vector Yout; - std::vector Param; + + + std::vector Y; ///< compartment amounts + std::vector Ydot; ///< dxdt values + std::vector Yout; ///< used to hold Y values during solving + std::vector Param; ///< parameter vector std::vector Capture; ///< captured data items - double Atol; - double Rtol; - int Npar; - int Neq; + double Atol; ///< absolute tolerance + double Rtol; ///< relative tolerance + int Npar; ///< number of parameters + int Neq; ///< number of equations int Istate; ///< istate value - bool ss_fixed; - int ss_n; + bool ss_fixed; ///< If true, then no warning is issued if SS not reached in ss_n doses + int ss_n; ///< Max number of doses during SS advance before warning is issued + bool ss_flag; ///< flag indicating when the system is advancing to SS + std::vector Ss_cmt; ///< vector of compartments to consider for SS std::vector R0; ///< acutal current infusion rate std::vector infusion_count; ///< number of active infusions @@ -219,32 +234,23 @@ class odeproblem { std::vector a; ///< used for advan 1/2/3/4 calculations std::vector alpha; ///< used for advan 1/2/3/4 calculation - mrgsolve::resim simeta; ///< functor for resimulating etas - mrgsolve::resim simeps; ///< functor for resimulating epsilons + mrgsolve::resim simeta;///< functor for resimulating etas + mrgsolve::resim simeps;///< functor for resimulating epsilons - arma::mat Omega; ///< variance/covariance matrix for between-subject variability - arma::mat Sigma; ///< variance/covariance matrix for within-subject variability + arma::mat Omega;///< variance/covariance matrix for between-subject variability + arma::mat Sigma;///< variance/covariance matrix for within-subject variability std::vector pred; ///< brings clearances, volumes, and & for advan 1/2/3/4 - deriv_func Derivs; ///< $ODE function init_func Inits; ///< $MAIN function table_func Table; ///< $TABLE function config_func Config; ///< $PREAMBLE function - bool Do_Init_Calc; - - + bool Do_Init_Calc; ///< Flag regulating whether or not initials are taken from $MAIN }; -/** - * Calculate PK model polyexponentials. - * - * - * - */ double PolyExp(const double& x, const double& dose, const double& rate, diff --git a/inst/maintenance/build_housemodel.R b/inst/maintenance/build_housemodel.R index 6fadef997..4eba81a91 100644 --- a/inst/maintenance/build_housemodel.R +++ b/inst/maintenance/build_housemodel.R @@ -2,6 +2,7 @@ .libPaths("~/Rlibs") suppressPackageStartupMessages(library(dplyr)) suppressPackageStartupMessages(library(methods)) +suppressPackageStartupMessages(library(glue)) fun <- function() { setClass("mrgsims") source("R/utils.R") diff --git a/inst/maintenance/tests.R b/inst/maintenance/tests.R index bf0643e02..cd296b9c7 100644 --- a/inst/maintenance/tests.R +++ b/inst/maintenance/tests.R @@ -3,12 +3,16 @@ library(mrgsolve) library(testthat) library(dplyr) - +message("tests/testthat") a <- test_dir("tests/testthat") a$result <- NULL +message("\ninst/maintenance/unit") b <- test_dir("inst/maintenance/unit/") b$result <- NULL -results <- dplyr::bind_rows(as_tibble(a),as_tibble(b)) +message("\ninst/validation") +c <- test_dir("inst/validation/") +c$result <- NULL +results <- dplyr::bind_rows(as_tibble(a),as_tibble(b),as_tibble(c)) results$user <- NULL results$system <- NULL results$real <- NULL diff --git a/inst/maintenance/unit/test-pk.R b/inst/maintenance/unit/test-pk.R index 5fcfcc90b..8a267cdfd 100644 --- a/inst/maintenance/unit/test-pk.R +++ b/inst/maintenance/unit/test-pk.R @@ -1,6 +1,29 @@ +# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# +# This file is part of mrgsolve. +# +# mrgsolve is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# mrgsolve is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with mrgsolve. If not, see . + +library(testthat) +library(mrgsolve) +library(dplyr) +Sys.setenv(R_TESTS="") +options("mrgsolve_mread_quiet"=TRUE) skip_if_not_installed("pmxTools") skip_if(!require("dplyr")) +select <- dplyr::select library(pmxTools) diff --git a/inst/maintenance/unit/test-solver.R b/inst/maintenance/unit/test-solver.R new file mode 100644 index 000000000..a4571425d --- /dev/null +++ b/inst/maintenance/unit/test-solver.R @@ -0,0 +1,45 @@ +# Copyright (C) 2013 - 2020 Metrum Research Group +# +# This file is part of mrgsolve. +# +# mrgsolve is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# mrgsolve is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with mrgsolve. If not, see . + +library(testthat) +library(mrgsolve) +library(dplyr) +Sys.setenv(R_TESTS="") +options("mrgsolve_mread_quiet"=TRUE) + +context("test-solver") + +test_that("ode variables are initialized issue-613", { + code <- ' +[cmt] CENT + +[ ode ] +double number = 2; +double CP = CENT/10; +dxdt_CENT = -0.1*CENT; + +[ capture ] CP number +' + mod <- mcode("issue-613", code) + dose <- ev(amt = 100) %>% ev_rep(ID = 1:4) + out1 <- mrgsim(mod,dose) + out2 <- mrgsim(mod,dose) + expect_identical(out1,out2) + expect_true(all(out1$number==2)) +}) + + diff --git a/inst/validation/1.xml b/inst/validation/1.xml deleted file mode 100644 index b9326bf60..000000000 --- a/inst/validation/1.xml +++ /dev/null @@ -1,341 +0,0 @@ - - - -2019-09-08T20:52:51.322 - - - - - - -PHENOBARB SIMPLE MODEL - - - -1 -fo -First Order - -833.769487675409 -742.051045069463 - -0 -89 -5.40699773671882 - - -37 - -0.87 - - - -0.38 -MINIMUM VALUE OF OBJECTIVE FUNCTION -742.051045069463 - -5.553631710091184E-003 -1.33638482649590 - - - -0.247073944753326 - - -0.000000000000000E+000 -0.141580998571503 - - - - -1.641534299666640E-002 - - - - -0.497065332479872 - - -0.000000000000000E+000 -0.376272505734212 - - - - -0.128122375082053 - - - -3.947633331008921E-004 -7.990174178784634E-002 - - - -0.155529783121908 - - -10000000000.0000 -3.489412984460865E-002 - - - - -3.394652414744397E-003 - - - - -0.156448029020618 - - -10000000000.0000 -4.636816311694166E-002 - - - - -1.324769546525483E-002 - - - - -1.558380891609259E-007 - - -4.575355876075616E-006 -6.384288340731670E-003 - - --2.724103850799584E-005 --1.931795360941983E-003 -2.418951343794784E-002 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - -3.560729383545792E-006 -1.281762888798458E-003 --9.922804087693427E-004 -0.000000000000000E+000 -1.217600297612408E-003 - - -7.249266133623901E-008 -2.127440894937393E-005 -7.080862604221358E-005 -0.000000000000000E+000 --5.337654247708404E-007 -1.152366501692996E-005 - - - - -3.947633331008921E-004 - - -0.145054706870370 -7.990174178784634E-002 - - --0.443683508541541 --0.155450207379772 -0.155529783121908 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - -0.258493596134156 -0.459726008038150 --0.182838848589507 -0.000000000000000E+000 -3.489412984460865E-002 - - -5.409559773965178E-002 -7.843428537424467E-002 -0.134114979788673 -0.000000000000000E+000 --4.506120000731391E-003 -3.394652414744397E-003 - - - - -8464900.27443226 - - -711.230725243173 -202.152618983615 - - -9175.30668956622 -9.75750892207979 -53.9158704320418 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - --18074.9260983115 --207.129347505760 -6.65651358934435 -0.000000000000000E+000 -1097.83635211256 - - --111779.784561933 --447.228444378663 --406.718116077827 -0.000000000000000E+000 -506.045814185946 -90829.3493513707 - - - -0.468638086332230 -0.581178484369865 -0.975597199229516 -1.14948802362200 -1.82509820644639 - - - - -2019-09-08T20:52:52.766 -9.929 - diff --git a/inst/validation/211.xml b/inst/validation/211.xml deleted file mode 100644 index 29449c307..000000000 --- a/inst/validation/211.xml +++ /dev/null @@ -1,1011 +0,0 @@ - - - -2019-09-08T17:32:57.601 - - - - - - -1-CMT linear and nonlinear clearance - - - -1 -focei -First Order Conditional Estimation with Interaction - -4721.33531378806 -4636.51496297596 -4531.93686466097 -4502.24675847000 -4482.79436203196 -4482.65180071683 -4482.65176164458 - -0 -756 -4.90658572885700 - - -37 -49 - - - --1.523039370591053E-002 -1.144363992168681E-003 --7.922895646760447E-003 - - - - -1.834022708755024E-002 -2.391371580252643E-002 -1.976791039042620E-002 - - - - -116 -116 -116 - - - - -0.406291930069114 -0.961832563249751 -0.688570552104116 - - - - -58.9458926898155 -4.10342756001022 -15.6891499990930 - - - - -59.2029054899457 -4.39729391839505 -15.9670726237575 - - - - -11.8754324792084 - - -51.56 - - - -47.59 -MINIMUM VALUE OF OBJECTIVE FUNCTION -4482.65176164458 - --1.16527087112513 --1.44276309680737 -2.03416782757298 --0.103580041464349 -1.39852101144186 -0.157258031654724 -0.664809280790266 --1.60636704691752 --0.126927416134773 -6.043257427297889E-002 -8.115230127496528E-002 - - - -0.233514756050203 - - -0.000000000000000E+000 -7.276224593314493E-002 - - -0.000000000000000E+000 -0.000000000000000E+000 -6.432395359724277E-002 - - - - -1.00000000000000 - - - - -0.483233645403756 - - -0.000000000000000E+000 -0.269744779250952 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.253621674147228 - - - - -1.00000000000000 - - - -0.119425378803933 -6.301702555739129E-002 -3.015303960576275E-002 -0.370040527700468 -0.492567478274299 -4.467155787753298E-003 -0.137394952910418 -0.253211980710160 -5.884787779978128E-002 -6.207449294956353E-002 -2.222771739683198E-002 - - - -0.100830878911703 - - -10000000000.0000 -1.070151358990619E-002 - - -10000000000.0000 -10000000000.0000 -1.143189820599340E-002 - - - - -10000000000.0000 - - - - -0.104329323786484 - - -10000000000.0000 -1.983636832494585E-002 - - -10000000000.0000 -10000000000.0000 -2.253730530805729E-002 - - - - -10000000000.0000 - - - - -1.426242110246293E-002 - - --1.451543753065686E-003 -3.971145510100907E-003 - - -2.971779499124933E-004 --1.884474092276998E-004 -9.092057974666972E-004 - - -6.922102446937641E-003 --9.324526079605324E-003 -2.250789893237209E-003 -0.136929992140841 - - -3.701347281319897E-003 --1.018403915772496E-002 -8.974035273125577E-004 -0.167108697901658 -0.242622720653502 - - -1.030949968416338E-005 -5.548020187908031E-006 -4.518759044380177E-006 --2.789440058254731E-005 -1.644628273196523E-005 -1.995548083205779E-005 - - --1.550950572785388E-004 -3.087193762096600E-004 -2.893383016639354E-005 -2.228932755584935E-003 -2.911337819529164E-003 --2.867666696630401E-007 -1.887737308525592E-002 - - -4.245806690661397E-004 -3.448393326534394E-003 --2.960354506673904E-004 --8.689861343463544E-003 --9.804066813801336E-003 --9.917927781303684E-007 --1.436988860450575E-002 -6.411630717516233E-002 - - -1.052954047864061E-004 --7.221661777429545E-004 --1.444251433122314E-005 --5.598302517516412E-004 --6.293109936129060E-004 -2.519128794331338E-006 --3.722509244791894E-004 -1.491774502285945E-003 -3.463072721537990E-003 - - --7.745353401435454E-005 --2.817060921358310E-003 --5.601922411766031E-006 --1.243988670616870E-003 --1.892218797251619E-003 -9.473113439197741E-007 --8.852657604455940E-004 --4.877473019443818E-004 --1.962378238556783E-004 -3.853242674945412E-003 - - --4.106644900995343E-005 -2.095398661361380E-004 -5.043853697937604E-006 -5.154002207691319E-004 -6.506051981656458E-004 -2.206085979912230E-010 --9.294056196069436E-006 -1.730824629097314E-003 -1.856009631262275E-004 --2.236114872366846E-004 -4.940714206734273E-004 - - -2.928457004513369E-003 --4.199461854758049E-004 -6.157752046253106E-005 -4.139867724827807E-003 -3.992318009634456E-003 --2.843883890730566E-005 -2.024717598338923E-004 -7.320675749479592E-005 --1.093848342019224E-004 --9.041098847088256E-005 --1.313672984578940E-005 -1.016686614210643E-002 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - --8.045218262220342E-005 --3.825650055119786E-005 -1.910860970839919E-005 -7.935581737719997E-004 -9.740923330606789E-004 --1.420585570489892E-006 -1.360388641509442E-006 --6.478579067816416E-005 --3.591477622507173E-006 --1.357036476498154E-005 -4.292259126186553E-006 --1.632911762195375E-005 -0.000000000000000E+000 -0.000000000000000E+000 -1.145223931149470E-004 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - --2.100934893252577E-005 -4.350613301614263E-006 --6.779251144020520E-006 -9.672035689869584E-005 -2.808106018244946E-004 --3.399518347734967E-006 --9.885737563232851E-006 -2.290579274455528E-005 --7.495682305126474E-006 --4.461627102701869E-006 --5.452347395566697E-007 --2.411607408289710E-005 -0.000000000000000E+000 -0.000000000000000E+000 --1.202359476443630E-007 -0.000000000000000E+000 -1.306882965921952E-004 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - - - -0.119425378803933 - - --0.192874850842345 -6.301702555739129E-002 - - -8.252563158310977E-002 --9.917476330688411E-002 -3.015303960576275E-002 - - -0.156636187326111 --0.399870693601763 -0.201722604394703 -0.370040527700468 - - -6.292126905326739E-002 --0.328092593059926 -6.042142169899391E-002 -0.916819896066981 -0.492567478274299 - - -1.932457110449653E-002 -1.970829407866346E-002 -3.354725480950219E-002 --1.687472264415214E-002 -7.474306783261456E-003 -4.467155787753298E-003 - - --9.452148812558934E-003 -3.565621239908984E-002 -6.983997097794298E-003 -4.384064099110416E-002 -4.301858174933908E-002 --4.672257768680786E-004 -0.137394952910418 - - -1.404039542415786E-002 -0.216109891428588 --3.877290784685986E-002 --9.274260806920979E-002 --7.860610508669148E-002 --8.768101989027207E-004 --0.413045953139512 -0.253211980710160 - - -1.498242061566251E-002 --0.194736983542783 --8.139184688394622E-003 --2.570847204265521E-002 --2.171044766982765E-002 -9.582712705397404E-003 --4.603988176975228E-002 -0.100112457811030 -5.884787779978128E-002 - - --1.044795828869393E-002 --0.720153636386201 --2.992904164315662E-003 --5.415691943648866E-002 --6.188600349340019E-002 -3.416240672039528E-003 --0.103798172426713 --3.103111955259083E-002 --5.372033753071464E-002 -6.207449294956353E-002 - - --1.547019034502742E-002 -0.149593903654344 -7.525520034291202E-003 -6.266145025467362E-002 -5.942332216443801E-002 -2.221756552818272E-006 --3.043264135976269E-003 -0.307520413156663 -0.141890903229136 --0.162063816792594 -2.222771739683198E-002 - - -0.243191656988188 --6.609097938103753E-002 -2.025338163689136E-002 -0.110954167835965 -8.038330174586675E-002 --6.313747506675808E-002 -1.461504393571206E-002 -2.867301540607972E-003 --1.843455906994399E-002 --1.444489814595363E-002 --5.861366117349909E-003 -0.100830878911703 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - --6.295003790214555E-002 --5.672860884082386E-002 -5.921787032132363E-002 -0.200393795211669 -0.184794560549700 --2.971605088598282E-002 -9.252242568325692E-004 --2.390838857699922E-002 --5.702918323902764E-003 --2.042834263064555E-002 -1.804454180893027E-002 --1.513296254628485E-002 -0.000000000000000E+000 -0.000000000000000E+000 -1.070151358990619E-002 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - --1.538854709250989E-002 -6.039127995473628E-003 --1.966673546817186E-002 -2.286389674332035E-002 -4.986885736239025E-002 --6.656837299766416E-002 --6.293901600318781E-003 -7.913028459862198E-003 --1.114197082290420E-002 --6.287264631830704E-003 --2.145706435956795E-003 --2.092159100408898E-002 -0.000000000000000E+000 -0.000000000000000E+000 --9.828127334732580E-004 -0.000000000000000E+000 -1.143189820599340E-002 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - - - -86.2654524192685 - - -94.8692639237764 -1456.17664847953 - - -0.682859042637229 --36.4383750408471 -1282.78838843900 - - --7.23232261354949 -131.218938430853 --100.322594914384 -69.2209656573859 - - -8.08328615822438 --22.8209688717148 -62.9827419305286 --40.6338849586756 -30.6919196423510 - - --118.862523381125 --355.137120733767 --469.592636153551 -107.825781633030 --97.5947157437963 -51155.0762431617 - - --1.60343203950527 --27.8648156402914 -2.68990479418962 --1.74419232792924 -2.424749007169791E-003 -7.31906067759336 -66.6074575558209 - - --5.85971574613893 --68.7708121519482 -4.42235710341567 --4.14595244549871 -0.566288104300424 -20.2225162565362 -17.5801042840108 -24.8247168122148 - - -23.0632319702097 -413.873505810214 --9.78333895669547 -39.5151017567276 --7.09111021063639 --125.644202135229 --4.25778352687846 --22.6966134395695 -414.487918693543 - - -73.0390438100495 -1095.69205691524 --25.4837863537672 -97.1137695354102 --14.4219480617492 --282.416227397944 --6.45005127425130 --49.3984527667788 -321.770948149067 -1095.41931333696 - - -7.52187325831128 --134.850147780493 -1.57960099756977 --29.7865832947338 -5.75917287422506 -10.9241783298941 --48.3146018324911 --68.3332118341335 --135.783473543642 -7.40638517293305 -2398.40878791058 - - --20.4010043665986 -2.51905588594694 -4.78663168748883 --2.52893145432628 -0.294507215949002 -160.144756390265 --1.56864462982061 --0.954067898548356 -4.24939109724617 -3.34542037602955 -5.35421110401039 -105.873810748920 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - -74.9534430630114 --50.7536365968629 --72.3455480880327 --65.9890035078878 -5.02266426988727 -591.606760840210 -11.1193234548271 -6.02702531018167 --14.9210167826570 --19.9685845427661 --13.0393224268844 -17.6435499205932 -0.000000000000000E+000 -0.000000000000000E+000 -9205.08703374511 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - --3.30500181886319 --21.4852512420973 --6.61339466442970 -33.6755674069744 --34.0028993048614 -1439.22699790456 -3.29735953992673 --2.51063927095949 -10.7642818740080 --9.63364121571111 -27.5035671345625 -22.2714502322846 -0.000000000000000E+000 -0.000000000000000E+000 -73.3380424849816 -0.000000000000000E+000 -7742.48263662005 - - -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 -0.000000000000000E+000 - - - -5.640683682923087E-002 -0.111083073639208 -0.480445840735043 -0.728523599881935 -0.819717812550184 -0.865762387168935 -0.958503601398269 -0.969164153588934 -1.06020866565192 -1.10139559905893 -1.24105659862907 -1.51585815137909 -1.69833640578301 -2.39353727370624 - - - - -2019-09-08T17:34:39.908 -769.144 - diff --git a/inst/validation/run_test.R b/inst/validation/run_test.R new file mode 100644 index 000000000..c8be919a5 --- /dev/null +++ b/inst/validation/run_test.R @@ -0,0 +1,25 @@ +library(testthat) +library(dplyr) +library(mrgsolve) + + +run_test <- function(dir,d) { + + cwd <- getwd() + on.exit(setwd(cwd)) + setwd("../../") + x <- test_dir(dir) %>% as_tibble + x$result <- NULL + x$location <- dir + x$date <- d + x +} + +d <- Sys.time() +x <- run_test("inst/validation",d) +y <- run_test("tests/testthat",d) +z <- run_test("inst/maintenance/unit/",d) + +df <- bind_rows(x,y,z) + +readr::write_csv(path="all_tests.csv", df) diff --git a/inst/validation/test-validation.R b/inst/validation/test-validation.R index a102d9c5a..76a6ed324 100644 --- a/inst/validation/test-validation.R +++ b/inst/validation/test-validation.R @@ -5,40 +5,99 @@ stopifnot(require(PKPDmisc)) Sys.setenv(R_TESTS="") options("mrgsolve_mread_quiet"=TRUE, mgsolve.soloc = "build") -context("new ODE solver") - -test_that("non-stiff problem", { - mod <- modlib("pk2cmt", end = 240, delta=0.001) - d <- 331.234 - dose <- ev(amt = d) - expect_silent(out <- mrgsim_e(mod,dose,ixpr=1)) - auc <- summarise(out, auc= auc_partial(time,CP)) %>% pull(auc) %>% unname - expect_equal(round(auc),round(d/mod$CL)) +test_that("equal sign in annotation issue-576", { + code <- ' +# Compartments +```{cmt} +@annotated +FOO : bar +BAR : baz = zot +``` +' + out <- tempfile(fileext=".Rmd") + writeLines(code, con = out) + mod <- mread(out,compile=FALSE) + expect_is(mod, "mrgmod") }) -test_that("stiff problem", { - mod <- modlib("pbpk", end = 48, delta = 0.001, rtol = 1e-12) - p <- list(Kpli = 0.4573, fup = 0.352) - dose <- 89.123 - e <- ev(amt = dose) - cl <- mod$HLM_CLint - MPPGL <- 45.0 - Vli <- mod$BW * mod$FVli - fumic <- 1 - clmet <- (cl/fumic)*MPPGL*Vli*60/1000 - mod <- param(mod,p) - msg <- capture.output( - out <- mrgsim_e(mod,e,ixpr=1), - type = "message" - ) - expect_true(grepl("a switch to the stiff method has occurred", msg)) - auc <- summarise(out, auc = auc_partial(time,Cp)) %>% pull(auc) %>% unname - expect_equal(round(auc), round(dose/(clmet*p$Kpli*p$fup))) + + +code <- ' +$PARAM CL = 1, V =20, KA = 1.488,LAG = 1, advance_auc = 1 +$CMT DEPOT CENT AUC + +$PREAMBLE +double SS_FL = 0; + +$MAIN +ALAG_DEPOT = LAG; + +$ODE +dxdt_DEPOT = -KA*DEPOT; +dxdt_CENT = KA*DEPOT - (CL/V)*CENT; +dxdt_AUC = CENT/V; +if(advance_auc==0) dxdt_AUC = 0; +if(SS_ADVANCE) ++SS_FL; + +$CAPTURE SS_FL +' + +test_that("ss bolus with lag and AUC issue-596", { + first <- ev(amt = 100, ii = 24, ss=1, cmt =1) + mod <- mcode_cache("issue_596",code) %>% param(LAG = 13) + out <- expect_warning(mrgsim_df(mod,first)) + expect_true(all(out[["CENT"]] >=0)) +}) + +test_that("control ss advance issue-598", { + first <- ev(amt = 100, ii = 24, ss=1, cmt =1) + mod <- mcode_cache("issue_596",code) + out <- expect_warning(mrgsim(mod,first)) + auci <- out$AUC[2] + out <- expect_silent(mrgsim(mod,first, param = list(advance_auc = 0))) + expect_true(all(out$AUC==0)) + mod <- mrgsolve:::set_ss_cmt(mod, "CENT") + expect_identical(mod@ss_cmt, 1L) + out <- expect_silent(mrgsim(mod,first)) + expect_true(out$AUC[2] < auci/10) + expect_true(out$SS_FL[2] > 0) }) -test_that("nm xml with no namespace issue-510", { - nmx <- mrgsolve:::nmxml - expect_is(x1 <- nmx(file = "1.xml") ,"NMXMLDATA") - expect_is(x2 <- nmx(file = "211.xml", xpath = ".//estimation"),"NMXMLDATA") - expect_identical(names(x1),names(x2)) +test_that("PKG_CXXFLAGS is set issue-603", { + code <- '$ENV PKG_CXXFLAGS = "-Wdiv-by-zero"' + expect_output( + mcode("cxxflags", code, ignore.stdout = FALSE,preclean=TRUE), + regexp = "Wdiv-by-zero" + ) }) + +test_that("Add N_CMT as plugin issue-606", { + code <- '$CMT A B\n$PLUGIN N_CMT\n$CAPTURE N_A' + mod <- mcode("N_CMT_TEST", code) + expect_is(mod, "mrgmod") + out <- mrgsim(mod, end = -1) + expect_true(all(out$N_A==1)) +}) + +test_that("call blocks on model from Rmd issue-608", { + mod <- modlib("popex.Rmd",compile=FALSE) + expect_output( + blocks(mod), + regexp = "popex\\.Rmd" + ) +}) + + +test_that("update model object with within issue-616", { + mod <- mrgsolve:::house() + mod2 <- within(mod, { + CL = CL*1.5 + CENT = 101 + end = 72 + }) + expect_identical(mod2$CL,1.5*mod$CL) + expect_identical(init(mod2)[["CENT"]],101) + expect_identical(mod2@end,72) +}) + + diff --git a/man/BLOCK_PARSE.Rd b/man/BLOCK_PARSE.Rd index 60850de26..08850fca9 100644 --- a/man/BLOCK_PARSE.Rd +++ b/man/BLOCK_PARSE.Rd @@ -10,13 +10,19 @@ \alias{CAPTURE} \title{Functions to parse code blocks} \usage{ -PARAM(x, env, annotated = FALSE, covariates = FALSE, pos = 1, - as_object = FALSE, ...) +PARAM( + x, + env, + annotated = FALSE, + covariates = FALSE, + pos = 1, + as_object = FALSE, + ... +) FIXED(x, env, annotated = FALSE, pos = 1, ...) -THETA(x, env, annotated = FALSE, pos = 1, name = "THETA", - fill = NULL, ...) +THETA(x, env, annotated = FALSE, pos = 1, name = "THETA", fill = NULL, ...) INIT(x, env, annotated = FALSE, pos = 1, as_object = FALSE, ...) diff --git a/man/PKMODEL.Rd b/man/PKMODEL.Rd index eab32e2e5..2fc4cff87 100644 --- a/man/PKMODEL.Rd +++ b/man/PKMODEL.Rd @@ -4,8 +4,15 @@ \alias{PKMODEL} \title{Parse PKMODEL BLOCK data} \usage{ -PKMODEL(ncmt = 1, depot = FALSE, cmt = NULL, - trans = pick_trans(ncmt, depot), env = list(), pos = 1, ...) +PKMODEL( + ncmt = 1, + depot = FALSE, + cmt = NULL, + trans = pick_trans(ncmt, depot), + env = list(), + pos = 1, + ... +) } \arguments{ \item{ncmt}{number of compartments; must be 1 (one-compartment, diff --git a/man/Req.Rd b/man/Req.Rd index 46a5c3c2a..bfb5d62f1 100644 --- a/man/Req.Rd +++ b/man/Req.Rd @@ -36,7 +36,7 @@ all of the captured items are returned. Remember that \code{req} is strictly for compartments. } \examples{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() mod \%>\% Req(CP,RESP) \%>\% ev(amt=1000) \%>\% mrgsim diff --git a/man/as.ev.Rd b/man/as.ev.Rd index 778af17b4..193b263d3 100644 --- a/man/as.ev.Rd +++ b/man/as.ev.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/events.R -\docType{methods} \name{as.ev} \alias{as.ev} \alias{as.ev,data.frame-method} diff --git a/man/as.list-mrgmod-method.Rd b/man/as.list-mrgmod-method.Rd index feb20e982..ce7a1e542 100644 --- a/man/as.list-mrgmod-method.Rd +++ b/man/as.list-mrgmod-method.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/class_mrgmod.R -\docType{methods} \name{as.list,mrgmod-method} \alias{as.list,mrgmod-method} \title{Coerce a model object to list} @@ -34,9 +33,9 @@ functions (with a call to \code{mrgsolve:::funset}). \item \code{cmt}: names of model compartments \item \code{param}: the parameter list \item \code{init}: initial condition list -\item \code{omega}: \code{$OMEGA} matrices, as a \code{matlist} object -\item \code{sigma}: \code{$SIGMA} matrices, as a \code{matlist} object -\item \code{fixed}: named list of \code{$FIXED} values +\item \code{omega}: \verb{$OMEGA} matrices, as a \code{matlist} object +\item \code{sigma}: \verb{$SIGMA} matrices, as a \code{matlist} object +\item \code{fixed}: named list of \verb{$FIXED} values \item \code{model}: model name \item \code{project}: model project directory \item \code{soloc}: directory where the model is being built @@ -51,7 +50,7 @@ functions (with a call to \code{mrgsolve:::funset}). \item \code{request}: compartments requested upon simulation \item \code{cmti}: named indices for current output compartments \item \code{capturei}: named indices for current output capture -\item \code{random}: names and labels of \code{$OMEGA} and \code{$SIGMA} +\item \code{random}: names and labels of \verb{$OMEGA} and \verb{$SIGMA} \item \code{code}: model source code from \code{cfile} \item \code{details}: model details data frame \item \code{atol}: see \link{solversettings} diff --git a/man/as.list-mrgsims-method.Rd b/man/as.list-mrgsims-method.Rd index 889001b66..bcad0d5f5 100644 --- a/man/as.list-mrgsims-method.Rd +++ b/man/as.list-mrgsims-method.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/class_mrgsims.R -\docType{methods} \name{as.list,mrgsims-method} \alias{as.list,mrgsims-method} \title{Coerce an mrgsims object to list} diff --git a/man/as_data_set.Rd b/man/as_data_set.Rd index 7dadabdb9..5ec8a7f73 100644 --- a/man/as_data_set.Rd +++ b/man/as_data_set.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/data_set.R -\docType{methods} \name{as_data_set} \alias{as_data_set} \alias{as_data_set,ev-method} diff --git a/man/blocks.Rd b/man/blocks.Rd index 11c28ba44..75230819e 100644 --- a/man/blocks.Rd +++ b/man/blocks.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/generics.R, R/class_mrgmod.R -\docType{methods} \name{blocks} \alias{blocks} \alias{blocks,mrgmod-method} @@ -22,7 +21,7 @@ blocks(x, ...) Return the code blocks from a model specification file } \examples{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() mod \%>\% blocks mod \%>\% blocks(PARAM,TABLE) diff --git a/man/cmtn.Rd b/man/cmtn.Rd index ea3cf1e8b..04d412ee3 100644 --- a/man/cmtn.Rd +++ b/man/cmtn.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/generics.R, R/class_mrgmod.R -\docType{methods} \name{cmtn} \alias{cmtn} \alias{cmtn,mrgmod-method} @@ -21,6 +20,6 @@ cmtn(x, ...) Get the compartment number from a compartment name } \examples{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() mod \%>\% cmtn("CENT") } diff --git a/man/data_set.Rd b/man/data_set.Rd index 77de12b02..063cd0c28 100644 --- a/man/data_set.Rd +++ b/man/data_set.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/data_set.R -\docType{methods} \name{data_set} \alias{data_set} \alias{data_set,mrgmod,data.frame-method} @@ -11,8 +10,15 @@ \usage{ data_set(x, data, ...) -\S4method{data_set}{mrgmod,data.frame}(x, data, .subset = TRUE, - .select = TRUE, object = NULL, need = NULL, ...) +\S4method{data_set}{mrgmod,data.frame}( + x, + data, + .subset = TRUE, + .select = TRUE, + object = NULL, + need = NULL, + ... +) \S4method{data_set}{mrgmod,ANY}(x, data, ...) @@ -96,7 +102,7 @@ See \code{\link{exdatasets}} for different example data sets. } \examples{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() data <- expand.ev(ID=1:3, amt=c(10,20)) diff --git a/man/design.Rd b/man/design.Rd index 209967ac8..1a88aaeb4 100644 --- a/man/design.Rd +++ b/man/design.Rd @@ -45,7 +45,7 @@ data$GRP <- data$amt/100 idata <- data[,c("ID", "amt")] -mod <- mrgsolve:::house() +mod <- mrgsolve::house() mod \%>\% omat(dmat(1,1,1,1)) \%>\% diff --git a/man/details.Rd b/man/details.Rd index 0a94d9401..e075912d9 100644 --- a/man/details.Rd +++ b/man/details.Rd @@ -25,7 +25,7 @@ This function is not exported. You will have to call it with \code{mrgsolve:::details()}. } \examples{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() mrgsolve:::details(mod) diff --git a/man/drop_re.Rd b/man/drop_re.Rd new file mode 100644 index 000000000..2873831ad --- /dev/null +++ b/man/drop_re.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/matlist.R +\name{drop_re} +\alias{drop_re} +\alias{drop.re} +\title{Deprecated: drop random effect matrices from model object} +\usage{ +drop_re(.x, ...) + +drop.re(...) +} +\arguments{ +\item{.x}{not used} + +\item{...}{not used} +} +\description{ +Deprecated: drop random effect matrices from model object +} +\details{ +Users are no longer allowed to remove random effect matrices from the model +object. Use \link{zero_re} instead to convert the matrix to all zeros. +} +\seealso{ +\link{zero_re} +} diff --git a/man/ev.Rd b/man/ev.Rd index 524dff304..6c091daf5 100644 --- a/man/ev.Rd +++ b/man/ev.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/events.R -\docType{methods} \name{ev} \alias{ev} \alias{ev,mrgmod-method} @@ -12,9 +11,18 @@ ev(x, ...) \S4method{ev}{mrgmod}(x, object = NULL, ...) -\S4method{ev}{missing}(time = 0, amt = 0, evid = 1, cmt = 1, - ID = numeric(0), replicate = TRUE, until = NULL, tinf = NULL, - realize_addl = FALSE, ...) +\S4method{ev}{missing}( + time = 0, + amt = 0, + evid = 1, + cmt = 1, + ID = numeric(0), + replicate = TRUE, + until = NULL, + tinf = NULL, + realize_addl = FALSE, + ... +) \S4method{ev}{ev}(x, realize_addl = FALSE, ...) } @@ -75,7 +83,7 @@ event rows must match the number of \code{ID}s entered } } \examples{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() mod <- mod \%>\% ev(amt=1000, time=0, cmt=1) diff --git a/man/ev_days.Rd b/man/ev_days.Rd index a0bdfe1cb..1990ace74 100644 --- a/man/ev_days.Rd +++ b/man/ev_days.Rd @@ -4,8 +4,14 @@ \alias{ev_days} \title{Schedule dosing events on days of the week} \usage{ -ev_days(ev = NULL, days = "", addl = 0, ii = 168, - unit = c("hours", "days"), ...) +ev_days( + ev = NULL, + days = "", + addl = 0, + ii = 168, + unit = c("hours", "days"), + ... +) } \arguments{ \item{ev}{an event object} diff --git a/man/ev_extract.Rd b/man/ev_extract.Rd index 6694d4c76..0b76cde72 100644 --- a/man/ev_extract.Rd +++ b/man/ev_extract.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/class_ev.R -\docType{methods} \name{$,ev-method} \alias{$,ev-method} \alias{[[,ev-method} diff --git a/man/ev_methods.Rd b/man/ev_methods.Rd index 791b99ee4..2850fa2f2 100644 --- a/man/ev_methods.Rd +++ b/man/ev_methods.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/class_ev.R -\docType{methods} \name{ev_methods} \alias{ev_methods} \alias{names.ev} @@ -16,8 +15,7 @@ \method{as.matrix}{ev}(x, ...) -\method{as.data.frame}{ev}(x, row.names = NULL, optional = FALSE, - add_ID = NULL, ...) +\method{as.data.frame}{ev}(x, row.names = NULL, optional = FALSE, add_ID = NULL, ...) \S4method{show}{ev}(object) } diff --git a/man/ev_rx.Rd b/man/ev_rx.Rd index 249455316..2e76e5072 100644 --- a/man/ev_rx.Rd +++ b/man/ev_rx.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/class_rx.R -\docType{methods} \name{ev_rx} \alias{ev_rx} \alias{ev_rx,mrgmod,character-method} @@ -40,13 +39,13 @@ by \link{parse_rx}; this function can be used to debug Rx inputs. \itemize{ \item The dose is found at the start of the string by sequential digits; this may be integer, decimal, or in scientific notation -\item Use \code{in} to identify the dosing compartment number; must be integer +\item Use \verb{in} to identify the dosing compartment number; must be integer \item Use \code{q} to identify the dosing interval; must be integer or decimal number (but not scientific notation) \item Use \code{over} to indicate an infusion and its duration; integer or decimal number \item Use \code{x} to indicate total number of doses; must be integer -\item Use \code{then} or \code{,} to separate dosing periods +\item Use \code{then} or \verb{,} to separate dosing periods \item User \code{after} to insert a lag in the start of a period; integer or decimal number (but not scientific notation) } diff --git a/man/exdatasets.Rd b/man/exdatasets.Rd index 8a33aa578..c25b0f864 100644 --- a/man/exdatasets.Rd +++ b/man/exdatasets.Rd @@ -39,7 +39,7 @@ Example input data sets } \examples{ -mod <- mrgsolve:::house() \%>\% update(end=240) \%>\% Req(CP) +mod <- mrgsolve::house() \%>\% update(end=240) \%>\% Req(CP) ## Full data set data(exTheoph) diff --git a/man/figures/lifecycle-archived.svg b/man/figures/lifecycle-archived.svg new file mode 100644 index 000000000..48f72a6f3 --- /dev/null +++ b/man/figures/lifecycle-archived.svg @@ -0,0 +1 @@ + lifecyclelifecyclearchivedarchived \ No newline at end of file diff --git a/man/figures/lifecycle-defunct.svg b/man/figures/lifecycle-defunct.svg new file mode 100644 index 000000000..01452e5fb --- /dev/null +++ b/man/figures/lifecycle-defunct.svg @@ -0,0 +1 @@ +lifecyclelifecycledefunctdefunct \ No newline at end of file diff --git a/man/figures/lifecycle-deprecated.svg b/man/figures/lifecycle-deprecated.svg new file mode 100644 index 000000000..4baaee01c --- /dev/null +++ b/man/figures/lifecycle-deprecated.svg @@ -0,0 +1 @@ +lifecyclelifecycledeprecateddeprecated \ No newline at end of file diff --git a/man/figures/lifecycle-experimental.svg b/man/figures/lifecycle-experimental.svg new file mode 100644 index 000000000..d1d060e92 --- /dev/null +++ b/man/figures/lifecycle-experimental.svg @@ -0,0 +1 @@ +lifecyclelifecycleexperimentalexperimental \ No newline at end of file diff --git a/man/figures/lifecycle-maturing.svg b/man/figures/lifecycle-maturing.svg new file mode 100644 index 000000000..df7131014 --- /dev/null +++ b/man/figures/lifecycle-maturing.svg @@ -0,0 +1 @@ +lifecyclelifecyclematuringmaturing \ No newline at end of file diff --git a/man/figures/lifecycle-questioning.svg b/man/figures/lifecycle-questioning.svg new file mode 100644 index 000000000..08ee0c903 --- /dev/null +++ b/man/figures/lifecycle-questioning.svg @@ -0,0 +1 @@ +lifecyclelifecyclequestioningquestioning \ No newline at end of file diff --git a/man/figures/lifecycle-retired.svg b/man/figures/lifecycle-retired.svg new file mode 100644 index 000000000..33f406b12 --- /dev/null +++ b/man/figures/lifecycle-retired.svg @@ -0,0 +1 @@ + lifecyclelifecycleretiredretired \ No newline at end of file diff --git a/man/figures/lifecycle-soft-deprecated.svg b/man/figures/lifecycle-soft-deprecated.svg new file mode 100644 index 000000000..9f014fd19 --- /dev/null +++ b/man/figures/lifecycle-soft-deprecated.svg @@ -0,0 +1 @@ +lifecyclelifecyclesoft-deprecatedsoft-deprecated \ No newline at end of file diff --git a/man/figures/lifecycle-stable.svg b/man/figures/lifecycle-stable.svg new file mode 100644 index 000000000..e015dc811 --- /dev/null +++ b/man/figures/lifecycle-stable.svg @@ -0,0 +1 @@ +lifecyclelifecyclestablestable \ No newline at end of file diff --git a/man/house.Rd b/man/house.Rd index ec9f4dc78..9d2350ec8 100644 --- a/man/house.Rd +++ b/man/house.Rd @@ -17,10 +17,11 @@ Return a pre-compiled, PK/PD model } \examples{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() see(mod) mod \%>\% ev(amt=100) \%>\% mrgsim \%>\% plot } +\keyword{internal} diff --git a/man/idata_set.Rd b/man/idata_set.Rd index fd9b25cc1..7367157ca 100644 --- a/man/idata_set.Rd +++ b/man/idata_set.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/idata_set.R -\docType{methods} \name{idata_set} \alias{idata_set} \alias{idata_set,mrgmod,data.frame-method} @@ -10,8 +9,15 @@ \usage{ idata_set(x, data, ...) -\S4method{idata_set}{mrgmod,data.frame}(x, data, .subset = TRUE, - .select = TRUE, object = NULL, need = NULL, ...) +\S4method{idata_set}{mrgmod,data.frame}( + x, + data, + .subset = TRUE, + .select = TRUE, + object = NULL, + need = NULL, + ... +) \S4method{idata_set}{mrgmod,ANY}(x, data, ...) @@ -71,7 +77,7 @@ An error will be generated if any parameter columns in the input idata set contain \code{NA}. } \examples{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() data(exidata) diff --git a/man/init.Rd b/man/init.Rd index c82225210..ec4c2b6d9 100644 --- a/man/init.Rd +++ b/man/init.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/init.R -\docType{methods} \name{init} \alias{init} \alias{init,mrgmod-method} @@ -53,7 +52,7 @@ to a list or numeric R object. } \examples{ ## example("init") -mod <- mrgsolve:::house() +mod <- mrgsolve::house() init(mod) init(mod, .pat="^C") ## may be useful for large models diff --git a/man/knobs.Rd b/man/knobs.Rd index e1de0a2e8..95e41e2be 100644 --- a/man/knobs.Rd +++ b/man/knobs.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/knobs.R -\docType{methods} \name{knobs} \alias{knobs} \alias{knobs,mrgmod,missing-method} @@ -16,8 +15,7 @@ knobs(x, y, ...) \S4method{knobs}{mrgmod,batch_mrgsims}(x, y, ...) -\S4method{as.data.frame}{batch_mrgsims}(x, row.names = NULL, - optional = FALSE, ...) +\S4method{as.data.frame}{batch_mrgsims}(x, row.names = NULL, optional = FALSE, ...) \S4method{knobs}{batch_mrgsims,ANY}(x, y, ...) @@ -55,7 +53,7 @@ time variables (\code{start}, \code{end}, \code{delta}), PK dosing items \examples{ ## example("knobs") -mod <- mrgsolve:::house(end=72) +mod <- mrgsolve::house(end=72) events <- ev(amt=1000, cmt=1, addl=3, ii=12) diff --git a/man/matlist.Rd b/man/matlist.Rd index 7721828b0..c27adf7c0 100644 --- a/man/matlist.Rd +++ b/man/matlist.Rd @@ -1,13 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/matlist.R -\docType{methods} \name{matlist} \alias{matlist} \alias{zero.re} \alias{zero.re,mrgmod-method} \alias{zero_re} -\alias{drop_re} -\alias{drop.re} \alias{as.list,matlist-method} \alias{as.matrix,matlist-method} \alias{names.matlist} @@ -24,10 +21,6 @@ zero.re(.x, ...) zero_re(...) -drop_re(.x, ...) - -drop.re(...) - \S4method{as.list}{matlist}(x, ...) \S4method{as.matrix}{matlist}(x, ...) diff --git a/man/matlist_ops.Rd b/man/matlist_ops.Rd index dfcf1301e..7ee66f7d4 100644 --- a/man/matlist_ops.Rd +++ b/man/matlist_ops.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/matlist.R -\docType{methods} \name{c,matlist-method} \alias{c,matlist-method} \title{Operations with matlist objects} diff --git a/man/matrix_converters.Rd b/man/matrix_converters.Rd index f705742fa..94b818ae4 100644 --- a/man/matrix_converters.Rd +++ b/man/matrix_converters.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/matrix.R -\docType{methods} \name{as_bmat} \alias{as_bmat} \alias{as_bmat,list-method} diff --git a/man/mcode.Rd b/man/mcode.Rd index 5ac9ac6f1..82c1034f0 100644 --- a/man/mcode.Rd +++ b/man/mcode.Rd @@ -5,11 +5,14 @@ \alias{mcode_cache} \title{Write, compile, and load model code} \usage{ -mcode(model, code, project = getOption("mrgsolve.project", tempdir()), - ...) - -mcode_cache(model, code, project = getOption("mrgsolve.project", - tempdir()), ...) +mcode(model, code, project = getOption("mrgsolve.project", tempdir()), ...) + +mcode_cache( + model, + code, + project = getOption("mrgsolve.project", tempdir()), + ... +) } \arguments{ \item{model}{model name} diff --git a/man/merge.Rd b/man/merge.Rd index 1759ca790..3a9361e06 100644 --- a/man/merge.Rd +++ b/man/merge.Rd @@ -4,8 +4,7 @@ \alias{merge.list} \title{Merge two lists} \usage{ -\method{merge}{list}(x, y, ..., open = FALSE, warn = TRUE, - context = "object", wild = "...") +\method{merge}{list}(x, y, ..., open = FALSE, warn = TRUE, context = "object", wild = "...") } \arguments{ \item{x}{the original list} diff --git a/man/mod.Rd b/man/mod.Rd index afb3b4006..eddb57f02 100644 --- a/man/mod.Rd +++ b/man/mod.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/generics.R, R/mrgsims.R -\docType{methods} \name{mod} \alias{mod} \alias{mod,mrgsims-method} diff --git a/man/modMATRIX.Rd b/man/modMATRIX.Rd index e2a333a27..24e055fb6 100644 --- a/man/modMATRIX.Rd +++ b/man/modMATRIX.Rd @@ -4,8 +4,15 @@ \alias{modMATRIX} \title{Create a matrix} \usage{ -modMATRIX(x, use = TRUE, block = FALSE, correlation = FALSE, - digits = -1, context = "matlist", ...) +modMATRIX( + x, + use = TRUE, + block = FALSE, + correlation = FALSE, + digits = -1, + context = "matlist", + ... +) } \arguments{ \item{x}{data for building the matrix. Data in \code{x} are assumed to be diff --git a/man/modelparse.Rd b/man/modelparse.Rd index 7edf56ef3..3fe9aa317 100644 --- a/man/modelparse.Rd +++ b/man/modelparse.Rd @@ -5,11 +5,9 @@ \alias{modelparse_rmd} \title{Parse model specification text} \usage{ -modelparse(txt, split = FALSE, drop_blank = TRUE, - comment_re = c("//", "##")) +modelparse(txt, split = FALSE, drop_blank = TRUE, comment_re = c("//", "##")) -modelparse_rmd(txt, split = FALSE, drop_blank = TRUE, - comment_re = "//") +modelparse_rmd(txt, split = FALSE, drop_blank = TRUE, comment_re = "//") } \arguments{ \item{txt}{model specification text} diff --git a/man/mread.Rd b/man/mread.Rd index 33f743296..2330da37c 100644 --- a/man/mread.Rd +++ b/man/mread.Rd @@ -6,18 +6,35 @@ \alias{mread_file} \title{Read a model specification file} \usage{ -mread(model, project = getOption("mrgsolve.project", getwd()), - code = NULL, file = NULL, udll = TRUE, ignore.stdout = TRUE, - raw = FALSE, compile = TRUE, audit = TRUE, +mread( + model, + project = getOption("mrgsolve.project", getwd()), + code = NULL, + file = NULL, + udll = TRUE, + ignore.stdout = TRUE, + raw = FALSE, + compile = TRUE, + audit = TRUE, quiet = getOption("mrgsolve_mread_quiet", FALSE), - check.bounds = FALSE, warn = TRUE, - soloc = getOption("mrgsolve.soloc", tempdir()), preclean = FALSE, - recover = FALSE, ...) - -mread_cache(model = NULL, project = getOption("mrgsolve.project", - getwd()), file = paste0(model, ".cpp"), code = NULL, - soloc = getOption("mrgsolve.soloc", tempdir()), quiet = FALSE, - preclean = FALSE, ...) + check.bounds = FALSE, + warn = TRUE, + soloc = getOption("mrgsolve.soloc", tempdir()), + preclean = FALSE, + recover = FALSE, + ... +) + +mread_cache( + model = NULL, + project = getOption("mrgsolve.project", getwd()), + file = paste0(model, ".cpp"), + code = NULL, + soloc = getOption("mrgsolve.soloc", tempdir()), + quiet = FALSE, + preclean = FALSE, + ... +) mread_file(file, ...) } diff --git a/man/mrgmod-class.Rd b/man/mrgmod-class.Rd index 686f3a362..fe3219c44 100644 --- a/man/mrgmod-class.Rd +++ b/man/mrgmod-class.Rd @@ -96,13 +96,16 @@ the simulation \code{}} \item{\code{plugin}}{model plugins \code{}} -\item{\code{Icap}}{capture indices to recover in the simulation} +\item{\code{Icap}}{capture indices to recover in the simulation \code{}} -\item{\code{capL}}{labels for \code{Icap}} +\item{\code{capL}}{labels for \code{Icap}; \code{}} -\item{\code{Icmt}}{compartment indices to recover in the simulation} +\item{\code{Icmt}}{compartment indices to recover in the simulation \code{}} -\item{\code{cmtL}}{labels for \code{Icmt}} +\item{\code{cmtL}}{labels for \code{Icmt}; \code{}} + +\item{\code{ss_cmt}}{compartments numbers to be considered when advancing the system +to steady state \code{}} }} \section{Notes}{ diff --git a/man/mrgmod_extract.Rd b/man/mrgmod_extract.Rd index 63403a652..0c574956e 100644 --- a/man/mrgmod_extract.Rd +++ b/man/mrgmod_extract.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/class_mrgmod.R -\docType{methods} \name{$,mrgmod-method} \alias{$,mrgmod-method} \alias{[[,mrgmod-method} diff --git a/man/mrgsim.Rd b/man/mrgsim.Rd index e39e45545..4dac1c8fe 100644 --- a/man/mrgsim.Rd +++ b/man/mrgsim.Rd @@ -10,13 +10,30 @@ mrgsim(x, data = NULL, idata = NULL, events = NULL, nid = 1, ...) mrgsim_df(..., output = "df") -do_mrgsim(x, data, idata = no_idata_set(), carry_out = carry.out, - carry.out = character(0), seed = as.integer(NA), - Request = character(0), output = NULL, capture = NULL, - obsonly = FALSE, obsaug = FALSE, tgrid = NULL, recsort = 1, - deslist = list(), descol = character(0), filbak = TRUE, - tad = FALSE, nocb = TRUE, skip_init_calc = FALSE, ss_n = 500, - ss_fixed = FALSE, ...) +do_mrgsim( + x, + data, + idata = no_idata_set(), + carry_out = carry.out, + carry.out = character(0), + seed = as.integer(NA), + Request = character(0), + output = NULL, + capture = NULL, + obsonly = FALSE, + obsaug = FALSE, + tgrid = NULL, + recsort = 1, + deslist = list(), + descol = character(0), + filbak = TRUE, + tad = FALSE, + nocb = TRUE, + skip_init_calc = FALSE, + ss_n = 500, + ss_fixed = FALSE, + ... +) } \arguments{ \item{x}{the model object} @@ -157,7 +174,7 @@ simulated output that occur prior to the first record in \code{data}. e <- ev(amt = 1000) -mod <- mrgsolve:::house() +mod <- mrgsolve::house() out <- mod \%>\% ev(e) \%>\% mrgsim() diff --git a/man/mrgsim_q.Rd b/man/mrgsim_q.Rd index 2418523c7..d10482e34 100644 --- a/man/mrgsim_q.Rd +++ b/man/mrgsim_q.Rd @@ -4,8 +4,15 @@ \alias{mrgsim_q} \title{Simulate from a model object with quicker turnaround} \usage{ -mrgsim_q(x, data, recsort = 1, stime = numeric(0), - output = "mrgsims", skip_init_calc = FALSE, simcall = 0) +mrgsim_q( + x, + data, + recsort = 1, + stime = numeric(0), + output = "mrgsims", + skip_init_calc = FALSE, + simcall = 0 +) } \arguments{ \item{x}{a model object} @@ -70,7 +77,7 @@ data.frame of simulated data on return. } \examples{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() data <- expand.ev(amt = c(100,300,1000)) diff --git a/man/mrgsims.Rd b/man/mrgsims.Rd index 0f6b5e8f7..eab4ad5fe 100644 --- a/man/mrgsims.Rd +++ b/man/mrgsims.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/mrgsims.R -\docType{methods} \name{mrgsims} \alias{mrgsims} \alias{$,mrgsims-method} @@ -24,8 +23,7 @@ \S4method{names}{mrgsims}(x) -\S4method{as.data.frame}{mrgsims}(x, row.names = NULL, - optional = FALSE, ...) +\S4method{as.data.frame}{mrgsims}(x, row.names = NULL, optional = FALSE, ...) \S4method{as.matrix}{mrgsims}(x, ...) @@ -80,7 +78,7 @@ commonly used in R (e.g. head, tail, as.data.frame, etc ...) ## example("mrgsims") -mod <- mrgsolve:::house() \%>\% init(GUT=100) +mod <- mrgsolve::house() \%>\% init(GUT=100) out <- mrgsim(mod) diff --git a/man/mrgsims_dplyr.Rd b/man/mrgsims_dplyr.Rd index dd82871cc..715e7e850 100644 --- a/man/mrgsims_dplyr.Rd +++ b/man/mrgsims_dplyr.Rd @@ -14,6 +14,7 @@ \alias{summarise.mrgsims} \alias{do.mrgsims} \alias{select.mrgsims} +\alias{select_sims} \alias{slice.mrgsims} \alias{as_data_frame.mrgsims} \alias{as_tibble.mrgsims} @@ -43,6 +44,8 @@ mutate_sims(.data, ...) \method{select}{mrgsims}(.data, ...) +select_sims(.data, ...) + \method{slice}{mrgsims}(.data, ...) as_data_frame.mrgsims(.data_, ...) @@ -69,3 +72,9 @@ as_data_frame.mrgsims(.data_, ...) \description{ Methods for handling output with dplyr verbs } +\details{ +For the \code{select_sims} function, the dots \code{...} must be either +compartment names or variables in \code{$CAPTURE}. An error will be +generated if no valid names are selected or the names for selection are +not found in the simulated output. +} diff --git a/man/mrgsolve_package.Rd b/man/mrgsolve_package.Rd index 811ebd521..33c751fa4 100644 --- a/man/mrgsolve_package.Rd +++ b/man/mrgsolve_package.Rd @@ -3,7 +3,6 @@ \docType{package} \name{mrgsolve} \alias{mrgsolve} -\alias{mrgsolve-package} \title{mrgsolve} \description{ mrgsolve is an R package maintained under the auspices of @@ -39,7 +38,7 @@ an item in the model object that doesn't exist ## example("mrgsolve") -mod <- mrgsolve:::house(delta=0.1) \%>\% param(CL=0.5) +mod <- mrgsolve::house(delta=0.1) \%>\% param(CL=0.5) events <- ev(amt=1000, cmt=1, addl=5, ii=24) diff --git a/man/names-mrgmod-method.Rd b/man/names-mrgmod-method.Rd index 95d92fc4b..ff6c93dac 100644 --- a/man/names-mrgmod-method.Rd +++ b/man/names-mrgmod-method.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/class_mrgmod.R -\docType{methods} \name{names,mrgmod-method} \alias{names,mrgmod-method} \title{Get all names from a model object} @@ -14,7 +13,7 @@ Get all names from a model object } \examples{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() names(mod) } diff --git a/man/nmxml.Rd b/man/nmxml.Rd index c08a54212..88fd6a946 100644 --- a/man/nmxml.Rd +++ b/man/nmxml.Rd @@ -5,11 +5,24 @@ \alias{NMXML} \title{Get THETA, OMEGA and SIGMA from a completed NONMEM run} \usage{ -nmxml(run = numeric(0), project = character(0), file = character(0), - theta = TRUE, omega = TRUE, sigma = TRUE, olabels = NULL, - slabels = NULL, oprefix = "", sprefix = "", tname = "THETA", - oname = "...", sname = "...", index = "last", - xpath = ".//nm:estimation", ...) +nmxml( + run = numeric(0), + project = character(0), + file = character(0), + theta = TRUE, + omega = TRUE, + sigma = TRUE, + olabels = NULL, + slabels = NULL, + oprefix = "", + sprefix = "", + tname = "THETA", + oname = "...", + sname = "...", + index = "last", + xpath = ".//nm:estimation", + ... +) } \arguments{ \item{run}{run number} diff --git a/man/numericlist.Rd b/man/numericlist.Rd index bb1993e9a..88dab935e 100644 --- a/man/numericlist.Rd +++ b/man/numericlist.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/class_numericlist.R -\docType{methods} \name{numericlist} \alias{numericlist} \alias{as.list,numericlist-method} @@ -17,8 +16,7 @@ \S4method{as.numeric}{numericlist}(x) -\S4method{as.data.frame}{numericlist}(x, row.names = NULL, - optional = FALSE, ...) +\S4method{as.data.frame}{numericlist}(x, row.names = NULL, optional = FALSE, ...) \S4method{length}{numericlist}(x) diff --git a/man/omega.Rd b/man/omega.Rd index 45de13f13..37229412e 100644 --- a/man/omega.Rd +++ b/man/omega.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/matlist.R -\docType{methods} \name{omega} \alias{omega} \alias{omat} @@ -60,7 +59,7 @@ omat(mat1) omat(mat1, mat2, mat3) omat(A=mat1, B=mat2, C=mat3) -mod <- mrgsolve:::house() \%>\% omat(mat4) +mod <- mrgsolve::house() \%>\% omat(mat4) omat(mod) omat(mod, make=TRUE) @@ -74,9 +73,9 @@ $OMEGA $OMEGA @block 1 0.1 2 -$OMEGA \\@cor -\\@ prefix ETA_ -\\@ labels CL VC KA +$OMEGA \@cor +\@ prefix ETA_ +\@ labels CL VC KA 0.1 0.67 0.2 0 0 0.3 diff --git a/man/outvars.Rd b/man/outvars.Rd new file mode 100644 index 000000000..b2d3dc376 --- /dev/null +++ b/man/outvars.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/class_mrgmod.R +\name{outvars} +\alias{outvars} +\title{Show names of current output variables} +\usage{ +outvars(x, unlist = FALSE) +} +\arguments{ +\item{x}{mrgmod object} + +\item{unlist}{if \code{TRUE} then a character vector (rather than list) is +returned} +} +\value{ +When \code{unlist} is \code{FALSE} (default) : a named list, with \code{cmt} showing names +of output compartments and \code{capture} giving names of output variables in +capture. When \code{unlist} is \code{TRUE}, then a single, unnamed character vector +of outvar names is returned. +} +\description{ +Show names of current output variables +} +\examples{ + +outvars(mrgsolve::house()) + +} diff --git a/man/param.Rd b/man/param.Rd index d02f339cb..244f7ff0a 100644 --- a/man/param.Rd +++ b/man/param.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/param.R -\docType{methods} \name{param} \alias{param} \alias{param,mrgmod-method} @@ -13,8 +12,7 @@ \usage{ param(.x, ...) -\S4method{param}{mrgmod}(.x, .y = list(), ..., .pat = "*", - .strict = FALSE) +\S4method{param}{mrgmod}(.x, .y = list(), ..., .pat = "*", .strict = FALSE) \S4method{param}{mrgsims}(.x, ...) @@ -63,7 +61,7 @@ both model parameters and data items listed in \code{$FIXED}. \examples{ ## example("param") -mod <- mrgsolve:::house() +mod <- mrgsolve::house() param(mod) diff --git a/man/plot_batch_mrgsims.Rd b/man/plot_batch_mrgsims.Rd index 11604bb11..292b4090a 100644 --- a/man/plot_batch_mrgsims.Rd +++ b/man/plot_batch_mrgsims.Rd @@ -1,17 +1,23 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/knobs.R -\docType{methods} \name{plot,batch_mrgsims,missing-method} \alias{plot,batch_mrgsims,missing-method} \alias{plot,batch_mrgsims,formula-method} \title{Plot method for mrgsims objects} \usage{ -\S4method{plot}{batch_mrgsims,missing}(x, yval = variables(x), - auto.key = list(), mincol = 3, ...) - -\S4method{plot}{batch_mrgsims,formula}(x, y, show.grid = TRUE, lwd = 2, - type = "l", yval = variables(x), auto.key = list(columns = 1), - scales = list(y = list(relation = "free")), ...) +\S4method{plot}{batch_mrgsims,missing}(x, yval = variables(x), auto.key = list(), mincol = 3, ...) + +\S4method{plot}{batch_mrgsims,formula}( + x, + y, + show.grid = TRUE, + lwd = 2, + type = "l", + yval = variables(x), + auto.key = list(columns = 1), + scales = list(y = list(relation = "free")), + ... +) } \arguments{ \item{x}{mrgsims object} diff --git a/man/plot_mrgsims.Rd b/man/plot_mrgsims.Rd index f7029b759..a6c471af3 100644 --- a/man/plot_mrgsims.Rd +++ b/man/plot_mrgsims.Rd @@ -1,18 +1,31 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/mrgsims.R -\docType{methods} \name{plot_mrgsims} \alias{plot_mrgsims} \alias{plot,mrgsims,missing-method} \alias{plot,mrgsims,formula-method} +\alias{plot,mrgsims,character-method} \title{Generate a quick plot of simulated data} \usage{ \S4method{plot}{mrgsims,missing}(x, limit = 16, ...) -\S4method{plot}{mrgsims,formula}(x, y, limit = 16, show.grid = TRUE, - outer = TRUE, type = "l", lwd = 2, ylab = "value", groups = ID, - scales = list(y = list(relation = "free")), logy = FALSE, - logbr = 1, ...) +\S4method{plot}{mrgsims,formula}( + x, + y, + limit = 16, + show.grid = TRUE, + outer = TRUE, + type = "l", + lwd = 2, + ylab = "value", + groups = ID, + scales = list(y = list(relation = "free")), + logy = FALSE, + logbr = 1, + ... +) + +\S4method{plot}{mrgsims,character}(x, y, ...) } \arguments{ \item{x}{mrgsims object} @@ -48,7 +61,7 @@ Generate a quick plot of simulated data } \examples{ -mod <- mrgsolve:::house(end=48, delta=0.2) \%>\% init(GUT=1000) +mod <- mrgsolve::house(end=48, delta=0.2) \%>\% init(GUT=1000) out <- mrgsim(mod) @@ -60,4 +73,8 @@ plot(out, GUT+CP~.) plot(out, CP+RESP~time, col="black", scales="same", lty=2) +\dontrun{ +plot(out, "CP RESP, GUT") +} + } diff --git a/man/plot_sims.Rd b/man/plot_sims.Rd index 44c9f8644..ad8dd4e62 100644 --- a/man/plot_sims.Rd +++ b/man/plot_sims.Rd @@ -24,7 +24,7 @@ were created by modifying an \code{mrgsims} object. } \examples{ -mod <- mrgsolve:::house() \%>\% ev(amt = 100) +mod <- mrgsolve::house() \%>\% ev(amt = 100) out <- mrgsim(mod) out_df <- dplyr::mutate(out, time <= 72) diff --git a/man/qsim.Rd b/man/qsim.Rd index ec69a1398..1137662c9 100644 --- a/man/qsim.Rd +++ b/man/qsim.Rd @@ -4,9 +4,19 @@ \alias{qsim} \title{Basic, simple simulation from model object} \usage{ -qsim(x, data, idata = no_idata_set(), obsonly = FALSE, tgrid = NULL, - recsort = 1, tad = FALSE, Req = NULL, outvars = Req, - skip_init_calc = FALSE, output = "mrgsims") +qsim( + x, + data, + idata = no_idata_set(), + obsonly = FALSE, + tgrid = NULL, + recsort = 1, + tad = FALSE, + Req = NULL, + outvars = Req, + skip_init_calc = FALSE, + output = "mrgsims" +) } \arguments{ \item{x}{the model object} @@ -67,7 +77,7 @@ Use the \link[mrgsolve:update]{mrgsolve::update} method to update the model obje } \examples{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() dose <- ev(amt = 100) diff --git a/man/read_nmext.Rd b/man/read_nmext.Rd index dc0cec9c6..96c1eb69e 100644 --- a/man/read_nmext.Rd +++ b/man/read_nmext.Rd @@ -4,8 +4,7 @@ \alias{read_nmext} \title{Extract estimates from NONMEM ext file} \usage{ -read_nmext(run, project = getwd(), file = paste0(run, ".ext"), - path = NULL) +read_nmext(run, project = getwd(), file = paste0(run, ".ext"), path = NULL) } \arguments{ \item{run}{a run number or run identifier} diff --git a/man/realize_addl.Rd b/man/realize_addl.Rd index 92470cad3..7a554b1d5 100644 --- a/man/realize_addl.Rd +++ b/man/realize_addl.Rd @@ -8,8 +8,13 @@ \usage{ realize_addl(x, ...) -\method{realize_addl}{data.frame}(x, warn = FALSE, mark_new = FALSE, - fill = c("inherit", "na", "locf"), ...) +\method{realize_addl}{data.frame}( + x, + warn = FALSE, + mark_new = FALSE, + fill = c("inherit", "na", "locf"), + ... +) \method{realize_addl}{ev}(x, ...) } diff --git a/man/render.Rd b/man/render.Rd index eb2a4c4f8..c5a5b8f41 100644 --- a/man/render.Rd +++ b/man/render.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/render.R -\docType{methods} \name{render} \alias{render} \alias{render,character-method} @@ -34,7 +33,7 @@ Render a model to a document } \examples{ \dontrun{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() mrgsolve:::render(mod) mrgsolve:::render("irm2", modlib()) } diff --git a/man/revar.Rd b/man/revar.Rd index 7af682c07..73b84780a 100644 --- a/man/revar.Rd +++ b/man/revar.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/generics.R, R/class_mrgmod.R -\docType{methods} \name{revar} \alias{revar} \alias{revar,mrgmod-method} diff --git a/man/scrape_opts.Rd b/man/scrape_opts.Rd index 1c2f0d08e..24b436677 100644 --- a/man/scrape_opts.Rd +++ b/man/scrape_opts.Rd @@ -4,8 +4,15 @@ \alias{scrape_opts} \title{Scrape options from a code block} \usage{ -scrape_opts(x, envir = list(), def = list(), all = TRUE, - marker = "=", allow_multiple = FALSE, narrow = TRUE) +scrape_opts( + x, + envir = list(), + def = list(), + all = TRUE, + marker = "=", + allow_multiple = FALSE, + narrow = TRUE +) } \arguments{ \item{x}{data} diff --git a/man/see.Rd b/man/see.Rd index 7ddcc0a5f..a0518e98d 100644 --- a/man/see.Rd +++ b/man/see.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/generics.R, R/class_mrgmod.R -\docType{methods} \name{see} \alias{see} \alias{see,mrgmod-method} diff --git a/man/show-cmt_list-method.Rd b/man/show-cmt_list-method.Rd index 728b7f46b..3a244c3f3 100644 --- a/man/show-cmt_list-method.Rd +++ b/man/show-cmt_list-method.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/init.R -\docType{methods} \name{show,cmt_list-method} \alias{show,cmt_list-method} \title{Show the compartment list} diff --git a/man/show-mrgmod-method.Rd b/man/show-mrgmod-method.Rd index 70ded593c..5a52da04b 100644 --- a/man/show-mrgmod-method.Rd +++ b/man/show-mrgmod-method.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/print.R -\docType{methods} \name{show,mrgmod-method} \alias{show,mrgmod-method} \title{Print model details} diff --git a/man/show-parameter_list-method.Rd b/man/show-parameter_list-method.Rd index f78cce425..37a8bb284 100644 --- a/man/show-parameter_list-method.Rd +++ b/man/show-parameter_list-method.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/param.R -\docType{methods} \name{show,parameter_list-method} \alias{show,parameter_list-method} \title{Show the parameter list} diff --git a/man/sigma.Rd b/man/sigma.Rd index 1e95b5b62..470fd5f48 100644 --- a/man/sigma.Rd +++ b/man/sigma.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/matlist.R -\docType{methods} \name{sigma} \alias{sigma} \alias{smat} @@ -61,7 +60,7 @@ smat(mat1) smat(mat1, mat2, mat3) smat(A=mat1, B=mat2, C=mat3) -mod <- mrgsolve:::house() \%>\% smat(mat1) +mod <- mrgsolve::house() \%>\% smat(mat1) smat(mod) smat(mod, make=TRUE) diff --git a/man/simargs.Rd b/man/simargs.Rd index 123999bb8..c871ce7df 100644 --- a/man/simargs.Rd +++ b/man/simargs.Rd @@ -25,7 +25,7 @@ list is returned. Access or clear arguments for calls to mrgsim } \examples{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() mod \%>\% Req(CP,RESP) \%>\% carry_out(evid,WT,FLAG) \%>\% simargs } diff --git a/man/soloc.Rd b/man/soloc.Rd index 331f51331..d2ea3c466 100644 --- a/man/soloc.Rd +++ b/man/soloc.Rd @@ -16,7 +16,7 @@ be rendered with a short path name} Return the location of the model shared object } \examples{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() soloc(mod) } diff --git a/man/stime.Rd b/man/stime.Rd index dd41a33b1..5376a182e 100644 --- a/man/stime.Rd +++ b/man/stime.Rd @@ -31,7 +31,7 @@ are discarded from the result. ## example("stime", package="mrgsolve") -mod <- mrgsolve:::house(end=12, delta=2, add=c(11,13,15)) +mod <- mrgsolve::house(end=12, delta=2, add=c(11,13,15)) stime(mod) diff --git a/man/tgrid.Rd b/man/tgrid.Rd index 46e649dac..b7d3cdef7 100644 --- a/man/tgrid.Rd +++ b/man/tgrid.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/class_tgrid.R, R/class_mrgmod.R -\docType{methods} \name{tgrid} \alias{tgrid} \alias{stime,tgrid-method} @@ -11,8 +10,15 @@ \alias{stime,mrgmod-method} \title{Create a simtime object} \usage{ -tgrid(start = 0, end = 24, delta = 1, add = numeric(0), - .offset = 0, .scale = 1, ...) +tgrid( + start = 0, + end = 24, + delta = 1, + add = numeric(0), + .offset = 0, + .scale = 1, + ... +) \S4method{stime}{tgrid}(x, ...) @@ -59,7 +65,7 @@ day1 <- c(peak,sparse) design <- c(day1, day1+72, day1+240) \dontrun{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() out <- mod \%>\% ev(amt=1000, ii=24, addl=10) \%>\% mrgsim(tgrid=design) diff --git a/man/tscale.Rd b/man/tscale.Rd index 31d45e2c1..89cb3ad03 100644 --- a/man/tscale.Rd +++ b/man/tscale.Rd @@ -23,7 +23,7 @@ the pipeline. } \examples{ # The model is in hours: -mod <- mrgsolve:::house() +mod <- mrgsolve::house() # The output is in days: mod \%>\% tscale(1/24) \%>\% mrgsim diff --git a/man/update.Rd b/man/update.Rd index 4d0ae24fc..c4ef2e9e5 100644 --- a/man/update.Rd +++ b/man/update.Rd @@ -1,25 +1,20 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/update.R -\docType{methods} \name{update} \alias{update} \alias{update,mrgmod-method} \alias{update,omegalist-method} \alias{update,sigmalist-method} \alias{update,parameter_list-method} -\alias{update,ev-method} \title{Update the model object} \usage{ -\S4method{update}{mrgmod}(object, ..., merge = TRUE, open = FALSE, - data = NULL, strict = TRUE) +\S4method{update}{mrgmod}(object, ..., merge = TRUE, open = FALSE, data = NULL, strict = TRUE) \S4method{update}{omegalist}(object, y, ...) \S4method{update}{sigmalist}(object, y, ...) \S4method{update}{parameter_list}(object, .y, ...) - -\S4method{update}{ev}(object, y, ...) } \arguments{ \item{object}{a model object} @@ -78,12 +73,13 @@ Slots that can be updated: } \examples{ \dontrun{ - mod <- mrgsolve:::house() + mod <- mrgsolve::house() mod <- update(mod, end=120, delta=4, param=list(CL=19.1)) } } \seealso{ -\code{\link{update}}, \code{\link{mrgmod-class}} +\code{\link{update}}, \code{\link{mrgmod-class}}, +\code{\link{within}} } diff --git a/man/valid_data_set.Rd b/man/valid_data_set.Rd index c88833ac6..6352ae308 100644 --- a/man/valid_data_set.Rd +++ b/man/valid_data_set.Rd @@ -32,7 +32,7 @@ simulation. } \examples{ -mod <- mrgsolve:::house() +mod <- mrgsolve::house() data(exTheoph) diff --git a/man/wf_sweep.Rd b/man/wf_sweep.Rd index 5c866662d..3696541d0 100644 --- a/man/wf_sweep.Rd +++ b/man/wf_sweep.Rd @@ -28,7 +28,7 @@ This function is experimental and may change or go away at any time without notice. } \examples{ -mod <- mrgsolve:::house() \%>\% zero_re() +mod <- mrgsolve::house() \%>\% zero_re() mod \%>\% ev(amt = 100) \%>\% diff --git a/man/within.Rd b/man/within.Rd new file mode 100644 index 000000000..92f009f55 --- /dev/null +++ b/man/within.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/update.R +\name{within} +\alias{within} +\alias{within.mrgmod} +\alias{within,mrgmod-method} +\title{Update parameters, initials, and settings within a model object} +\usage{ +\method{within}{mrgmod}(data, expr, ...) +} +\arguments{ +\item{data}{an object with class mrgmod} + +\item{expr}{expressions evaluated in an environment containing various model +object components, including parameters, initial conditions, and others +(see details)} + +\item{...}{not used} +} +\description{ +The main use case for using \link{within} rather than \link{update} or \link{param} or +\link{init} is when you want to update to a new value that is calculated from +the existing value. See the example in details +} +\details{ +Other model object slots that can be updated: \code{start}, \code{end}, \code{delta}, +\code{add}, \code{rtol}, \code{atol}, \code{hmax}, \code{maxsteps}. These are include for convenience, +but we expect that most of the time these will get updated through the +update method. +} +\examples{ +mod <- mrgsolve::house() + +mod2 <- within(mod, {CL <- CL * 1.5}) + +mod$CL +mod2$CL + +} +\seealso{ +\link{update} +} diff --git a/src/datarecord.cpp b/src/datarecord.cpp index e6edccc7c..bd41f5ec3 100644 --- a/src/datarecord.cpp +++ b/src/datarecord.cpp @@ -220,6 +220,8 @@ void datarecord::steady(odeproblem* prob, reclist& thisi, double Fn, LSODA& solv void datarecord::steady_bolus(odeproblem* prob, LSODA& solver) { + prob->ss_flag = true; + dvec state_incoming; if(Ss == 2) { @@ -238,7 +240,8 @@ void datarecord::steady_bolus(odeproblem* prob, LSODA& solver) { std::vector last(prob->neq(), -1E9); double diff = 0, err = 0; bool made_it = false; - + size_t n_cmt = prob->Ss_cmt.size(); + prob->lsoda_init(); rec_ptr evon = NEWREC(Cmt, 1, Amt, Time, Rate); @@ -252,20 +255,18 @@ void datarecord::steady_bolus(odeproblem* prob, LSODA& solver) { prob->lsoda_init(); prob->advance(tfrom,tto,solver); - int ngood = 0; - for(int j=0; j < prob->neq(); ++j) { + size_t ngood = 0, j = 0; + for(size_t jj=0; jj < n_cmt; ++jj) { + j = prob->Ss_cmt[jj]; diff = fabs(prob->y(j) - last[j]); err = solver.Rtol * fabs(prob->y(j)) + solver.Atol; if(diff < err ) ++ngood; last[j] = prob->y(j); } - if(ngood == prob->neq()) { - tfrom = double(i-1)*Ii; - tto = double(i)*Ii; + if(ngood == n_cmt) { made_it = true; break; } - tfrom = tto; } if((!made_it) && warn) { @@ -281,16 +282,18 @@ void datarecord::steady_bolus(odeproblem* prob, LSODA& solver) { // and advance to tto - lagtime. double lagt = prob->alag(this->cmtn()); if(lagt > 0) { - // if(lagt >= Ii) { - // throw Rcpp::exception("ALAG(n) greater than ii on ss record.",false); - // } if(Ss==2) { throw Rcpp::exception("Ss == 2 with lag time is not currently supported.",false); } - evon->implement(prob); prob->lsoda_init(); + evon->implement(prob); if(lagt <= Ii) { - prob->advance(tfrom, (tto - lagt), solver); + tfrom = tto; + tto = tfrom + Ii - lagt; + if(tto <= tfrom) { + throw Rcpp::exception("tto <= tfrom in seady_bolus with lag time.",false); + } + prob->advance(tfrom, tto, solver); } } @@ -300,6 +303,7 @@ void datarecord::steady_bolus(odeproblem* prob, LSODA& solver) { } } prob->lsoda_init(); + prob->ss_flag = false; } @@ -315,6 +319,8 @@ void datarecord::steady_infusion(odeproblem* prob, reclist& thisi, LSODA& solver return; } + prob->ss_flag = true; + std::vector state_incoming; if(Ss == 2) { @@ -332,9 +338,10 @@ void datarecord::steady_infusion(odeproblem* prob, reclist& thisi, LSODA& solver double tfrom = 0.0; int i; - int j; + bool warn = !prob->ss_fixed; int N_SS = prob->ss_n; + size_t n_cmt = prob->Ss_cmt.size(); std::vector last(prob->neq(),-1e9); reclist offs; @@ -380,14 +387,15 @@ void datarecord::steady_infusion(odeproblem* prob, reclist& thisi, LSODA& solver tfrom = nexti; - int ngood = 0; - for(j=0; j < prob->neq(); ++j) { + size_t ngood = 0, j = 0; + for(size_t jj=0; jj < n_cmt; ++jj) { + j = prob->Ss_cmt[jj]; diff = fabs(prob->y(j) - last[j]); err = solver.Rtol * fabs(prob->y(j)) + solver.Atol; if(diff < err ) ++ngood; last[j] = prob->y(j); } - if(ngood == prob->neq()) { + if(ngood == n_cmt) { tfrom = nexti; nexti = double(i+1)*Ii; made_it = true; @@ -448,23 +456,13 @@ void datarecord::steady_infusion(odeproblem* prob, reclist& thisi, LSODA& solver first_off = duration - Ii + Time + lagt; --ninf_ss; } - // Rcpp::Rcout << "ninfss " << ninf_ss << std::endl; - // Rcpp::Rcout << "length offs " << offs.size() << std::endl; - // Rcpp::Rcout << "Started " << start << std::endl; - // Rcpp::Rcout << "Ended " << end << std::endl; - // Rcpp::Rcout << "infusions " << prob->rate_count(1) << std::endl; - // Rcpp::Rcout << "Steady: " << prob->y(1) << std::endl; - // for(int k=0; k < ninf_ss; ++k) { - // double offtime = first_off + double(k)*double(Ii); - // rec_ptr evoff = NEWREC(Cmt, 9, Amt, offtime, Rate, -300, Id); - // thisi.push_back(evoff); - // } for(size_t k = 0; k < offs.size(); ++k) { offs.at(k)->time(first_off + double(k)*double(Ii)); thisi.push_back(offs.at(k)); } std::sort(thisi.begin(),thisi.end(),CompRec()); prob->lsoda_init(); + prob->ss_flag = false; } void datarecord::steady_zero(odeproblem* prob, LSODA& solver) { @@ -474,11 +472,14 @@ void datarecord::steady_zero(odeproblem* prob, LSODA& solver) { return; } + prob->ss_flag = true; + double tfrom = 0.0; double tto = 0.0; double a1 = 0, a2 = 0, t1 = 0, t2 = 0; bool warn = !prob->ss_fixed; int N_SS = prob->ss_n; + size_t n_cmt = prob->Ss_cmt.size(); std::vector last(prob->neq(),-1e9); bool made_it = false; @@ -493,14 +494,15 @@ void datarecord::steady_zero(odeproblem* prob, LSODA& solver) { tto = tfrom + duration; prob->advance(tfrom,tto,solver); tfrom = tto; - int ngood = 0; - for(int j=0; j < prob->neq(); ++j) { + size_t ngood = 0, j = 0; + for(size_t jj=0; jj < n_cmt; ++jj) { + j = prob->Ss_cmt[jj]; diff = fabs(prob->y(j) - last[j]); err = solver.Rtol*fabs(prob->y(j)) + solver.Atol; if(diff < err) ++ngood; last[j] = prob->y(j); } - if(ngood == prob->neq()) { + if(ngood == n_cmt) { made_it = true; break; } @@ -528,6 +530,7 @@ void datarecord::steady_zero(odeproblem* prob, LSODA& solver) { prob->rate_reset(); prob->lsoda_init(); this->unarm(); + prob->ss_flag = false; } void datarecord::schedule(std::vector& thisi, double maxtime, diff --git a/src/devtran.cpp b/src/devtran.cpp index 0b73e2519..bed7d7846 100644 --- a/src/devtran.cpp +++ b/src/devtran.cpp @@ -16,24 +16,11 @@ // along with mrgsolve. If not, see . -/** - * @mainpage - * - * Documentation for `mrgsolve` `C++` code. - * - * To see functions available in the `mrgx` plugin, see the - * `mrgx` module here. - * - * - */ - /** * @file devtran.cpp * */ -// #include -// #include #include #include "mrgsolve.h" #include "odeproblem.h" @@ -50,17 +37,19 @@ /** Perform a simulation run. * * @param parin list of data and options for the simulation - * @param inpar numeric parameter values + * @param inpar parameter values * @param parnames parameter names * @param init numeric initial values * @param cmtnames compartment names * @param capture indices in capture vector to actually get * @param funs list of pointer addresses to model functions generated by - * getNativeSymbolInfo() + * getNativeSymbolInfo() * @param data the main data set * @param idata the idata data aset * @param OMEGA between-ID normal random effects * @param SIGMA within-ID normal random effects + * @param envir the model environment + * * @return list containing matrix of simulated data and a character vector of * tran names that may have been carried into the output * @@ -139,6 +128,7 @@ Rcpp::List DEVTRAN(const Rcpp::List parin, const unsigned int neq = prob.neq(); LSODA solver(neq, parin); + recstack a(NID); unsigned int obscount = 0; @@ -401,7 +391,7 @@ Rcpp::List DEVTRAN(const Rcpp::List parin, prob.set_d(a[i][0]); prob.init_call(tfrom); - + for(size_t j=0; j < a[i].size(); ++j) { if(crow == NN) continue; diff --git a/src/mrgsolve_init.cpp b/src/mrgsolve_init.cpp index 714173f99..239f5761a 100644 --- a/src/mrgsolve_init.cpp +++ b/src/mrgsolve_init.cpp @@ -15,6 +15,28 @@ // You should have received a copy of the GNU General Public License // along with mrgsolve. If not, see . +/** + * @mainpage + * + * Documentation for `mrgsolve` `C++` code. + * + * @section interface User Interface + * + * To see functions available in the `mrgx` plugin, see the + * `mrgx` module here. + * + * See the databox class for documentation + * around the self object. + * + * @section technical Technical Documentation + * + * The main simulation function is DEVTRAN(). + * + * + */ + + + #include "RcppInclude.h" #include "mrgsolv.h" diff --git a/src/odeproblem.cpp b/src/odeproblem.cpp index fc10f87e9..c3d8300d4 100644 --- a/src/odeproblem.cpp +++ b/src/odeproblem.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013 - 2019 Metrum Research Group +// Copyright (C) 2013 - 2020 Metrum Research Group // // This file is part of mrgsolve. // @@ -86,6 +86,7 @@ odeproblem::odeproblem(Rcpp::NumericVector param, Do_Init_Calc = true; ss_fixed = false; ss_n = 500; + ss_flag = false; pred.assign(5,0.0); @@ -101,7 +102,6 @@ odeproblem::odeproblem(Rcpp::NumericVector param, simeta = mrgsolve::resim(&dosimeta,reinterpret_cast(this)); simeps = mrgsolve::resim(&dosimeps,reinterpret_cast(this)); - } double odeproblem::fbio(unsigned int pos) { @@ -170,12 +170,15 @@ void main_derivs(double t, double *y, double *ydot, odeproblem *data) { } void odeproblem::call_derivs(double *t, double *y, double *ydot) { - Derivs(t,y,ydot,Init_value,Param); + Derivs(t,y,ydot,Init_value,Param,ss_flag); for(int i = 0; i < Neq; ++i) { ydot[i] = (ydot[i] + R0[i])*On[i]; } } +void odeproblem::init_derivs(double time) { + this->call_derivs(&time,&Y[0],&Yout[1]); +} void odeproblem::set_d(rec_ptr this_rec) { d.time = this_rec->time(); @@ -336,11 +339,12 @@ void odeproblem::advance(double tfrom, double tto, LSODA& solver) { } solver.lsoda_update(main_derivs,Neq,Y,Yout,&tfrom,tto,&Istate,this); + if(Istate < 0) { negative_istate(Istate, solver.Maxsteps, solver.Rtol, solver.Atol); } - //this->call_derivs(&Neq, &tto, Y, Ydot); + this->init_derivs(tto); } void odeproblem::advan2(const double& tfrom, const double& tto) { @@ -524,7 +528,12 @@ void odeproblem::advan4(const double& tfrom, const double& tto) { } } - +/** + * Calculate PK model polyexponentials. + * + * + * + */ double PolyExp(const double& x, const double& dose, const double& rate, @@ -640,6 +649,7 @@ void odeproblem::copy_parin(const Rcpp::List& parin) { Rtol = Rcpp::as(parin["rtol"]); Atol = Rcpp::as(parin["atol"]); Do_Init_Calc = Rcpp::as(parin["do_init_calc"]); + Ss_cmt = Rcpp::as>(parin["ss_cmt"]); } void odeproblem::copy_funs(const Rcpp::List& funs) { @@ -668,8 +678,8 @@ void odeproblem::advan(int x) { /** * Call the $MAIN function from a model object. * - * @param lparam model parameters - * @param linit model initial contitions + * @param lparam model parameter value + * @param linit model initial contition values * @param Neta number of rows in OMEGA * @param Neps number of rows in SIGMA * @param capture vector of capture names diff --git a/tests/testthat/test-as_list_mrgmod.R b/tests/testthat/test-as_list_mrgmod.R index 104fedc27..4f22bbec6 100644 --- a/tests/testthat/test-as_list_mrgmod.R +++ b/tests/testthat/test-as_list_mrgmod.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -26,7 +26,7 @@ context("test-as_list_mrgmod") options(mrgsolve_mread_quiet=TRUE) test_that("check items in as.list output", { - x <- as.list(mrgsolve:::house()) + x <- as.list(mrgsolve::house()) x_names <- names(x) expect_true("start" %in% x_names) expect_true("end" %in% x_names) diff --git a/tests/testthat/test-carry-out.R b/tests/testthat/test-carry-out.R index 98f74932c..330922b3c 100644 --- a/tests/testthat/test-carry-out.R +++ b/tests/testthat/test-carry-out.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -23,7 +23,7 @@ options("mrgsolve_mread_quiet"=TRUE) context("test-carry-out") -mod <- mrgsolve:::house() %>% update(end=5, delta=1) %>% Req(CP) +mod <- mrgsolve::house() %>% update(end=5, delta=1) %>% Req(CP) ex <- rep(0,7) diff --git a/tests/testthat/test-carry_out.R b/tests/testthat/test-carry_out.R index 1bf40e7f3..30ce41c6d 100644 --- a/tests/testthat/test-carry_out.R +++ b/tests/testthat/test-carry_out.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -23,7 +23,7 @@ options("mrgsolve_mread_quiet"=TRUE) context("test-carry_out") -mod <- mrgsolve:::house() +mod <- mrgsolve::house() data(exTheoph) @@ -31,7 +31,7 @@ exTheoph <- mutate(exTheoph, ROW=1:nrow(exTheoph)) %>% filter(ID <=10) -mod <- mrgsolve:::house() +mod <- mrgsolve::house() data <- expand.idata(ID=1:5,amt=c(200,300)) %>% diff --git a/tests/testthat/test-data_set.R b/tests/testthat/test-data_set.R index a0079b5a3..eee61976b 100644 --- a/tests/testthat/test-data_set.R +++ b/tests/testthat/test-data_set.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -21,7 +21,7 @@ library(dplyr) Sys.setenv(R_TESTS="") options("mrgsolve_mread_quiet"=TRUE) -mod <- mrgsolve:::house() %>% update(end=240) +mod <- mrgsolve::house() %>% update(end=240) context("test-data_set") @@ -78,7 +78,7 @@ test_that("time is required", { expect_error(mod %>% data_set(df) %>% mrgsim) }) -mod <- mrgsolve:::house() +mod <- mrgsolve::house() data(exTheoph) @@ -95,7 +95,7 @@ test_that("Properly sorted records produces no error", { }) test_that("Data set column order gives same answer", { - mod <- mrgsolve:::house() %>% omat(dmat(1,1,1,1)) + mod <- mrgsolve::house() %>% omat(dmat(1,1,1,1)) data(extran3) set.seed(9923403) extran3 <- extran3 %>% mutate(a=-10, Z = -11, M = -22, h = -33) diff --git a/tests/testthat/test-deslist.R b/tests/testthat/test-deslist.R index 5247dfc71..d055fd078 100644 --- a/tests/testthat/test-deslist.R +++ b/tests/testthat/test-deslist.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -37,7 +37,7 @@ test_that("as_deslist", { ##' ID 33 expect_equal(max(stime(des[[2]])),1) - mod <- mrgsolve:::house() + mod <- mrgsolve::house() out <- mod %>% diff --git a/tests/testthat/test-dplyr-generics.R b/tests/testthat/test-dplyr-generics.R index 29f6210da..d12b28679 100644 --- a/tests/testthat/test-dplyr-generics.R +++ b/tests/testthat/test-dplyr-generics.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -25,7 +25,7 @@ context("test-dplyr-generics") project <- file.path(system.file(package="mrgsolve"), "models") -out <- mrgsolve:::house() %>% ev(amt=100) %>% mrgsim(end=122) +out <- mrgsolve::house() %>% ev(amt=100) %>% mrgsim(end=122) test_that("Pipe to tibble", { expect_is(out %>% as.tbl, "tbl_df") @@ -82,3 +82,9 @@ test_that("mutate_mrgsims", { expect_is(x, "mrgsims") expect_true(all(x$foo == chk)) }) + +test_that("select_mrgsims", { + x <- select_sims(out, RESP) + expect_is(x, "mrgsims") + expect_identical(names(x), c("ID", "time", "RESP")) +}) diff --git a/tests/testthat/test-evid4.R b/tests/testthat/test-evid4.R index 13c3ceb57..14108728c 100644 --- a/tests/testthat/test-evid4.R +++ b/tests/testthat/test-evid4.R @@ -24,7 +24,7 @@ options("mrgsolve_mread_quiet"=TRUE) # Issue 299 context("test-evid4") -mod <- mrgsolve:::house() +mod <- mrgsolve::house() test_that("evid4 bolus dosing is the same as evid1", { e1 <- ev(amt = 100, ii = 24, addl = 3) diff --git a/tests/testthat/test-funset.R b/tests/testthat/test-funset.R index 531d861c1..417df9fcd 100644 --- a/tests/testthat/test-funset.R +++ b/tests/testthat/test-funset.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -24,7 +24,7 @@ options("mrgsolve_mread_quiet"=TRUE) context("test-funset") test_that("funset", { - mod <- mrgsolve:::house() + mod <- mrgsolve::house() a <- mrgsolve:::funset(mod) expect_identical(names(a), c("symbols", "shlib")) expect_true(a$shlib$compiled) diff --git a/tests/testthat/test-idata_set.R b/tests/testthat/test-idata_set.R index 981f3826a..7a15b2539 100644 --- a/tests/testthat/test-idata_set.R +++ b/tests/testthat/test-idata_set.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -21,7 +21,7 @@ library(dplyr) Sys.setenv(R_TESTS="") options("mrgsolve_mread_quiet"=TRUE) -mod <- mrgsolve:::house() %>% update(end=240) +mod <- mrgsolve::house() %>% update(end=240) context("test-data_set") diff --git a/tests/testthat/test-infusion.R b/tests/testthat/test-infusion.R index ec2e5b5a9..ca609ed8c 100644 --- a/tests/testthat/test-infusion.R +++ b/tests/testthat/test-infusion.R @@ -22,7 +22,7 @@ Sys.setenv(R_TESTS="") options("mrgsolve_mread_quiet"=TRUE) -mod <- mrgsolve:::house() +mod <- mrgsolve::house() context("test-infusion") @@ -97,7 +97,7 @@ test_that("Infusion with duration a multiple of ii", { expect_is(out, "mrgsims") }) -mod <- mrgsolve:::house() +mod <- mrgsolve::house() test_that("Infusion with no obs overlap", { mod <- mod %>% ev(amt=6, rate=5) @@ -124,7 +124,7 @@ test_that("Infusion executes with ss flag and ii==dur", { test_that("ss infusion issue-249", { cl <- 1.3 r <- 25 - mod <- mrgsolve:::house(end=1,outvars="CP") %>% param(CL = cl) + mod <- mrgsolve::house(end=1,outvars="CP") %>% param(CL = cl) ss <- ev(amt = 0, rate = r, ii =10,ss=1) out <- mrgsim(mod,ss) expect_equal(out$CP[2],r/cl) diff --git a/tests/testthat/test-init.R b/tests/testthat/test-init.R index 069d30ce5..aa009b0b0 100644 --- a/tests/testthat/test-init.R +++ b/tests/testthat/test-init.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -33,7 +33,7 @@ test_that("inits are constructed", { }) test_that("inits are shown", { - mod <- mrgsolve:::house() + mod <- mrgsolve::house() x <- capture.output(init(mod)) expect_match(x[2], "Model initial conditions") }) diff --git a/tests/testthat/test-inventory-too.R b/tests/testthat/test-inventory-too.R index 9208200ec..559f58bf2 100644 --- a/tests/testthat/test-inventory-too.R +++ b/tests/testthat/test-inventory-too.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -26,7 +26,7 @@ context("test-inventory-too") test_that("inventory conditions", { - mod <- mrgsolve:::house() + mod <- mrgsolve::house() data <- expand.ev(amt=100,CL=1, SEX=0) idata <- data.frame(ID=1, CL=1, SEX=0) diff --git a/tests/testthat/test-iv-po.R b/tests/testthat/test-iv-po.R index 96278d60a..c3377f1b0 100644 --- a/tests/testthat/test-iv-po.R +++ b/tests/testthat/test-iv-po.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -35,7 +35,7 @@ iv <- function(dose,par,time) { } context("test-iv-po") -mod <- mrgsolve:::house() %>% +mod <- mrgsolve::house() %>% update(atol = 1E-20, rtol = 1E-12, digits = 8) out <- mrgsim(mod) diff --git a/tests/testthat/test-knobs.R b/tests/testthat/test-knobs.R index 2a4c51728..42508ab52 100644 --- a/tests/testthat/test-knobs.R +++ b/tests/testthat/test-knobs.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -26,7 +26,7 @@ project <- file.path(system.file(package="mrgsolve"), "models") context("test-knobs") -mod <- mrgsolve:::house(atol=1E-20,rtol=1E-12,digits=8) +mod <- mrgsolve::house(atol=1E-20,rtol=1E-12,digits=8) out <- knobs(mod %>% init(GUT=0), CL=c(1,2,3), foo=c(2,3,4),fooo=1, amt=c(100,200), cmt=1) dfout <- as.data.frame(out) diff --git a/tests/testthat/test-modlib.R b/tests/testthat/test-modlib.R index 02e20ddc4..317efcb9f 100644 --- a/tests/testthat/test-modlib.R +++ b/tests/testthat/test-modlib.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -24,7 +24,7 @@ options("mrgsolve_mread_quiet"=TRUE) context("test-modlib") test_that("code extraction", { - mod <- mrgsolve:::house() + mod <- mrgsolve::house() x <- mrgsolve:::code(mod) expect_is(x, "character") expect_error(mrgsolve:::code(letters)) diff --git a/tests/testthat/test-mrgindata.R b/tests/testthat/test-mrgindata.R index c2238541c..1e9373bea 100644 --- a/tests/testthat/test-mrgindata.R +++ b/tests/testthat/test-mrgindata.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -26,7 +26,7 @@ context("test-mrgindata") end <- 60 delta <- 3 n <- length(seq(0,end,delta)) -mod <- mrgsolve:::house() %>% update(end=end, delta=delta) +mod <- mrgsolve::house() %>% update(end=end, delta=delta) data(extran3) test_that("valid_data_set warns for character columns", { diff --git a/tests/testthat/test-mrgmod.R b/tests/testthat/test-mrgmod.R index b32a8d2c4..ca298c89f 100644 --- a/tests/testthat/test-mrgmod.R +++ b/tests/testthat/test-mrgmod.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -24,20 +24,24 @@ options("mrgsolve_mread_quiet"=TRUE) context("test-mrgmod") -mod <- mrgsolve:::house() - +mod <- mrgsolve::house() test_that("methods", { expect_equal(mod$CL,1) expect_equal(mod$VC,20) + expect_equal(mod$RESP,50) + expect_equal(mod[["RESP"]],50) + expect_equal(mod$end,120) + expect_equal(mod[["end"]],mod@end) expect_error(mod$kylebaron) - expect_error(mod[["kylebaron"]]) + expect_error(mod[["kylebaron"]],regexp = "not found or not extractable") expect_is(as.list(mod), "list") expect_output(summary(mod), "Model: housemodel") expect_true(mrgsolve:::valid.mrgmod(mod)) - expect_true(all.equal(mod, mrgsolve:::house())) - l <- mod[c("CL", "VC")] - expect_identical(l, list(CL = mod$CL, VC = mod$VC)) + expect_true(all.equal(mod, mrgsolve::house())) + l <- mod[c("CL", "VC", "CENT", "end")] + expect_identical(l, list(CL = mod$CL, VC = mod$VC, CENT = mod$CENT, end = mod$end)) + expect_error(mod[c("CL", "Kyle")],regexp = "not found or not extractable") x <- capture.output(see(mod)) expect_true(grepl("Model file", x[2])) expect_true(grepl("housemodel\\.cpp", x[2])) diff --git a/tests/testthat/test-mrgsim.R b/tests/testthat/test-mrgsim.R index 487fd355d..fe714857c 100644 --- a/tests/testthat/test-mrgsim.R +++ b/tests/testthat/test-mrgsim.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -22,7 +22,7 @@ library(dplyr) Sys.setenv(R_TESTS="") options("mrgsolve_mread_quiet"=TRUE) -mod <- mrgsolve:::house() +mod <- mrgsolve::house() mod <- update(mod, end = 84, atol = 1E-30) ## one individual diff --git a/tests/testthat/test-mrgsim_q.R b/tests/testthat/test-mrgsim_q.R index c9d3b8c78..378d99ed5 100644 --- a/tests/testthat/test-mrgsim_q.R +++ b/tests/testthat/test-mrgsim_q.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -21,7 +21,7 @@ library(dplyr) Sys.setenv(R_TESTS="") options("mrgsolve_mread_quiet"=TRUE) -mod <- mrgsolve:::house() %>% update(end=240) +mod <- mrgsolve::house() %>% update(end=240) cap <- as.list(mod)$capture context("test-mrgsim_q") diff --git a/tests/testthat/test-mrgsims.R b/tests/testthat/test-mrgsims.R index 0f86c8f2b..ef3236b67 100644 --- a/tests/testthat/test-mrgsims.R +++ b/tests/testthat/test-mrgsims.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -25,9 +25,16 @@ options("mrgsolve_mread_quiet"=TRUE) context("test-mrgsims") test_that("mrgsims class", { - mod <- mrgsolve:::house() + mod <- mrgsolve::house() out <- mrgsim(mod) expect_true(is.mrgsims(out)) expect_is(as.list(out), "mrgsims_list") }) +test_that("plot from character", { + out <- mrgsolve::house() %>% mrgsim() + pl1 <- out %>% plot(" CENT DV, CP") + pl2 <- out %>% plot(CENT+DV+CP~time) + expect_equal(pl1,pl2) +}) + diff --git a/tests/testthat/test-obsonly-obsaug.R b/tests/testthat/test-obsonly-obsaug.R index e60b0db17..035d913d3 100644 --- a/tests/testthat/test-obsonly-obsaug.R +++ b/tests/testthat/test-obsonly-obsaug.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -23,7 +23,7 @@ options("mrgsolve_mread_quiet"=TRUE) context("test-obsonly-obsaug") -mod <- mrgsolve:::house(add=c(8.123, 33.3333)) +mod <- mrgsolve::house(add=c(8.123, 33.3333)) data(exTheoph) diff --git a/tests/testthat/test-param.R b/tests/testthat/test-param.R index ecaab2b00..da185be95 100644 --- a/tests/testthat/test-param.R +++ b/tests/testthat/test-param.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -21,7 +21,7 @@ library(dplyr) Sys.setenv(R_TESTS="") options("mrgsolve_mread_quiet"=TRUE) -mod <- mrgsolve:::house() +mod <- mrgsolve::house() test_that("params are constructed", { x <- param(A = 1, B = 2) @@ -41,7 +41,7 @@ test_that("params are accessed", { }) test_that("params are updated", { - mod <- mrgsolve:::house() + mod <- mrgsolve::house() mod2 <- param(mod, CL = 55, VC = 111) expect_equal(mod2$CL,55) expect_equal(mod2$VC,111) @@ -61,7 +61,7 @@ test_that("params are updated", { }) test_that("params are shown", { - mod <- mrgsolve:::house() + mod <- mrgsolve::house() x <- capture.output(param(mod)) expect_match(x[2], "Model parameters") }) diff --git a/tests/testthat/test-realize.R b/tests/testthat/test-realize.R index 0a3bcbfc2..fc7c5ba9f 100644 --- a/tests/testthat/test-realize.R +++ b/tests/testthat/test-realize.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -24,7 +24,7 @@ options("mrgsolve_mread_quiet"=TRUE) context("test-ev") -mod <- mrgsolve:::house() +mod <- mrgsolve::house() test_that("dosing without ss", { e <- ev(amt = 100, ii = 24, addl = 3) diff --git a/tests/testthat/test-records.R b/tests/testthat/test-records.R index e5d626733..1f174df9e 100644 --- a/tests/testthat/test-records.R +++ b/tests/testthat/test-records.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -23,7 +23,7 @@ options("mrgsolve_mread_quiet"=TRUE) context("test-records") -mod <- mrgsolve:::house() %>% Req(CENT,RESP) +mod <- mrgsolve::house() %>% Req(CENT,RESP) data(exidata) diff --git a/tests/testthat/test-recsort.R b/tests/testthat/test-recsort.R index dbf2580d6..1027f890b 100644 --- a/tests/testthat/test-recsort.R +++ b/tests/testthat/test-recsort.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -21,7 +21,7 @@ library(dplyr) Sys.setenv(R_TESTS="") options("mrgsolve_mread_quiet"=TRUE) -mod <- mrgsolve:::house() %>% update(end = -1) %>% param(CL = 0, KA = 0) +mod <- mrgsolve::house() %>% update(end = -1) %>% param(CL = 0, KA = 0) mod <- carry_out(mod, evid) # record sorting flag. Default value is 1. Possible values are 1,2,3,4: diff --git a/tests/testthat/test-rename.R b/tests/testthat/test-rename.R index 7fff12fa4..bd1a80aab 100644 --- a/tests/testthat/test-rename.R +++ b/tests/testthat/test-rename.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -23,7 +23,7 @@ options("mrgsolve_mread_quiet"=TRUE) context("test-rename") -mod <- mrgsolve:::house() %>% Req(CENT,RESP) +mod <- mrgsolve::house() %>% Req(CENT,RESP) data(exTheoph) df <- exTheoph %>% mutate(KYLE=7) diff --git a/tests/testthat/test-rng.R b/tests/testthat/test-rng.R index 28cc262ac..f435b5561 100644 --- a/tests/testthat/test-rng.R +++ b/tests/testthat/test-rng.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -23,7 +23,7 @@ options("mrgsolve_mread_quiet"=TRUE) context("test-rng") -mod <- mrgsolve:::house(omega=diag(c(1,1,1,1))) +mod <- mrgsolve::house(omega=diag(c(1,1,1,1))) ident <- function(x,y,...) { identical(x,y) diff --git a/tests/testthat/test-ss.R b/tests/testthat/test-ss.R index 518c1c2e4..31212083d 100644 --- a/tests/testthat/test-ss.R +++ b/tests/testthat/test-ss.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -25,7 +25,7 @@ options("mrgsolve_mread_quiet"=TRUE) context("test-ss") test_that("ss_n and ss_fixed issue-533", { - mod <- mrgsolve:::house(end = 72,delta=4) %>% param(VC = 50) + mod <- mrgsolve::house(end = 72,delta=4) %>% param(VC = 50) dose <- ev(amt = 100, ii = 24, ss=1, cmt=2, addl=2, ID=123) out <- mrgsim_e(mod,dose,recsort=3) expect_is(out,"mrgsims") diff --git a/tests/testthat/test-tad.R b/tests/testthat/test-tad.R index a3dc062b5..9ba4eb2b1 100644 --- a/tests/testthat/test-tad.R +++ b/tests/testthat/test-tad.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -24,7 +24,7 @@ options("mrgsolve_mread_quiet"=TRUE) context("test-tad") -mod <- mrgsolve:::house(end=5, delta=1) %>% Req() +mod <- mrgsolve::house(end=5, delta=1) %>% Req() test_that("tad", { out <- mrgsim(mod) diff --git a/tests/testthat/test-update.R b/tests/testthat/test-update.R index 368a2ca31..3d3088cf5 100644 --- a/tests/testthat/test-update.R +++ b/tests/testthat/test-update.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -21,7 +21,7 @@ library(dplyr) Sys.setenv(R_TESTS="") options("mrgsolve_mread_quiet"=TRUE) -mod <- mrgsolve:::house() %>% update(atol = 1E-20, rtol = 1E-12, digits = 8) +mod <- mrgsolve::house() %>% update(atol = 1E-20, rtol = 1E-12, digits = 8) mod1 <- update(mod %>% param(CL=12, VC=220), delta=33, end=222) mod2 <- update(mod, param=list(CL=12, VC=220), delta=33, end=222) x <- sort(runif(100, 0,300)) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 0d2d038f4..b2ff64cc3 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group, LLC +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -62,7 +62,7 @@ test_that("combine_list", { -mod <- mrgsolve:::house() +mod <- mrgsolve::house() out <- mrgsim(mod) test_that("Corecing simulated output to data.frame", { diff --git a/tests/testthat/test-workflow.R b/tests/testthat/test-workflow.R index 40b918871..4c667126b 100644 --- a/tests/testthat/test-workflow.R +++ b/tests/testthat/test-workflow.R @@ -1,4 +1,4 @@ -# Copyright (C) 2013 - 2019 Metrum Research Group +# Copyright (C) 2013 - 2020 Metrum Research Group # # This file is part of mrgsolve. # @@ -24,7 +24,7 @@ options("mrgsolve_mread_quiet"=FALSE) context("test-workflow") test_that("workflow", { - mod <- mrgsolve:::house() + mod <- mrgsolve::house() e <- ev(amt = 100) out <- mod %>% ev(e) %>% wf_sweep(CL) expect_is(out, "mrgsims")