R/npars.R

Defines functions npars.default npars

Documented in npars npars.default

#' Number of Parameters
#'
#' Gets the number of parameters of an object.
#'
#' @inheritParams params
#' @return An integer scalar of the number of parameters.
#' @seealso [pars()]
#' @family MCMC dimensions
#' @family parameters
#' @export
npars <- function(x, ...) UseMethod("npars")

#' @description
#' The default methods returns the length of [pars()] if none are
#' `NA`, otherwise it returns `NA`.
#' @rdname npars
#' @export
npars.default <- function(x, ...) {
  x <- pars(x, ...)
  if (anyNA(x)) {
    return(NA_integer_)
  }
  length(x)
}

Try the universals package in your browser

Any scripts or data that you put into this service are public.

universals documentation built on Sept. 22, 2022, 5:07 p.m.