-
Notifications
You must be signed in to change notification settings - Fork 23
/
README.Rmd
120 lines (86 loc) · 3.39 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
output:
github_document:
html_preview: false
---
<!-- README.md and index.md are generated from README.Rmd. Please edit that file. -->
```{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/)
<!-- badges: start -->
[![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)
<!-- badges: end -->
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.