-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
91 lines (60 loc) · 1.63 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
---
output: github_document
---
<!-- README.md is 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%"
)
```
# wither
<!-- badges: start -->
[![R-CMD-check](https://github.com/torbjorn/wither/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/torbjorn/wither/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
Run a block or expression temporarily under a different `here()` root.
This is useful if you need to source R code from another project for
example (as might be the case with git submodules)
## Installation
You can install the development version of wither from
[GitHub](https://github.com/) with:
``` r
# install.packages("pak")
pak::pak("torbjorn/wither")
```
## Example
### with_here
`with_here()` evaluates an expression under a temporarily different
here root():
```{r example, eval=FALSE}
library(here)
library(wither)
was <- here()
d <- tempfile()
dir.create(d)
# have here() be somewhere else for an expression
is_now <- with_here(d, here())
stopifnot(normalizePath(was) != normalizePath(is_now))
# clean up
unlink(d, recursive=TRUE)
```
### local_here
`local_here()` evaluates the remainder of a block under a temporarily
different here root():
```{r example2, eval=FALSE}
library(here)
library(wither)
was <- here()
d <- tempfile()
dir.create(d)
local({
# have here() be somewhere else for the rest of the block
local_here(d)
is_now <- here()
stopifnot(normalizePath(was) != normalizePath(is_now))
})
# clean up
unlink(d, recursive=TRUE)
```