LilahMcC / NarwhalHR

0 stars 1 forks source link

Installing/loading packages #1

Open FlukeAndFeather opened 2 years ago

FlukeAndFeather commented 2 years ago

Excellent questions!

Installing packages should be done once at the console, not in a script. The install.packages() function has a pretty profound side effect (i.e., it substantially changes your system) so you don't want to re-run it all the time. I think you should remove all calls to install.packages() from the .Rmd.

Once you load a package (e.g., library(lubridate)) then it's loaded for the rest of the session. All the chunks in an .Rmd run in the same session, so you only need to do it once. I often include a chunk at the start of .Rmd files called setup where I make all my library calls. That way it's easy for other people to see which packages they need to knit the file. (Note: "other people" always includes "you a few months from now", so making things easy for other people is a great way to make things easy for yourself in the future.)

https://github.com/LilahMcC/NarwhalHR/blob/f785919009890dfdd8761fc94928078cd0c3d379/Depth%20Profiles.Rmd#L13-L14

LilahMcC commented 2 years ago

Great! Thank you! I changed this, so I think it's better now.