How can I specify the formatting method RStudio uses when displaying data frames RMarkdown notebook-style chunks?

[The original question title was "What function is called that creates the pretty format output of data.frames and tibbles?"]

I seem to recall that there's some special function that formats dataframes into the browsable ones you normally see in RMD documents in progress, like the one below.

What is that function?

I'd like to know this so I can define a more reasonable default than the '<S3: myfhc>' that appears for my custom objects.

Something like kable or huxtable maybe?

Both produce nice looking tables, but neither matches the output I see below the chunk in the RMD document. Also, neither seem to be interactive.

What do you mean by interactive?

Are you thinking of something like DT (data table) which produces html output?

https://rstudio.github.io/DT/
https://appsilon.com/forget-about-excel-use-r-shiny-packages-instead/

Thanks for your willingness to help, but I think I need to clarify myself. I'm probably falling prey to the XY problem here.

My primary goal is instead of my custom classes showing up as <S3: myfhc> (see column foo), I want to specify how they should be seen when 'printed' in this context. I don't think I'll have any trouble writing up that method; but finding what method I need to specify is the tricky part. It doesn't appear that behavior is determined by the format generic or the print generic. (In fact, when I print this table in the console, I get a much more reasonable output than <S3: myfhc>, it actually includes values.) I'm dumbfounded on how to find the function that RStudio uses in this case.

I was hoping that finding that method would lead me to source code that shows the right method I need to implement, but that may be difficult too.

Does that screenshot come from RStudio? I've never seen anything like it.

It does, here's a wider view. Maybe it's the theme that's throwing you off?

The object being printed is a tbl / data.frame.

I think it might be pillar package.

1 Like

I imagine they use the javascript DataTables library. RStudio is apparently written in java which is converted to javascript.

https://stackoverflow.com/questions/28946920/what-programming-language-was-rstudio-written-in

1 Like

Pillar is used in the terminal-style output (fixed width, on the right of the photo above), and that was helpful to find, but I still can't find the right method that changes how custom types are displayed in the Rmd preview section.

I think I found it! The rendering method is rmarkdown::paged_table, but it doesn't appear that there's an easy way to specify how vectors should be converted to strings.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.