This package helps accessing files relative to a project root to stop the working directory insanity.
The source for this text is in the readme subdirectory:
readme
basename(getwd()) #> [1] "readme"
How do we access the package root? In a robust fashion? Easily:
dir(rprojroot::find_root("DESCRIPTION")) #> [1] "_pkgdown.yml" "API" "appveyor.yml" #> [4] "cran-comments.md" "DESCRIPTION" "docs" #> [7] "inst" "Makefile" "man" #> [10] "NAMESPACE" "NEWS.md" "R" #> [13] "readme" "README.md" "revdep" #> [16] "rprojroot.Rproj" "tests" "tic.R" #> [19] "vignettes"
Install from GitHub:
devtools::install_github("r-lib/rprojroot")
See the documentation for more detail.