Skip to content

Commit

Permalink
Merge pull request #392 from metrumresearchgroup/dev
Browse files Browse the repository at this point in the history
Implementation of $PRED
  • Loading branch information
kylebaron authored Sep 1, 2018
2 parents f650c79 + a719fbc commit 73018a1
Show file tree
Hide file tree
Showing 53 changed files with 679 additions and 225 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: r
language: R
sudo: false
dist: trusty
cache: packages
Expand All @@ -10,10 +10,11 @@ binary_packages:
- dplyr

env:
- R_KEEP_PKG_SOURCE=yes
- _R_S3_METHOD_LOOKUP_BASEENV_AFTER_GLOBALENV_=true
- _R_S3_METHOD_LOOKUP_USE_TOPENV_AS_DEFENV_=true
- _R_CHECK_FORCE_SUGGESTS=0
global:
- R_KEEP_PKG_SOURCE=yes
- _R_S3_METHOD_LOOKUP_BASEENV_AFTER_GLOBALENV_=true
- _R_S3_METHOD_LOOKUP_USE_TOPENV_AS_DEFENV_=true
- _R_CHECK_FORCE_SUGGESTS=0

pandoc: false

Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mrgsolve
Type: Package
Version: 0.8.12
Version: 0.8.12.9000
Title: Simulate from ODE-Based Population PK/PD and Systems Pharmacology
Models
Authors@R: c(
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ CHKDIR=Rchecks
gut_check:
Rscript "inst/maintenance/gut_check.R"

everything:
make all
make pkgdown

pkgdown:
Rscript "inst/maintenance/pkgdown.R"
cp -r DOCS/ ../../mrgsolve/docs/
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ S3method(handle_spec_block,specOMEGA)
S3method(handle_spec_block,specPARAM)
S3method(handle_spec_block,specPKMODEL)
S3method(handle_spec_block,specPLUGIN)
S3method(handle_spec_block,specPRED)
S3method(handle_spec_block,specSET)
S3method(handle_spec_block,specSIGMA)
S3method(handle_spec_block,specTABLE)
Expand Down Expand Up @@ -114,6 +115,7 @@ export(mrgsim_ei)
export(mrgsim_i)
export(mutate_sims)
export(mvgauss)
export(numerics_only)
export(obsaug)
export(obsonly)
export(omat)
Expand Down
20 changes: 20 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# mrgsolve 0.8.12.9000

## New functions
- Added `numerics_only` function to drop non-numeric columns from
the input data set after optionally converting logical columns
to integer

## New features
- Added `$PRED` block for models that don't utilize any compartments
- Added `pred1` to the `modlib`

## New behavior
- `time/TIME` is no longer required in a data set when `$PRED` is in use
- `cmt/CMT` is no longer required in a data set; a default value of 0 will
be assigned in case it is missing and an error will continue to be generated
when dosing into an invalid compartment (0 is always an invalid index
for dosing compartment)

# mrgsolve 0.8.12
- Minor changes to namespace for CRAN
# mrgsove 0.8.11
- Internal release
- Removed the function `s` and replaced with `s_`; this was not a problem
Expand Down
2 changes: 1 addition & 1 deletion R/Aaaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ block_list <- c("ENV", "PROB", "PARAM", "INIT",
"FIXED", "CMTN", "THETA", "NMXML", "VCMT",
"PKMODEL", "PLUGIN", "INCLUDE", "NAMESPACE",
"OMEGA", "SIGMA", "SET","GLOBAL", "CAPTURE",
"PREAMBLE")
"PREAMBLE", "PRED")

Reserved_cvar <- c("SOLVERTIME","table","ETA","EPS",
"ID", "TIME", "EVID","simeps", "self", "simeta",
Expand Down
17 changes: 14 additions & 3 deletions R/annot.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,24 @@ parse_annot_line <- function(x, novalue=FALSE, noname=FALSE,context="not given")
list(name=a[1],value=a[2],unit=units,options=options,descr=b)
}

