Skip to content

Commit

Permalink
Documentation and default method update for bru_used
Browse files Browse the repository at this point in the history
  • Loading branch information
finnlindgren committed Nov 25, 2024
1 parent fae3120 commit ba00468
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ S3method(bru_response_size,bru_info)
S3method(bru_response_size,bru_like)
S3method(bru_response_size,bru_like_list)
S3method(bru_timings,bru)
S3method(bru_used,"NULL")
S3method(bru_used,bru)
S3method(bru_used,bru_like)
S3method(bru_used,bru_used)
S3method(bru_used,character)
S3method(bru_used,default)
S3method(bru_used,expression)
S3method(bru_used,formula)
S3method(bru_used,list)
Expand Down
23 changes: 10 additions & 13 deletions R/used.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,14 @@ bru_used <- function(x = NULL, ...) {
UseMethod("bru_used", x)
}

#' @describeIn bru_used Create a `bru_used` object.
#' @describeIn bru_used Create a `bru_used` object from effect name character
#' vectors.
#' @export
bru_used.default <- function(x = NULL, ...,
bru_used.NULL <- function(x = NULL, ...,
effect = NULL,
effect_exclude = NULL,
latent = NULL,
labels = NULL) {
if (!is.null(x)) {
stop(paste0(
"bru_used input class not supported: ",
"'", paste0(class(x), collapse = "', '"), "'"
))
}

used <- structure(
list(
effect = effect,
Expand Down Expand Up @@ -321,13 +315,15 @@ bru_used.formula <- function(x, ...,
)
}

#' @rdname bru_used
#' @describeIn bru_used Extract the `bru_used` information for the collection
#' of observation models used in a `bru` object.
#' @export
bru_used.bru <- function(x, ..., join = TRUE) {
bru_used(x[["bru_info"]][["lhoods"]], ..., join = join)
}

#' @rdname bru_used
#' @describeIn bru_used Extract the `bru_used` information for each element
#' of a list, and optionally join into a single `bru_used` object.
#' @export
bru_used.list <- function(x, ..., join = TRUE) {
used <- lapply(x, function(y) bru_used(y, ...))
Expand All @@ -350,7 +346,8 @@ bru_used.list <- function(x, ..., join = TRUE) {
used
}

#' @rdname bru_used
#' @describeIn bru_used Extract the `bru_used` information for the collection
#' of observation models used in a `bru` observation model `bru_like` object.
#' @export
bru_used.bru_like <- function(x, ...) {
bru_used(x[["used"]], ...)
Expand Down Expand Up @@ -381,7 +378,7 @@ format.bru_used <- function(x, ...) {
} else {
s <- paste0(s, ", latent[", paste0(x$latent, collapse = ", "), "]")
}
if (!is.null(x$effect_exclude)) {
if (!is.null(x[["effect_exclude"]])) {
s <- paste0(s, ", exclude[", paste0(x$effect_exclude, collapse = ", "), "]")
}
s
Expand Down
16 changes: 13 additions & 3 deletions man/bru_used.Rd

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

0 comments on commit ba00468

Please sign in to comment.