R/dimension.default.R

###########################################################################/**
# @RdocDefault dimension
#
# @title "Gets the dimension of the object"
#
# \description{
#   Gets the dimension of the object similar to what \code{dim()} does,
#   but instead of @NULL it will return the length of a vector.
#   If a function is passed, @NULL is returned.
# }
#
# @synopsis
#
# \arguments{
#   \item{object}{The object for which the dimension should be obtained.}
#   \item{...}{Not used.}
# }
#
# \value{
#  Returns an @integer @vector or @NULL.
# }
#
# \examples{
#   dimension(matrix(1:100, ncol=10))     # 10 10
#   dimension(1:14)                       # 14
#   dimension(data.frame(a=1:10, b=10:1)) # 10  2
#   dimension(print)                      # NULL
# }
#
# @author
#
# \seealso{
#   @see "ll.default".
#   @see "base::dim" and @see "base::length".
# }
#
# @keyword attribute
# @keyword utilities
# @keyword internal
#*/###########################################################################
setMethodS3("dimension", "default", function(object, ...) {
  if (is.function(object))
    return(NULL)
  size <- dim(object)
  if (is.null(size))
    size <- length(object)
  as.integer(size)
})

Try the R.oo package in your browser

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

R.oo documentation built on Nov. 2, 2024, 1:07 a.m.