I am trying to write an R markdown script with a table in it and I am having trouble getting the document to knit properly.
This is the entirety of my markdown document (ignore the \s before the ticks it I need to escape ticks somehow).
---
title: "Extension Write Up"
author: "Kate Champion"
date: "2024-11-28"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
\```
Text to fill in later
```{r print_table}
setwd("my/working/directory/")
readRDS("02_code/table_1.rds")
table_1
\```
table_1
is a tinytable I saved out from a script that I want to be displayed inline in the final document. If I hit 'run current chunk' in the r print_table
section it works fine it calls the object and I can see it displayed in the Rmd file. But everytime I try to knit to a pdf I get an error (see below). Also I get the same results regardless if the last line is print(table_1)
or just table_1
.
|............................................. | 80% [print_table]
processing file: extension_writeup.Rmd
Error:
! object 'table_1' not found
Backtrace:
1. rmarkdown::render(...)
2. knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
3. knitr:::process_file(text, output)
6. knitr:::process_group(group)
7. knitr:::call_block(x)
...
14. base::withRestarts(...)
15. base (local) withRestartList(expr, restarts)
16. base (local) withOneRestart(withRestartList(expr, restarts[-nr]), restarts[[nr]])
17. base (local) docall(restart$handler, restartArgs)
19. evaluate (local) fun(base::quote(`<smplErrr>`))
Quitting from lines 16-19 [print_table] (extension_writeup.Rmd)
Execution halted
I am not sure why it's able to call the RDS object just fine when I run the chunk be itself but it fails when I try to knit the whole document.
Also my goal is to get a table in an Rmd file so if there is a better way to do that please let me know. Most of the examples I saw online had you running the full regression inside the markdown file before printing the results to a table but I don't want to put my full regression spec in the markdown because it's quite complicated. table_1
was generated using modelsummary
and tinytable
and then saved out using SaveRDS
. I would be ok saving my regression output and then generating the table directly in the markdown if that's the better route to go.