Skip to content

Commit

Permalink
after r87627, re-allow (& document) summary.data.frame(*, digits=NULL…
Browse files Browse the repository at this point in the history
…) via format.summaryDefault(..)

git-svn-id: https://svn.r-project.org/R/trunk@87651 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
maechler committed Jan 27, 2025
1 parent 24430e7 commit 3a8c80f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/library/base/R/summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ format.summaryDefault <- function(x, digits = max(3L, getOption("digits") - 3L),
xx <- x
if(is.numeric(x) || is.complex(x)) {
finite <- is.finite(x)
xx[finite] <- zapsmall(x[finite], digits = digits + zdigits)
digs <- digits %||% eval(formals()$digits) # use <default> if NULL
xx[finite] <- zapsmall(x[finite], digits = digs + zdigits)
}
class(xx) <- class(x)[-1]
m <- match("NA's", names(x), 0)
Expand Down Expand Up @@ -137,7 +138,7 @@ summary.data.frame <-
}
z
}
# compute results to full precision.
# compute results to "full" precision (FIXME: option full.digits = 12L )
z <- lapply(X = as.list(object), FUN = summary,
maxsum = maxsum, digits = 12L, ...)
nv <- length(object)
Expand Down
7 changes: 6 additions & 1 deletion src/library/base/man/summary.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ summary(object, \dots)
\item{x}{a result of the \emph{default} method of \code{summary()}.}
\item{maxsum}{integer, indicating how many levels should be shown for
\code{\link{factor}}s.}
\item{digits}{integer, used for number formatting with
\item{digits}{integer (or \code{\link{NULL}}, see \sQuote{Details}),
used for number formatting with
\code{\link{signif}()} (for \code{summary.default}) or
\code{\link{format}()} (for \code{summary.data.frame}). In
\code{summary.default}, if not specified (i.e.,
Expand All @@ -56,6 +57,10 @@ summary(object, \dots)
summarized in \code{"(Others)"} (resulting in at most \code{maxsum}
frequencies).

The \code{digits} argument may be \code{\link{NULL}} for some methods
specifying to use the default value, e.g., for the
\code{"summaryDefault"} \code{format()} method.

The functions \code{summary.lm} and \code{summary.glm} are examples
of particular methods which summarize the results produced by
\code{\link{lm}} and \code{\link{glm}}.
Expand Down
6 changes: 6 additions & 0 deletions tests/reg-tests-1e.R
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,12 @@ stopifnot(identical(shN2, ushfmt))
## Mean was wrongly double-rounded to "164326" for years in R < 4.5.0


## summary.data.frame(*, digits=NULL)
(sdf <- summary(data.frame(x = seq_along(helconc), helconc), digits = NULL))
stopifnot(is.table(sdf), is.matrix(sdf), identical(dim(sdf), c(6L, 2L)))
## failed for a few days only



## keep at end
rbind(last = proc.time() - .pt,
Expand Down

0 comments on commit 3a8c80f

Please sign in to comment.