code chunks running but failing to knit

The error message you mention suggests the previous line of code is not present in your Rmd file itself or it is not being executed when knitted.

When you knit an Rmd document the code gets executed in a clean environment other than the one you are currently working on so the mentioned data frame doesn't exist there. You need to include the necessary code to import the data frame into memory, in your Rmd document itself.

If this doesn't solve your problem, please provide a proper REPRoducible EXample (reprex) illustrating your issue.