printing multiple objects from a single function in Rmarkdown


Need your advice on how to best approach this.

I am building a function, that would automatically generate multiple tables and graphs.

For example:
Table 1 - a summary table that compares two GLM objects

Table 2 - Model summary and model comparison coming from sjPlots

Then a graphs which would look something like this (4 charts arranged to be as one)

All the tables and charts are coming from a single function

There are two options now:
1 - use rmarkdown
2 - create pdf

I am leaning towards using rmarkdown for now.

Call_all_modelling_functions <- function(
  # If doesn't exist, create a list of CM and RM
  # Set RM and CM models
  # Summary table page
  # Returns ms_summary_table.  This needs to be printed into rmarkdown

  # Summary model page
  # returns model summary from sjPlots. This needs to be printed into rmarkdown

  # Variable plots  
  # Not developed yet
  # Residual plots
  # Not developed yet  

I then call this function in r chunk in markdown. Problem is, it prints only the last table/chart when knitting into html.

Can someone give me some guidelines on how to print all tables and charts from this single function?


This is because only the last printed content show in a knitr unless you really knit the content of the chunk. knit_child() is about that.

I would look at resource in this other topic

Basically using a R Markdown child document as template is what would be the easiest

You'll find more on this site about how to programatically create content.

Create a function that would fill your template, and run knit_child() on it to integrate the result in your main document.

Look at the cookbook to understand with some recipies how this all works.

1 Like

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.