Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebaron committed Oct 9, 2024
1 parent bf9aad1 commit 299a603
Show file tree
Hide file tree
Showing 33 changed files with 417 additions and 390 deletions.
10 changes: 5 additions & 5 deletions R/class_mrgmod.R
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ setMethod("project", "packmod", function(x,...) {
})

#' @rdname cmtn
#' @param tag compartment name
#' @param tag compartment name.
#' @export
setMethod("cmtn", "mrgmod", function(x,tag,...) {
return(which(cmt(x)==tag))
Expand Down Expand Up @@ -434,9 +434,9 @@ CAPTUREI <- function(x) c(length(x@capture),x@Icap-1L)
#' This is also the directory where the model is built, which could be the
#' value of [tempdir()].
#'
#' @param x model object
#' @param short logical; if `TRUE`, `soloc`s will
#' be rendered with a short path name
#' @param x model object.
#' @param short logical; if `TRUE`, `soloc`s will be rendered with a short
#' path name.
#'
#' @examples
#' mod <- mrgsolve::house()
Expand Down Expand Up @@ -493,7 +493,7 @@ setMethod("names", "mrgmod", function(x) {
#'
#' @param x a model object.
#' @param deep if `TRUE`, extra information is returned in the output list
#' (see details).
#' (see **Details**).
#' @param ... not used.
#'
#' @details
Expand Down
28 changes: 15 additions & 13 deletions R/class_mrgsims.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2013 - 2019 Metrum Research Group
# Copyright (C) 2013 - 2024 Metrum Research Group
#
# This file is part of mrgsolve.
#
Expand Down Expand Up @@ -44,21 +44,23 @@ setClass("batch_mrgsims",contains="mrgsims",
)


##' Check if an object is mrgsim output
##'
##' @param x any object
##'
##' @return \code{TRUE} if \code{x} inherits \code{mrgsims}.
##'
##' @export
#' Check if an object is mrgsims output
#'
#' @param x any object.
#'
#' @return `TRUE` if `x` inherits `mrgsims`.
#'
#' @md
#' @export
is.mrgsims <- function(x) inherits(x,"mrgsims")


##' Coerce an mrgsims object to list
##'
##' @param x an mrgsims object
##' @param ... not used
##' @export
#' Coerce an mrgsims object to list
#'
#' @param x an mrgsims object.
#' @param ... not used.
#' @md
#' @export
setMethod("as.list", "mrgsims", function(x, ...) {
to_get <- slotNames("mrgsims")
out <- vector("list",length(to_get))
Expand Down
98 changes: 51 additions & 47 deletions R/env.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2013 - 2019 Metrum Research Group
# Copyright (C) 2013 - 2024 Metrum Research Group
#
# This file is part of mrgsolve.
#
Expand All @@ -16,33 +16,34 @@
# along with mrgsolve. If not, see <http://www.gnu.org/licenses/>.


##' Re-evaluate the code in the ENV block
##'
##' The \code{$ENV} block is a block of R code that can
##' realize any sort of R object that might be used in running
##' a model.
##'
##' @seealso \code{\link{env_get}}, \code{\link{env_ls}}
##'
##' @param x model object
##' @param seed passed to \code{\link{set.seed}} if a numeric value is supplied
##'
##' @export
#' Re-evaluate the code in the ENV block
#'
#' The `$ENV` block is a block of R code that can realize any sort of R object
#' that might be used in running a model.
#'
#' @seealso [env_get()], [env_ls()]
#'
#' @param x a model object.
#' @param seed passed to [set.seed()] if a numeric value is supplied.
#'
#' @md
#' @export
env_eval <- function(x,seed=NULL) {
if(is.numeric(seed)) set.seed(seed)
eval_ENV_block(x=x@envir$.code,where=project(x),envir=x@envir)
return(invisible(x))
}

##' List objects in the model environment
##'
##' Each model keeps an internal environment that allows the user
##' to carry any \code{R} object along. Objects are coded in \code{$ENV}.
##'
##' @param x model object
##' @param ... passed to \code{\link{ls}}
##'
##' @export
#' List objects in the model environment
#'
#' Each model keeps an internal environment that allows the user
#' to carry any `R` object along. Objects are coded in `$ENV`.
#'
#' @param x amodel object.
#' @param ... passed to [ls()].
#'
#' @md
#' @export
env_ls <- function(x,...) {
objects <- ls(x@envir,...)
cl <- sapply(objects,function(o) {
Expand All @@ -53,12 +54,13 @@ env_ls <- function(x,...) {
arrange__(ans, .dots=c("class"))
}

##' Return model environment
##'
##' @param x model object
##' @param tolist should the environment be coerced to \code{list}?
##'
##' @export
#' Return model environment
#'
#' @param x a model object.
#' @param tolist should the environment be coerced to `list`?
#'
#' @md
#' @export
env_get <- function(x,tolist=TRUE) {
if(tolist) {
return(as.list(x@envir))
Expand All @@ -67,36 +69,38 @@ env_get <- function(x,tolist=TRUE) {
}
}

##' @rdname env_get
##' @export
#' @rdname env_get
#' @export
env_get_env <- function(x) {
x@envir
}

##' Update objects in model environment
##'
##' @param .x model object
##' @param .dots list of objects to updated
##' @param ... objects to update
##'
##' @export
#' Update objects in model environment
#'
#' @param .x a model object.
#' @param .dots list of objects to updated.
#' @param ... objects to update.
#'
#' @md
#' @export
env_update <- function(.x,...,.dots=list()) {
right <- c(list(...),.dots)
left <- as.list(.x@envir)
.x@envir <- as.environment(merge.list(left,right))
return(invisible(.x))
}

##' Run the model cama function
##'
##' @param mod model object
##' @param fn function name
##' @param ... passed to update
##'
##' @details \code{sah-mah}
##'
##' @keywords internal
##' @export
#' Run the model cama function
#'
#' @param mod a model object.
#' @param fn function name.
#' @param ... passed to update.
#'
#' @details `sah-mah`
#'
#' @keywords internal
#' @md
#' @export
cama <- function(mod,fn="cama",...) {
stop("this function is deprecated.")
# object_exists(fn, mod@envir, "function", inherits=FALSE)
Expand Down
23 changes: 13 additions & 10 deletions R/generics.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2013 - 2020 Metrum Research Group
# Copyright (C) 2013 - 2024 Metrum Research Group
#
# This file is part of mrgsolve.
#
Expand All @@ -15,15 +15,17 @@
# You should have received a copy of the GNU General Public License
# along with mrgsolve. If not, see <http://www.gnu.org/licenses/>.

##' Get the compartment number from a compartment name
##'
##' @param x model object
##' @param ... passed along
##'
##' @examples
##' mod <- mrgsolve::house()
##' mod %>% cmtn("CENT")
##' @export
#' Get the compartment number from a compartment name
#'
#' @param x model object.
#' @param ... not used.
#'
#' @examples
#' mod <- mrgsolve::house()
#' cmtn(mod, "CENT")
#'
#' @md
#' @export
setGeneric("cmtn", function(x,...) standardGeneric("cmtn"))

#' Print model code to the console
Expand All @@ -37,6 +39,7 @@ setGeneric("cmtn", function(x,...) standardGeneric("cmtn"))
#' @param ... not used.
#' @return `NULL` is returned invisibly when `raw` is `FALSE`; when `raw` is
#' set to `TRUE`, the model code is returned as a character vector.
#' @md
#' @export
setGeneric("see", function(x,...) standardGeneric("see"))

Expand Down
105 changes: 55 additions & 50 deletions R/init.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2013 - 2020 Metrum Research Group
# Copyright (C) 2013 - 2024 Metrum Research Group
#
# This file is part of mrgsolve.
#
Expand All @@ -16,50 +16,55 @@
# along with mrgsolve. If not, see <http://www.gnu.org/licenses/>.


##' Methods for working with the model compartment list
##'
##' Calling \code{init} with the model object as the first argument
##' will return the model initial conditions as a \code{numericlist}
##' object. See \code{\link{numericlist}} for methods to deal with
##' \code{cmt_list} objects.
##'
##' @aliases init
##' @param .x the model object
##' @param .y list to be merged into parameter list
##' @param .pat a regular expression (character) to be applied as
##' a filter when printing compartments to the screen
##' @param ... passed along
##' @return an object of class \code{cmt_list} (see
##' \code{\link{numericlist}})
##' @details
##' Can be used to either get a compartment list object from a
##' \code{mrgmod} model object or to update the compartment initial
##' conditions in a model object. For both uses, the return value
##' is a \code{cmt_list} object. For the former use, \code{init}
##' is usually called to print the compartment initial conditions
##' to the screen, but the \code{cmt_list} object can also be coerced
##' to a list or numeric R object.
##'
##' @examples
##' ## example("init")
##' mod <- mrgsolve::house()
##'
##' init(mod)
##' init(mod, .pat="^C") ## may be useful for large models
##'
##' class(init(mod))
##'
##' init(mod)$CENT
##'
##' as.list(init(mod))
##' as.data.frame(init(mod))

##' @export
#' Methods for working with the model compartment list
#'
#' Calling `init()` with the model object as the first argument
#' will return the model initial conditions as a [numericlist]
#' object. See [numericlist] for methods to deal with
#' `cmt_list` objects.
#'
#' @aliases init
#' @param .x the model object.
#' @param .y list to be merged into parameter list.
#' @param .pat a regular expression (character) to be applied as
#' a filter when printing compartments to the screen.
#' @param ... `name = value` assignments to update the initial conditions list.
#'
#' @return An object of class `cmt_list` (see [numericlist]).
#'
#' @details
#' Can be used to either get a compartment list object from a
#' `mrgmod` model object or to update the compartment initial
#' conditions in a model object. For both uses, the return value
#' is a `cmt_list` object. For the former use, `init()`
#' is usually called to print the compartment initial conditions
#' to the screen, but the `cmt_list` object can also be coerced
#' to a list or numeric R object.
#'
#' @examples
#' ## example("init")
#' mod <- mrgsolve::house()
#'
#' init(mod)
#'
#' init(mod, .pat="^C") ## may be useful for large models
#'
#' class(init(mod))
#'
#' init(mod)$CENT
#'
#' as.list(init(mod))
#'
#' as.data.frame(init(mod))
#'
#'
#' @md
#' @export
setGeneric("init", function(.x,...) standardGeneric("init"))


##' @export
##' @rdname init
#' @export
#' @rdname init
setMethod("init", "mrgmod", function(.x,.y=list(),..., .pat="*") {

args <- c(as.list(.y),list(...))
Expand All @@ -80,26 +85,26 @@ setMethod("init", "mrgmod", function(.x,.y=list(),..., .pat="*") {
return(.x@init)
})

##' @rdname init
##' @export
#' @rdname init
#' @export
setMethod("init", "mrgsims", function(.x,...) {
init(mod(.x),...)
})

##' @rdname init
##' @export
#' @rdname init
#' @export
setMethod("init", "missing", function(...) {
init(list(...))
})

##' @rdname init
##' @export
#' @rdname init
#' @export
setMethod("init", "list", function(.x,...) {
create_numeric_list(.x,"cmt_list",...)
})

##' @rdname init
##' @export
#' @rdname init
#' @export
setMethod("init", "ANY", function(.x,...) {
init(as.list(.x),...)
})
Expand Down
Loading

0 comments on commit 299a603

Please sign in to comment.