talira

Build file paths relative to your R project's root

open sourceMITfree

here builds paths to files relative to the top-level directory of an R project, instead of relying on setwd(), which breaks depending on where a script runs. You declare a file's place in the project with i_am() and use here() as a drop-in replacement for file.path(), so scripts and reports in different subdirectories read and write the same files.

Problems it solves

  • stop my R scripts breaking when they're run from a different working directory
  • refer to data files from R Markdown reports in subfolders of my project
  • avoid setwd() calls in shared R analysis projects

Features

  • here() as a drop-in replacement for file.path() relative to the project root
  • i_am() to declare a file's relative path in the project
  • shows the detected project root on load