##' Extract model details.
##' Extract model details
##'
##' @param x a model object
##' @param complete logical; if \code{TRUE}, un-annotated parameters and compartments will be added to the output
##' @param values logical; if \code{TRUE}, a values column will be added to the output
##' @param complete logical; if \code{TRUE}, un-annotated parameters and
##' compartments will be added to the output
##' @param values logical; if \code{TRUE}, a values column will be added to
##' the output
##' @param ... not used
##'
##' @details
##' This function is not exported. You will have to call it
##' with \code{mrgsolve:::details()}.
##'
##' @examples
##' mod <- mrgsolve:::house()
##'
##' mrgsolve:::details(mod)
##'
details <- function(x,complete=FALSE,values=FALSE,...) {

stopifnot(is.mrgmod(x))
Expand Down
1 change: 1 addition & 0 deletions R/class_ev.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ select.ev <- function(.data, ...) {
.data@data <- as.data.frame(dplyr::select(.data@data,...))
.data
}

##' @rdname ev_dplyr
##' @export
filter_.ev <- function(.data, ...) {
Expand Down
12 changes: 9 additions & 3 deletions R/class_mrgmod.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ check_names <- function(x,par,cmt) {
dups <- any(duplicated(x))
us <- any(charthere(x,"_"))
res <- any(is.element(x,Reserved))
alph <- !all(grepl("^[[:alpha:]]",x))

ans <- character(0)

Expand All @@ -42,9 +43,14 @@ check_names <- function(x,par,cmt) {
}
## Look for names in the Reserved word list
if(res) {
tmp <- paste(x[is.element(x,Reserved)],collapse=" ")
tmp <- paste0(x[is.element(x,Reserved)],collapse=" ")
ans <- c(ans,paste0("Reserved words in model names: ",tmp))
}
## names that don't start with alpha
if(alph) {
tmp <- paste0(x[!grepl("^[[:alpha:]]", x)], collapse = " ")
ans <- c(ans, paste0("Names without leading alpha character: ", tmp))
}
## Scan for names with underscores
## Leading underscores are not allowed
## Also, look for any name that conflicts with
Expand Down Expand Up @@ -138,12 +144,12 @@ valid.mrgmod <- function(object) {
tags <- unlist(names(object), use.names=FALSE)
x <- check_names(tags,Pars(object),Cmt(object))
x1 <- length(x)==0
x2 <- object@advan %in% c(1,2,3,4,13)
x2 <- object@advan %in% c(0,1,2,3,4,13)
fun <- valid_funs(object@funs)
cool <- x1 & x2 & fun[[1]]
if(cool) return(TRUE)
x <- c(x,fun[[2]])
if(!x2) x <- c(x,"Advan must be 1, 2, 3, 4, or 13")
if(!x2) x <- c(x,"advan must be 1, 2, 3, 4, or 13")
return(x)
}

Expand Down
28 changes: 18 additions & 10 deletions R/data_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

##' Select and modify a data set for simulation
##'
##'
##' @param x model object
##' @param data data set
##' @param .subset an unquoted expression passed to
Expand Down Expand Up @@ -46,23 +45,32 @@
##'
##' Input data set may include the following columns related to
##' PK dosing events: \code{time}, \code{cmt}, \code{amt}, \code{rate},
##' \code{ii}, \code{addl}, \code{ss}. \code{time} and \code{cmt}
##' (and \code{ID}) are required columns in the input data set.
##' \code{ii}, \code{addl}, \code{ss}. Along with \code{ID}, \code{time}
##' is a required column in the input data set unless \code{$PRED} is in
##' use. Upper case PK dosing column names including
##' \code{TIME}, \code{CMT}, \code{AMT}, \code{RATE}, \code{II},
##' \code{ADDL}, \code{SS} are also recognized. However, an
##' error will be generated if a mix of upper case and lower
##' case columns in this family are found.
##'
##' \code{time} is the observation or event time, \code{cmt}
##' is the compartment number (see \code{\link{init}}), \code{amt}
##' is the dosing amount, \code{rate} is the infusion rate,
##' \code{ii} is the dosing interval, \code{addl} specifies
##' additional doses to administer, and \code{ss} is a flag
##' for steady state dosing. These column names operate
##' similarly to other non-linear mixed effects modeling
##' software. Upper case PK dosing column names including
##' \code{TIME}, \code{CMT}, \code{AMT}, \code{RATE}, \code{II},
##' \code{ADDL}, \code{SS} are also recognized. However, an
##' error will be generated if a mix of upper case and lower
##' case columns are found.
##'
##' software.
##'
##' An error will be generate when mrgsolve detects that the data set
##' is not sorted by \code{time} within an individual. Also, an error
##' will be generated in case mrgsolve finds negative values for
##' \code{time}, unless \code{$PRED} is in use.
##'
##' Only numeric data can be brought in to the problem.
##' Any non-numeric data columns will be dropped with warning.
##' Any non-numeric data columns will be dropped with warning.
##' See \code{\link{numerics_only}}, which is used
##' to prepare the data set.
##'
##' See \code{\link{exdatasets}} for different example data sets.
##'
Expand Down
25 changes: 17 additions & 8 deletions R/events.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
##' ways.
##'
##' @param x a model object
##' @param time event time
##' @param amt dose amount
##' @param evid event ID
##' @param cmt compartment

##' @param ID subject ID
##' @param time event time
##' @param replicate logical; if \code{TRUE}, events will be replicated for
##' each individual in \code{ID}
##' @param cmt compartment

##' @param until the expected maximum \bold{observation} time for this regimen
##' @param realize_addl if \code{FALSE} (default), no change to \code{addl}
##' doses. If \code{TRUE}, \code{addl} doses are made explicit with
Expand All @@ -43,11 +46,14 @@
##'
##' @details
##' \itemize{
##' \item Required input for creating events objects include
##' \code{time} and \code{cmt}
##' \item Required items in events objects include
##' \code{time}, \code{amt}, \code{evid} and \code{cmt}.
##' \item If not supplied, \code{evid} is assumed to be 1.
##' \item If not supplied, \code{cmt} is assumed to be 1.
##' \item If not supplied, \code{time} is assumed to be 0.
##' \item If \code{amt} is not supplied, an error will be generated.
##' \item Other items can include \code{ii}, \code{ss}, and \code{addl}
##' (see \code{\link{data_set}} for details on all of these items).
##' \item \code{ID} may be specified as a vector.
##' \item If replicate is \code{TRUE} (default), thenthe events
##' regimen is replicated for each \code{ID}; otherwise, the number of
Expand Down Expand Up @@ -93,9 +99,8 @@ setMethod("ev", "mrgmod", function(x,object=NULL,...) {

##' @rdname ev
##' @export
setMethod("ev", "missing", function(time=0, evid=1, ID=numeric(0),
cmt=1, replicate=TRUE, until=NULL,
realize_addl=FALSE,...) {
setMethod("ev", "missing", function(time=0, amt, evid=1, cmt=1, ID=numeric(0),
replicate=TRUE, until=NULL, realize_addl=FALSE, ...) {

if(length(match.call())==1) {
return(new("ev", data=data.frame()[0,]))
Expand All @@ -105,7 +110,7 @@ setMethod("ev", "missing", function(time=0, evid=1, ID=numeric(0),
stop("evid cannot be 0 (observation)")
}

data <- as_data_frame(list(..., time = time, cmt = cmt, evid = evid))
data <- as_data_frame(list(time=time, cmt=cmt, amt=amt, evid=evid, ...))

data <- as.data.frame(data)

Expand Down Expand Up @@ -180,6 +185,10 @@ setMethod("ev", "ev", function(x, realize_addl=FALSE,...) {
##' the result
##' @param ... not used
##'
##' @examples
##' data <- data.frame(amt = 100)
##'
##' as.ev(data)
##'
##' @export
setGeneric("as.ev", function(x,...) {
Expand Down
2 changes: 2 additions & 0 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,7 @@ setGeneric("ex", function(x,...) standardGeneric("ex"))
##'
##' @param x mrgsims object
##' @param ... passed along
##'
##'
##' @rdname mod
setGeneric("mod", function(x,...) standardGeneric("mod"))
15 changes: 11 additions & 4 deletions R/idata_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
##' data for the problem. An \code{ID} column is required and there
##' can be no more than one row in the data frame for each individual.
##'
##' In most cases, the columns in the `idata_set` have the same names
##' In most cases, the columns in the \code{idata_set} have the same names
##' as parameters in the \code{\link{param}} list. When this is the case,
##' the parameter set is updated as the simulation proceeds once at the
##' start of each individual. The `idata_set` can also be used to
Expand Down Expand Up @@ -65,11 +65,18 @@
##'
##' exidata
##'
##' mod %>% idata_set(exidata, ID <= 2) %>% mrgsim %>% plot
##' mod %>%
##' idata_set(exidata, ID <= 2) %>%
##' ev(amt = 100) %>%
##' mrgsim() %>%
##' plot()
##'
##' mod %>% idata_set(exidata) %>% mrgsim
##' mod %>%
##' idata_set(exidata) %>%
##' ev(amt = 100) %>%
##' mrgsim()
##'
##' mod %>% mrgsim(idata=exidata)
##' mod %>% ev(amt = 100) %>% mrgsim(idata=exidata)
##'
##' @seealso \code{\link{data_set}}, \code{\link{ev}}
##'
Expand Down
3 changes: 2 additions & 1 deletion R/modlib.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with mrgsolve. If not, see <http://www.gnu.org/licenses/>.


##' Internal model library.
##' Internal model library
##'
##' @param list list available models
##' @export
Expand Down Expand Up @@ -48,6 +48,7 @@
##' mod <- mread("tmdd", modlib())
##' mod <- mread("viral1", modlib())
##' mod <- mread("viral2", modlib())
##' mod <- mread("pred1", modlib())
##'
##' mrgsolve:::code(mod)
##' }
Expand Down
Loading

0 comments on commit 73018a1

Please sign in to comment.