-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
123 lines (90 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
121
122
123
---
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%"
)
```
# watcher
<!-- badges: start -->
[![Travis build status](https://travis-ci.com/coatless/watcher.svg?branch=master)](https://travis-ci.com/coatless/watcher)
[![CRAN status](https://www.r-pkg.org/badges/version/watcher)](https://CRAN.R-project.org/package=watcher)
[![Codecov test coverage](https://codecov.io/gh/coatless/watcher/branch/master/graph/badge.svg)](https://codecov.io/gh/coatless/watcher?branch=master)
<!-- badges: end -->
The goal of watcher is to prevent _R_ packages from being used through
`library()` and `require()` calls. This is useful to prevent (un)intentional
use of packages not approved within a classroom, research, or company environment.
## Installation
<!--
You can install the released version of watcher from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("watcher")
```
Or, you can be on the cutting-edge development version on GitHub using: -->
This package is only available on GitHub. To install the package,
please use:
```{r gh-installation, eval = FALSE}
if(!requireNamespace("remotes")) install.packages("remotes")
remotes::install_github("coatless/watcher")
```
## Usage
To use the `watcher` package, load it into _R_ using:
```{r example}
library("watcher")
```
From there, any package that is on a blacklist will be prevented from
being loaded. The blacklist can be established on a per-session basis or
can be loaded as needed.
For example, let's say we didn't want to allow `toad` to be loaded. We would
call:
```{r add-pkg}
watch_pkg("toad")
```
If we attempted to load `toad` using either `library()` or `require()`, then
we would error:
```r
library("toad")
#> Detected {toad} package load...
#> The {toad} package is not allowed to be used.
#> Error in as.environment(lib.pos) : invalid 'pos' argument
require("toad")
#> Loading required package: toad
#> Detected {toad} package load...
#> The {toad} package is not allowed to be used.
#> Failed with error: 'invalid 'pos' argument'
```
All packages that are prohibited from being used can be viewed with:
```{r list-watches}
watchlist()
```
To allow the package to be used, we would need to remove the watch:
```{r remove-watch}
unwatch_pkg("toad")
```
Then, the package load would be allowed.
```r
library("toad")
```
## Motivation
When designing `watcher`, the goal was to achieve a "soft-failure" when
undesirable packages were loaded via `library()` or `require()`.
Generally, this follows in the footsteps of
[`strict`](https://github.com/hadley/strict)
-- which sought to raise issues with undesirable design patterns in code --
and, subsequently, [`conflicted`](https://github.com/r-lib/conflicted) --
which addressed search path collisions between similarly named functions in
different packages -- both by Hadley Wickham. With this being said,
there are better variants of protecting the _R_ process. Most notably, the
[`RAppArmor`](https://cran.r-project.org/package=RAppArmor) by Jeroen Ooms
provides superior sandboxing of _R_. Alternatively, the version of _R_
could simply not have these packages installed to begin with.
Fun fact: The code for this sat in an `untitled.R` file for ~2 years.
## Author
James Joseph Balamuta
## License
GPL (>= 2)