Organising your files into directories (folders) has the following advantages:
The here package enables you to reference files relative to the top-level directory, regardless of where that project directory is on your computer, or the cloud
For those familiar with R, if you use the here package, you never have to use getwd()
, setwd()
or file.path()
again!
here
packageInstall and load the here package with:
Your main project directory needs to contain an empty file called .here. This should be created automatically by RStudio when you save your project
Use the here()
function to check that your over-arching project directory is recognised correctly
At the top of every script, include a line which specifies the location of that script
For example, if your project directory is called LeafProject, tell R where the script file is *within that parent directory
Declaring the location of the script to R means that you will:
here()
inside other functionsNow when you need to reference a file within another function, you can use relative file paths
Hereβs an example with the readr packageβs read_tsv()
function, for importing data in text files
here()
function toβ¦