Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/r-lib/rprojroot
Finding files in project subdirectories
https://github.com/r-lib/rprojroot
Last synced: 4 days ago
JSON representation
Finding files in project subdirectories
- Host: GitHub
- URL: https://github.com/r-lib/rprojroot
- Owner: r-lib
- License: other
- Created: 2015-05-19T02:10:40.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-11-09T05:16:34.000Z (5 days ago)
- Last Synced: 2024-11-09T06:20:07.035Z (5 days ago)
- Language: R
- Homepage: https://rprojroot.r-lib.org/
- Size: 1.06 MB
- Stars: 149
- Watchers: 8
- Forks: 23
- Open Issues: 2
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
- jimsghstars - r-lib/rprojroot - Finding files in project subdirectories (R)
README
---
output:
github_document:
html_preview: false
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)set.seed(20230702)
clean_output <- function(x, options) {
# Side effect
usethis::use_build_ignore("index.md")x <- gsub("0x[0-9a-f]+", "0xdeadbeef", x)
x <- gsub("dataframe_[0-9]*_[0-9]*", " dataframe_42_42 ", x)
x <- gsub("[0-9]*\\.___row_number ASC", "42.___row_number ASC", x)index <- x
index <- gsub("─", "-", index)
index <- strsplit(paste(index, collapse = "\n"), "\n---\n")[[1]][[2]]
writeLines(index, "index.md")x <- fansi::strip_sgr(x)
x
}options(cli.num_colors = 256)
local({
hook_source <- knitr::knit_hooks$get("document")
knitr::knit_hooks$set(document = clean_output)
})rlang::local_interactive(FALSE)
```# [rprojroot](https://rprojroot.r-lib.org/)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![rcc](https://github.com/r-lib/rprojroot/workflows/rcc/badge.svg)](https://github.com/r-lib/rprojroot/actions)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/rprojroot)](https://cran.r-project.org/package=rprojroot)
[![Codecov test coverage](https://codecov.io/gh/r-lib/rprojroot/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/rprojroot?branch=main)This package helps accessing files relative to a *project root* to [stop the working directory insanity](https://gist.github.com/jennybc/362f52446fe1ebc4c49f).
It is a low-level helper package for the [here](https://here.r-lib.org/) package.```{r}
library(rprojroot)
```## Example
The rprojroot package works best when you have a "project": all related files contained in a subdirectory that can be categorized using a strict criterion.
Let's create a package for demonstration.```{r}
dir <- tempfile()
pkg <- usethis::create_package(dir)
```R packages satisfy the `is_r_package` criterion.
A criterion is an object that contains a `find_file()` function.
With `pkg` as working directory, the function works like `file.path()`, rooted at the working directory:```{r}
setwd(pkg)
is_r_package
is_r_package$find_file()
is_r_package$find_file("tests", "testthat")
```This works identically when starting from a subdirectory:
```{r}
setwd(file.path(pkg, "R"))
is_r_package$find_file()
is_r_package$find_file("tests", "testthat")
```There is one exception: if the first component passed to `find_file()` is already an absolute path.
This allows safely applying this function to paths that may be absolute or relative:```{r}
setwd(file.path(pkg, "R"))
path <- is_r_package$find_file()
is_r_package$find_file(path, "tests", "testthat")
```As long as you are sure that your working directory is somewhere inside your project, you can retrieve the project root.
## Installation and further reading
Install the package from CRAN:
``` r
install.package("rprojroot")
```See the [documentation](https://rprojroot.r-lib.org/articles/rprojroot.html) for more detail.
---
## Code of Conduct
Please note that the rprojroot project is released with a [Contributor Code of Conduct](https://rprojroot.r-lib.org/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.