Problem knitting rmarkdown file

Your problem seems to be that you are skipping the part where you load "data" into memory. Have in mind that when you knit a file, the code gets executed in a clean environment so it is not going to have access to the data you already have in your current working environment, you have to explicitly include all the code needed to load the data from scratch.

Actually, the better way to go about this is not to share your actual code but to make a minimal REPRoducible EXample (reprex) representative of your issue.

BTW, I splited this thread into a new topic just for the sake of keeping things tidy. Topics should contained only a single reasonably well defined question or issue.