We like to keep things tidy around here so please ask only one question per topic, if you have distinct questions you can always open a new topic.
I'm going to shortly adress your other questions. You should not include install commands in a Rmd file because you only need to install packages once, not every time you knit a document, you only need to load the packages with library().
About the missing data frame, when you knit a Rmd document the code gets executed in a clean environment other than the one you are currently working on so you have to include the necessary code to read the data frame into memory.
If you need further assistance with any of this, please open a new specific topic for it.