Skip to content

Commit

Permalink
add examples or rdnames tags to exported functions
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwlambert committed Oct 22, 2024
1 parent 516b5e5 commit 847f6a6
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 1 deletion.
1 change: 1 addition & 0 deletions R/accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ get_parameters.epiparameter <- function(x, ...) {
params
}

#' @rdname get_parameters.epiparameter
#' @export
get_parameters.multi_epiparameter <- function(x, ...) {
params <- lapply(x, get_parameters)
Expand Down
2 changes: 2 additions & 0 deletions R/checkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ is_parameterised <- function(x, ...) {
#' @export
is_parameterized <- is_parameterised

#' @rdname is_parameterised
#' @export
is_parameterised.epiparameter <- function(x, ...) {
chkDots(...)
# probability distribution object
return(is.object(x$prob_distribution))
}

#' @rdname is_parameterised
#' @export
is_parameterised.multi_epiparameter <- function(x, ...) {
chkDots(...)
Expand Down
23 changes: 23 additions & 0 deletions R/coercion.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
#'
#' @return A [function] object.
#' @export
#'
#' @examples
#' ep <- epiparameter_db(single_epiparameter = TRUE)
#' # by default it will convert to a density function
#' f <- as.function(ep)
#' # use function
#' f(10)
#'
#' f <- as.function(ep, func_type = "cdf")
#' f(10)
as.function.epiparameter <- function(x,
func_type = c(
"density", "cdf", "generate", "quantile"
Expand Down Expand Up @@ -53,6 +63,10 @@ as.function.epiparameter <- function(x,
#'
#' @return A `<data.frame>` with a single row.
#' @export
#'
#' @examples
#' ep <- epiparameter_db(single_epiparameter = TRUE)
#' as.data.frame(ep)
as.data.frame.epiparameter <- function(x, ...) {
chkDots(...)
# check object as could be invalidated by user
Expand Down Expand Up @@ -82,6 +96,10 @@ as.data.frame.epiparameter <- function(x, ...) {
#'
#' @return A `<data.frame>` with as many rows as length of input list.
#' @export
#'
#' @examples
#' db <- epiparameter_db()
#' as.data.frame(db)
as.data.frame.multi_epiparameter <- function(x, ...) {
chkDots(...)
do.call(rbind, lapply(x, as.data.frame))
Expand Down Expand Up @@ -133,6 +151,11 @@ as_epiparameter <- function(x, ...) {
#'
#' @inherit epiparameter_db return
#' @export
#'
#' @examples
#' ep <- epiparameter_db(single_epiparameter = TRUE)
#' df <- as.data.frame(ep)
#' ep <- as_epiparameter(df)
as_epiparameter.data.frame <- function(x, ...) {
if (is_epiparameter_df(x)) {
epiparameter <- .epiparameter_df_to_epiparameter(x, ...)
Expand Down
17 changes: 17 additions & 0 deletions R/epiparameter.R
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ epiparameter <- function(disease,
#' (errors when invalid `<epiparameter>` object is provided).
#'
#' @export
#'
#' @examples
#' ep <- epiparameter_db(single_epiparameter = TRUE)
#' assert_epiparameter(ep)
#'
#' # example with invalid <epiparameter>
#' ep$disease <- NULL
#' try(assert_epiparameter(ep))
assert_epiparameter <- function(x) {
msg <- .validate_epiparameter(x)
if (length(msg) > 0) {
Expand All @@ -320,6 +328,14 @@ assert_epiparameter <- function(x) {
#' @return A boolean `logical` whether the object is a valid `<epiparameter>`
#' object (prints message when invalid `<epiparameter>` object is provided).
#' @export
#'
#' @examples
#' ep <- epiparameter_db(single_epiparameter = TRUE)
#' test_epiparameter(ep)
#'
#' # example with invalid <epiparameter>
#' ep$disease <- NULL
#' test_epiparameter(ep)
test_epiparameter <- function(x) {
msg <- .validate_epiparameter(x)
if (length(msg) > 0) {
Expand Down Expand Up @@ -987,6 +1003,7 @@ c.epiparameter <- function(...) {
ep_list
}

#' @rdname c.epiparameter
#' @export
c.multi_epiparameter <- function(...) {
c.epiparameter(...)
Expand Down
4 changes: 3 additions & 1 deletion R/parameter_tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#' @param multi_epiparameter Either an `<epiparameter>` object or a list of
#' `<epiparameter>` objects.
#'
#' @author Joshua W. Lambert, Adam Kucharski
#' @return A `<parameter_tbl>` object which is a subclass of `<data.frame>`.
#' @export
#' @author Joshua W. Lambert, Adam Kucharski
#'
#' @examples
#' epiparameter_list <- epiparameter_db(disease = "COVID-19")
#' parameter_tbl(multi_epiparameter = epiparameter_list)
Expand Down
4 changes: 4 additions & 0 deletions man/as.data.frame.epiparameter.Rd

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

4 changes: 4 additions & 0 deletions man/as.data.frame.multi_epiparameter.Rd

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

10 changes: 10 additions & 0 deletions man/as.function.epiparameter.Rd

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

5 changes: 5 additions & 0 deletions man/as_epiparameter.data.frame.Rd

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

8 changes: 8 additions & 0 deletions man/assert_epiparameter.Rd

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

3 changes: 3 additions & 0 deletions man/c.epiparameter.Rd

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

3 changes: 3 additions & 0 deletions man/get_parameters.epiparameter.Rd

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

6 changes: 6 additions & 0 deletions man/is_parameterised.Rd

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

3 changes: 3 additions & 0 deletions man/parameter_tbl.Rd

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

8 changes: 8 additions & 0 deletions man/test_epiparameter.Rd

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

0 comments on commit 847f6a6

Please sign in to comment.