-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
147 lines (112 loc) · 4.33 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
output: github_document
params:
root: !r Sys.getenv("PERLBREW_ROOT")
perl_version: 5.24.3
---
[![Travis build status](https://travis-ci.org/kiwiroy/perlbrewr.svg?branch=master)](https://travis-ci.org/kiwiroy/perlbrewr)
[![Coverage status](https://coveralls.io/repos/github/kiwiroy/perlbrewr/badge.svg)](https://coveralls.io/r/kiwiroy/perlbrewr?branch=master)
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
<!-- README.md is generated from README.Rmd. Please edit that file -->
<!-- home: !r Sys.getenv("PERLBREW_HOME") -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
Sys.setenv("PERLBREW_ROOT"=params$root)
tmp <- file.path(tempdir(), ".perlbrew")
if(!dir.exists(tmp)) {
dir.create(tmp)
}
Sys.setenv("PERLBREW_HOME"=tmp)
Sys.setenv("perlbrew_command"=file.path(params$root, "bin", "perlbrew"))
```
# perlbrewr
The goal of perlbrewr is to assist the loading of a [perlbrew](https://perlbrew.pl)
perl and optionally a library with the aim of improving reproducibility. The
central task that perlbrewr performs is management of the environment variables
in the same manner as perlbrew itself, by calling perlbrew commands and
translating the changes there into R function calls that achieve the same
outcome. Primarily, these are `Sys.setenv` and `Sys.unsetenv`.
## Dependencies
### R
* R (>= 3.3.0)
* magrittr
* stringr
### Non R
* [perlbrew](https://perlbrew.pl)
## Installation
You can install the released version of perlbrewr from [GitHub](https://github.com/kiwiroy/perlbrewr) with:
``` r
devtools::install_github("kiwiroy/perlbrewr")
```
## Example
This is a basic example of usage to load a perlbrew environment:
`params$perl_version` = ``r params$perl_version``
```{r example}
library(perlbrewr)
result <- perlbrew(root = Sys.getenv("PERLBREW_ROOT"), version = params$perl_version)
```
The brewed version of perl is now the default.
```{r perlversion}
Sys.which("perl")
```
This is also the case in `bash` shell blocks.
```{r perlversion-in-bash, engine = "bash"}
which perl
```
By configuring `knitr` - this happens automatically by default.
```{r knitr-config}
knitr::opts_chunk$set(engine.path = list(perl = Sys.which("perl")[["perl"]]))
```
Perl code in `perl` blocks run the same interpreter.
```{r perl-code, engine = "perl"}
print "$^X\n";
```
### local::lib library access
Perlbrew supports [`local::lib`](https://metacpan.org/pod/local::lib) libraries for further controlling which modules are installed. `perlbrewr` supports loading these also.
```{r create-lib, include=FALSE}
perlbrew_lib_create(version = params$perl_version, lib = "example")
```
```{r use-lib}
perlbrew(version = params$perl_version, lib = "example")
Sys.getenv("PERL5LIB")
```
Within this `local::lib` modules may be installed with [`cpanm`](https://metacpan.org/pod/App::cpanminus).
```{r install-something, engine = "bash"}
cd inst
cpanm -n -q --installdeps .
```
Since `perlbrewr::perlbrew` sets the `PERL5LIB` environment variable perl code
relying on the dependencies is now sucessful.
```{r perl-code-2, engine = "perl"}
use Mojo::Base -strict;
use Mojo::File;
say Mojo::File->new('inst/cpanfile')->slurp;
```
### listing and creating libraries
```{r re-root, include = FALSE}
brew_list <- perlbrew_list()
if(length(brew_list) > 12) {
## This shortens the lists in the next two
root <- file.path(getwd(),"tests","testthat","mock")
pbcmd <- file.path(root, "bin", "perlbrew")
Sys.setenv("PERLBREW_ROOT"=root, "perlbrew_command"=pbcmd)
}
```
`perlbrew_list` returns a listing of the available versions of perl and any `local::lib` libraries. If a version or library is in use, the `active` object attribute is also set.
```{r perlbrew-list}
perlbrew_list()
```
A new library is created with `perlbrew_lib_create`.
```{r perlbrew-lib-create-show}
perlbrew_list()
```
### knitr
The knitr chunk options `engine.path` and `engine.opts` are set automatically so that each `engine="perl"` chunk will use the correct `perl` interpreter and `PERL5LIB`. Any `engine.opts` for perl that have already been set should remain in the list. For this to work correctly the `list()` version of the `engine.opts` should be used. i.e.
```r
knitr::opts_chunk$set(engine.opts = list(perl = "-CS", bash = "--norc"))
```