3 Knitting


3.0.1 Why won’t my code knit? Everything works in markdown and then it breaks when I knit.

  • Are all the libraries loaded from within the R code? Having the library loaded in your workspace but not within the code won’t work. Always load libraries from within the R code.

  • Are all the data files loaded from within the R code? Do not use the file -> import dataset pathway. You must load the data file from within the R code.

  • Try restarting the R session and running all chunks. Sometimes rerunning the code can fix errors that were introduced from running code out of order. Remember that when a file is knit it runs through the code from top to bottom. This is why it’s often best practice to load libraries and datasets at the beginning of a script.

  • Double check the yaml or header of the document. Is the output the right format? Are the correct header items there?

3.0.2 Why does my knit document look weird?

  • Check the spacing in between text, R chunks, and headings. There needs to be a hard return or line break between a content chunk and the subsequent header. Remember that you can tell where a line of code begins and ends by looking at the row numbers on the left side of the R script.