Skip to content

Commit c3b3ac8

Browse files
committed
enh: improve fallback for print_list()
1 parent a008a84 commit c3b3ac8

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

R/format.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,23 @@ print_list <- function(x, pre = "") {
391391
if (length(ns) != length(x)) {
392392
stop("all elements must be named")
393393
}
394-
x <- lapply(x, as.character)
394+
x <- lapply(x, function(i) {
395+
if (is.character(i) ||
396+
is.logical(i) ||
397+
is.factor(i) ||
398+
is.numeric(i)) {
399+
return(as.character(i))
400+
}
401+
# fallback
402+
.print_fallback(i)
403+
})
395404
cat(sprintf("%s%s : %s", pre, format(ns), x), sep = "\n")
396405
invisible(x)
397406
}
398407

408+
.print_fallback <- function(x) {
409+
sprintf("<%s> length %d", class(x), length(x))
410+
}
399411

400412

401413

0 commit comments

Comments
 (0)