Skip to content

Commit

Permalink
update tgrid doc
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebaron committed Oct 10, 2024
1 parent a77e6f0 commit fcd6982
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 70 deletions.
101 changes: 48 additions & 53 deletions R/class_tgrid.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 Down Expand Up @@ -107,41 +107,42 @@ as_deslist <- function(data, descol="ID") {
structure(out, descol=descol)
}

##' Create a simtime object
##'
##' simtime objects allow the user to specify simulation start and end times,
##' along with the simulation time step.
##'
##' @rdname tgrid
##' @name tgrid
##'
##' @param x tgrid object
##' @param start simulation start time
##' @param end simulation end time
##' @param delta simulation time step
##' @param add addition simulation times
##' @param .offset the resulting set of times will be adjusted by this amount
##' @param .scale the resulting set of times will be scaled by this factor
##' @param ... passed on to other methods
##' @export
##' @examples
##'
##' peak <- tgrid(0,6,0.2)
##' sparse <- tgrid(0,24,4)
##'
##' day1 <- c(peak,sparse)
##'
##' design <- c(day1, day1+72, day1+240)
##'
##' \dontrun{
##' mod <- mrgsolve::house()
##'
##' out <- mod %>% ev(amt=1000, ii=24, addl=10) %>% mrgsim(tgrid=design)
##'
##' plot(out,CP~., type='b')
##' }
#' Create a simtime object
#'
#' simtime objects allow the user to specify simulation start and end times,
#' along with the simulation time step.
#'
#' @rdname tgrid
#' @name tgrid
#'
#' @param x tgrid object.
#' @param start simulation start time.
#' @param end simulation end time.
#' @param delta simulation time step.
#' @param add addition simulation times.
#' @param .offset the resulting set of times will be adjusted by this amount.
#' @param .scale the resulting set of times will be scaled by this factor.
#' @param ... not used.
#'
#' @examples
#' peak <- tgrid(0, 6, 0.2)
#' sparse <- tgrid(0, 24, 4)
#'
#' day1 <- c(peak, sparse)
#'
#' design <- c(day1, day1+72, day1+240)
#'
#' \dontrun{
#' mod <- mrgsolve::house()
#'
#' out <- mod %>% ev(amt=1000, ii=24, addl=10) %>% mrgsim(tgrid=design)
#'
#' plot(out, CP ~ time, type = 'b')
#' }
#' @md
#' @export
tgrid <- function(start=0,end=24,delta=1,add=numeric(0),
.offset=0, .scale=1,...) {
.offset=0, .scale=1, ...) {
new("tgrid", start=start, end=end, delta=delta,
add=add, offset=.offset, scale=.scale)
}
Expand Down Expand Up @@ -173,19 +174,20 @@ render_time <- function(x) {
times
}

##' @rdname tgrid
##' @export
#' @rdname tgrid
#' @export
setMethod("stime", "numeric", function(x,...) {
sort(unique(x))
})

##' Operations with tgrid objects
##'
##' @param x mrgmod object
##' @param recursive not used
##' @param ... passed along to other methods
##' @rdname tgrid_ops
##' @export
#' Operations with tgrid objects
#'
#' @param x a tgrid object.
#' @param ... additional tgrid objects.
#' @param recursive not used.
#' @rdname tgrid_ops
#' @md
#' @export
setMethod("c", "tgrid", function(x,..., recursive=FALSE) {

x <- c(list(x), list(...))
Expand All @@ -200,8 +202,8 @@ setMethod("c", "tgrid", function(x,..., recursive=FALSE) {
})


##' @rdname tgrid_ops
##' @export
#' @rdname tgrid_ops
#' @export
setMethod("c", "tgrids", function(x,...,recursive=FALSE) {
do.call("c",c(x@data, list(...)))
})
Expand Down Expand Up @@ -278,10 +280,3 @@ setMethod("show", "tgrids", function(object) {
cat("--------\n")
})
})







27 changes: 13 additions & 14 deletions man/tgrid.Rd

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

6 changes: 3 additions & 3 deletions man/tgrid_ops.Rd

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

0 comments on commit fcd6982

Please sign in to comment.