[1] "/Users/l.smith/Documents/Teaching/Emory/epi590r-2023"
{here}
packageFire safety, continued
setwd()
setwd()
changes the working directory, leading to potential issues in collaboration and reproducibility
It’s also really annoying to change your working directory when you move around files and folders, even if it’s just you using them
here
packageYou can also separate the file paths with /
:
Construct file paths with reference to the top directory holding your .Rproj
file.
here::here("data", "raw", "data.csv")
for me, here, becomes "/Users/l.smith/Documents/Teaching/Emory/epi590r-2023/data/raw/data.csv"
And if I send you my code to run, it will become whatever file path you need it to be, as long as you’re running it within the R Project.
here
packageis equivalent to
I just prefer to write out the package name whenever I need it, but you can load the package for your entire session if you want.
Install the {here}
package:
install.packages("here")
Make sure you’re in your in-class R project! In the console, run:
here::here()
to print your project directorygetwd()
to print your working directoryWhat do you notice?
In the console, run:
setwd("data")
to set your working directoryThen run the same lines as above. What do you notice?
.R
script from the website and use your file browser to put it in the R folder in your project.15:00