Create tibble printing methods for other classes

rlang
tibble

#1

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:

suppressMessages({
  library(tidyverse)
  library(rlang)
})

#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)))
}

print(some_expressions)
#>                 
#> "1 + 1" "1 + 2"

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

tibble(some_expressions)
#> # 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!


#2

You may find some answer in this vignette from tibble :package:
https://tibble.tidyverse.org/articles/extending.html

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: