How to find the appropriate print function for an object

As I explained in Interactive data frames in rmarkdown::render() like RStudio's Preview (or, printing in Rmd) - #2 by cderv usually using knitr::knit_print() would help for printing inside knitr chunk . See Custom Print Methods

Otherwise regarding your question about print.<class>, this is how methods works. You call print(object) and R will check the class to apply the right method. If object is a ggplot one, then it will call print.ggplot()

Learn more about S3 class : 13 S3 | Advanced R

Not that complex when you understand how this works, and what is the logic. This is to me the safest if you need to loop through object that prints with a complex representation (Htmlwidgets, HTML tables, ...)