Skip to content

Commit 940b5c2

Browse files
author
maechler
committed
format.default(<list>, ..) now calls format(), not format.default()
git-svn-id: https://svn.r-project.org/R/trunk@88448 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 6cc69b1 commit 940b5c2

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/library/base/R/format.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ format.default <-
3333
if(missing(trim)) trim <- TRUE
3434
if(missing(justify)) justify <- "none"
3535
res <- lapply(X = x,
36-
FUN = function(xx, ...) format.default(unlist(xx),...),
36+
FUN = function(xx, ...) format(unlist(xx), ...),
3737
trim = trim, digits = digits, nsmall = nsmall,
3838
justify = justify, width = width, na.encode = na.encode,
3939
scientific = scientific,
4040
big.mark = big.mark, big.interval = big.interval,
4141
small.mark = small.mark, small.interval = small.interval,
4242
decimal.mark = decimal.mark, zero.print = zero.print,
4343
drop0trailing = drop0trailing, ...)
44-
vapply(res, paste, "", collapse = ", ")
44+
vapply(res, paste0, "", collapse = ", ")
4545
} else {
4646
switch(mode(x),
4747
NULL = "NULL",

src/library/base/man/format.Rd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% File src/library/base/man/format.Rd
22
% Part of the R package, https://www.R-project.org
3-
% Copyright 1995-2024 R Core Team
3+
% Copyright 1995-2025 R Core Team
44
% Copyright 2003-2016 The R Foundation
55
% Distributed under GPL 2 or later
66

@@ -146,10 +146,11 @@ format(x, \dots)
146146
attributes are copied.
147147
148148
If \code{x} is a list, the result is a character vector obtained by
149-
applying \code{format.default(x, \dots)} to each element of the list
149+
applying \code{format(x, \dots)} (instead of \code{format.default(x,
150+
\dots)} in \R <= 4.5.z) to each element of the list
150151
(after \I{\code{\link{unlist}}ing} elements which are themselves lists),
151152
and then collapsing the result for each element with
152-
\code{paste(collapse = ", ")}. The defaults in this case are
153+
\code{paste0(collapse = ", ")}. The defaults in this case are
153154
\code{trim = TRUE, justify = "none"} since one does not usually want
154155
alignment in the collapsed strings.
155156
}

tests/reg-tests-1e.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,6 +2076,14 @@ chk(a1); chk(a2)
20762076
## Im(.)s had more NA's than just at the end, in R <= 4.5.z
20772077

20782078

2079+
## format(<list of objects>) -- now dispatches correctly
2080+
dts <- seq(.Date(11100), .Date(11111))
2081+
(fD <- format(Ldt <- as.list(dts)))
2082+
stopifnot(is.list(Ldt), vapply(Ldt, inherits, NA, "Date"),
2083+
identical(fD, format.Date(dts)))
2084+
# fD was "11100" "11101" .... "11111" in R <= 4.5.z
2085+
2086+
20792087

20802088
## keep at end
20812089
rbind(last = proc.time() - .pt,

0 commit comments

Comments
 (0)