Part 39 here::here()

The here package is the best way to refer to files.

The major function is here::here(). Like file.path(), here::here() lets you specify a path to a file and then adds the system-appropriate separators (/ or \\).

Where here::here() shines is that it figures out where the relative paths should start from. It looks around in the folders in your directory and finds the .Rproj file, then constructs the relative file paths from there.

The .Rproj file is a sign post that says “START HERE”.

For example, create a new folder “data” in your participation folder. Then, save gap_asia_2007 using the here::here() and write_csv() functions:

write_csv(gap_asia_2007, 
          here::here("participation", "data", "gap_asia_2007.csv")
)

More details on here are available in this short article.