From 1ca32685beaa3d842dddb60cf157b5415bc8ef45 Mon Sep 17 00:00:00 2001 From: guslipkin Date: Fri, 1 Nov 2024 21:00:13 -0600 Subject: [PATCH] If length(x) > 1, return a matrix --- R/guess.r | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/R/guess.r b/R/guess.r index 8f4e8de6..a3a7bfec 100644 --- a/R/guess.r +++ b/R/guess.r @@ -153,18 +153,24 @@ guess_formats <- function(x, orders, locale = Sys.getlocale("LC_TIME"), } .build_formats <- function(regs, orders, x) { - out <- mapply( - function(reg, name) { - out <- .substitute_formats(reg, x) - if (!is.null(out)) { - names(out) <- rep.int(name, length(out)) - out - } - }, REGS, orders, - SIMPLIFY = F, USE.NAMES = F - ) - names(out) <- NULL - unlist(out) + if (length(x) > 1) { + subs <- lapply(REGS, .substitute_formats, x, fmts_only = FALSE) + names(subs) <- orders + do.call(cbind, c('x' = list(x), subs)) + } else { + out <- mapply( + function(reg, name) { + out <- .substitute_formats(reg, x) + if (!is.null(out)) { + names(out) <- rep.int(name, length(out)) + out + } + }, REGS, orders, + SIMPLIFY = F, USE.NAMES = F + ) + names(out) <- NULL + unlist(out) + } } if (preproc_wday && !any(grepl("[aA]", orders))) {