Create tibble printing methods for other classes

Hi all,

I would like to know how to create or change print methods for classes printed within a tibble. Forgive me if the answer is obvious, I don't often write classes and methods. Below is a reprex:


#Create an S3 object of class "exprlist", representing a list of R expressions

some_expressions <- exprs(1 + 1, 1 + 2)
class(some_expressions) <- "exprlist"

#Create a print method for "exprlist" that deparses expressions to characters 
#before printing

print.exprlist <- function(x) {
  print(map_chr(x, ~expr_text(.x)))

#> "1 + 1" "1 + 2"

#How do I get an "exprlist" to print the same way within a tibble?

#> # A tibble: 2 x 1
#>   some_expressions
#>   <list>          
#> 1 <language>      
#> 2 <language>

Created on 2018-07-26 by the reprex package (v0.2.0).

Any ideas? Thanks!

1 Like

You may find some answer in this vignette from tibble :package:

It explains how to extdnd tibble to use with a new class, including a custom printing.

FWIW, printing mechanism for tibble lives in pillar :package: