Skip to content

Commit 0c535de

Browse files
author
maechler
committed
fix buglet in str.{Date,POSIXt}(<length 0>, give.attr=FALSE)
git-svn-id: https://svn.r-project.org/R/trunk@89075 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 757ece4 commit 0c535de

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

doc/NEWS.Rd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,18 @@
389389
\item \code{diff(m, lag, dif)} for matrix \code{m} now still returns
390390
matrices, also when \code{lag * dif > nrow(m)} (\PR{18972}, thanks to
391391
\I{Mikael Jagan}).
392+
393+
\item \code{str(x, give.attr=FALSE)} no longer shows attributes when
394+
\code{x} is a zero length \code{"Date"} or \code{"POSIXt"} object.
395+
}
396+
}
397+
}
398+
399+
\section{\Rlogo CHANGES IN R 4.5.2 patched}{
400+
401+
\subsection{BUG FIXES}{
402+
\itemize{
403+
\item .
392404
}
393405
}
394406
}

src/library/utils/R/str.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ str.Date <- str.POSIXt <- function(object, ...) {
4848
cl <- oldClass(object)
4949
## be careful to be fast for large object:
5050
n <- length(object) # FIXME, could be NA
51-
if(n == 0L) return(str.default(object))
51+
if(n == 0L) return(str.default(object, ...))
5252
if(n > 1000L) object <- object[seq_len(1000L)]
5353

5454
give.length <- TRUE ## default
@@ -555,9 +555,8 @@ str.default <-
555555
format.fun <- deParse
556556
} else {
557557
if(mod == "...") { # DOTSXP
558-
format.fun <- function(x) { # use le := length(x)
559-
le <- length(x) ## for testing <<<<< FIXME DROP!! <<<<<<<<<<
560-
hasNm <- nzchar(nm <- names(x) %||% rep.int("", le))
558+
format.fun <- function(x) {
559+
hasNm <- nzchar(nm <- names(x) %||% rep.int("", length(x)))
561560
nm[hasNm] <- paste0(nm[hasNm], "=")
562561
paste0("(", paste(paste0(nm,"*"), collapse=", "),
563562
")")

tests/reg-tests-1e.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2385,7 +2385,15 @@ str(L, give.attr=FALSE) # now 0 x 1 matrices
23852385
vapply(L, \(.) identical(.$f0, .$f), NA) # where all FALSE; now not all TRUE
23862386
stopifnot( print(
23872387
vapply(L, \(.) identical(.$f0 - .$f0, .$f), NA) ) )
2388-
## where all FALSE : diff(fnm, 2,5) was not a matrix
2388+
## were all FALSE : diff(fnm, 2,5) was not a matrix
2389+
2390+
2391+
## str.{Date,POSIXt}(<length 0>, give.attr=FALSE) - now works
2392+
chk0 <- function(x) identical(capture.output(str(x, give.attr = FALSE)),
2393+
capture.output(str(`attr<-`(x, "foobar", NULL))))
2394+
stopifnot(chk0(structure(.Date (numeric()), foobar = list(Dt = "A"))),
2395+
chk0(structure(.POSIXct(numeric()), foobar = list(ct = "C"))))
2396+
## in R <= 4.5.2, give.attr=FALSE was not obeyed for 0-length "Date" / "POSIXt"
23892397

23902398

23912399

0 commit comments

Comments
 (0)