I'm writing a paper with bookdown (or at least trying to-its new to me!)
I have a stats chapter where I perform the stats, and another chapter where I discuss the results. Is there a way for me to display the table in the results chapter which I made in the stats chapter? The workaround I've been using is to have a chunk that calls the table I created before...is this the best way?
If you have a code chunk in a previous chapter that builds the table, you can also just refer to that chunk directly using a ref.label option in a chunk. So assuming you have labeled the original chunk that created the table in an earlier chapter, and let's say you called it create-table
```{r ref.label="create-table", echo=FALSE}
```
This isn't much different than your current approach but it might be a bit safer, in the case where you might accidentally overwrite the table object in some intermediate code.
Worth noting, this will only work if you use the default bookdown rendering approach of "merge-and-knit", rather than "knit-and-merge".
Oh and, sorry 1 more: if there are 2 tables in the same chunk, say 'create-table' chunk, can I specify which to show later on when I reference it? Or should I separate out the chunks?
You will be using M-K by default unless you have set the new_session: yes in the _bookdown.yml file.
Basically, when you use ref.label, the code from the previous code chunk will be "copy and pasted" into the new code chunk and will run the entire chunk (assuming eval isn't FALSE). So it will run everything and it might be wise to split the tables into separate chunks if that is what you need.