[Rd] Why does format.default skip dispatch for list items?

Michael Chirico m|ch@e|ch|r|co4 @end|ng |rom gm@||@com
Mon May 12 00:35:10 CEST 2025


This is the documented behavior since r35262 (2005), from ?format

> If x is a list, the result is a character vector obtained by applying format.default(x, ...) to each element of the list

One consequence is that we can't add "nice" printing methods for
list-of-object columns in data.frames:

https://github.com/eddelbuettel/rprotobuf/issues/109

library(RProtoBuf)
person_desc <- P("tutorial.Person")
DF <- data.frame(id = 1:2)
DF$person = list(person_desc$new(name = "Me"), person_desc$new(name =
"You", email = "y using u.com"))

DF
#   id                                                  person
# 1  1 <S4 class ‘Message’ [package “RProtoBuf”] with 2 slots>
# 2  2 <S4 class ‘Message’ [package “RProtoBuf”] with 2 slots>
             ^ from format.default, with option to make it more informative

One assumes that at this point, there are back-compatibility concerns
since this is the documented behavior.

Is there no other option than to make the 'person' column itself an S3
class with an associated format method?



More information about the R-devel mailing list