Skip to content

Commit 3a8c80f

Browse files
author
maechler
committed
after r87627, re-allow (& document) summary.data.frame(*, digits=NULL) via format.summaryDefault(..)
git-svn-id: https://svn.r-project.org/R/trunk@87651 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 24430e7 commit 3a8c80f

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/library/base/R/summary.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ format.summaryDefault <- function(x, digits = max(3L, getOption("digits") - 3L),
7171
xx <- x
7272
if(is.numeric(x) || is.complex(x)) {
7373
finite <- is.finite(x)
74-
xx[finite] <- zapsmall(x[finite], digits = digits + zdigits)
74+
digs <- digits %||% eval(formals()$digits) # use <default> if NULL
75+
xx[finite] <- zapsmall(x[finite], digits = digs + zdigits)
7576
}
7677
class(xx) <- class(x)[-1]
7778
m <- match("NA's", names(x), 0)
@@ -137,7 +138,7 @@ summary.data.frame <-
137138
}
138139
z
139140
}
140-
# compute results to full precision.
141+
# compute results to "full" precision (FIXME: option full.digits = 12L )
141142
z <- lapply(X = as.list(object), FUN = summary,
142143
maxsum = maxsum, digits = 12L, ...)
143144
nv <- length(object)

src/library/base/man/summary.Rd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ summary(object, \dots)
3737
\item{x}{a result of the \emph{default} method of \code{summary()}.}
3838
\item{maxsum}{integer, indicating how many levels should be shown for
3939
\code{\link{factor}}s.}
40-
\item{digits}{integer, used for number formatting with
40+
\item{digits}{integer (or \code{\link{NULL}}, see \sQuote{Details}),
41+
used for number formatting with
4142
\code{\link{signif}()} (for \code{summary.default}) or
4243
\code{\link{format}()} (for \code{summary.data.frame}). In
4344
\code{summary.default}, if not specified (i.e.,
@@ -56,6 +57,10 @@ summary(object, \dots)
5657
summarized in \code{"(Others)"} (resulting in at most \code{maxsum}
5758
frequencies).
5859

60+
The \code{digits} argument may be \code{\link{NULL}} for some methods
61+
specifying to use the default value, e.g., for the
62+
\code{"summaryDefault"} \code{format()} method.
63+
5964
The functions \code{summary.lm} and \code{summary.glm} are examples
6065
of particular methods which summarize the results produced by
6166
\code{\link{lm}} and \code{\link{glm}}.

tests/reg-tests-1e.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,12 @@ stopifnot(identical(shN2, ushfmt))
17761776
## Mean was wrongly double-rounded to "164326" for years in R < 4.5.0
17771777

17781778

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

17801786
## keep at end
17811787
rbind(last = proc.time() - .pt,

0 commit comments

Comments
 (0)