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"))
The goal of perlbrewr is to assist the loading of a perlbrew
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
.
You can install the released version of perlbrewr from GitHub with:
devtools::install_github("kiwiroy/perlbrewr")
This is a basic example of usage to load a perlbrew environment:
params$perl_version
= r params$perl_version
library(perlbrewr) result <- perlbrew(root = Sys.getenv("PERLBREW_ROOT"), version = params$perl_version)
The brewed version of perl is now the default.
Sys.which("perl")
This is also the case in bash
shell blocks.
which perl
By configuring knitr
- this happens automatically by default.
knitr::opts_chunk$set(engine.path = list(perl = Sys.which("perl")[["perl"]]))
Perl code in perl
blocks run the same interpreter.
print "$^X\n";
Perlbrew supports local::lib
libraries for further controlling which modules are installed. perlbrewr
supports loading these also.
perlbrew_lib_create(version = params$perl_version, lib = "example")
perlbrew(version = params$perl_version, lib = "example") Sys.getenv("PERL5LIB")
Within this local::lib
modules may be installed with cpanm
.
cd inst cpanm -n -q --installdeps .
Since perlbrewr::perlbrew
sets the PERL5LIB
environment variable perl code
relying on the dependencies is now sucessful.
use Mojo::Base -strict; use Mojo::File; say Mojo::File->new('inst/cpanfile')->slurp;
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.
perlbrew_list()
A new library is created with perlbrew_lib_create
.
perlbrew_list()
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.
knitr::opts_chunk$set(engine.opts = list(perl = "-CS", bash = "--norc"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.