-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathREADME.Rmd
112 lines (79 loc) · 3.13 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
set.seed(1014)
```
# strict
[![Travis-CI Build Status](https://travis-ci.org/hadley/strict.svg?branch=master)](https://travis-ci.org/hadley/strict)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/strict)](https://cran.r-project.org/package=strict)
[![Coverage Status](https://img.shields.io/codecov/c/github/hadley/strict/master.svg)](https://codecov.io/github/hadley/strict?branch=master)
The goal of strict to make R behave a little more strictly, making base functions more likely to throw an error rather than returning potentially ambiguous results.
`library(strict)` forces you to confront potential problems now, instead of in the future. This has both pros and cons: often you can most easily fix a potential ambiguity when your working on the code (rather than in six months time when you've forgotten how it works), but it also forces you to resolve ambiguities that might never occur with your code/data.
## Installation
```{r, eval = FALSE}
# install.packages("devtools")
devtools::install_github("hadley/strict")
```
## Features
`library(strict)` affects code in the current script/session only (i.e. it doesn't affect code in others packages).
* An alternative conflict resolution mechanism. Instead of warning about
conflicts on package load and letting the last loaded package win,
strict throws an error when you access ambiguous functions:
```{r, error = TRUE}
library(strict)
library(plyr)
library(Hmisc)
is.discrete
```
(Thanks to @[krlmlr](https://github.com/krlmlr) for this neat idea!)
* Shims for functions with "risky" arguments, i.e. arguments that either rely
on global options (like `stringsAsFactors`) or have computed defaults that
90% evaluate to one thing (like `drop`). strict forces you to supply values
for these arguments.
```{r, error = TRUE}
library(strict)
mtcars[, 1]
data.frame(x = "a")
```
* Automatically sets options to warn when partial matching occurs.
```{r}
library(strict)
df <- data.frame(xyz = 1)
df$x
```
* `T` and `F` generate errors, forcing you to use `TRUE` and `FALSE`.
```{r, error = TRUE}
library(strict)
T
```
* `sapply()` throws an error suggesting that you use the type-safe
`vapply()` instead. `apply()` throws an error if you use it with a
data frame.
```{r, error = TRUE}
library(strict)
sapply(1:10, sum)
```
* `:` will throw an error instead of creating a decreasing sequence that
terminates in 0.
```{r, error = TRUE}
library(strict)
x <- numeric()
1:length(x)
```
* `diag()` and `sample()` throw an error if given scalar `x`. This avoids
an otherwise unpleasant surprise.
```{r, error = TRUE}
library(strict)
sample(5:3)
sample(5:4)
lax(sample(5:5))
sample(5:5)
```
Once strict is loaded, you can continue to run code in a lax manner using `lax()`.