-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
90 lines (59 loc) · 2.84 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
---
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%"
)
```
# typos <img src="man/figures/logo.png" align="right" height=139 />
The goal of `typos` is to provide a flexible warning when commonly mis-typed functions are called. Functions with typing errors will still be evaluated and a warning will be output. It also provides the user with a convenient function to define their own typos.
## Installation
You can install the development version of `typos` from [GitHub](https://github.com/) with:
```
# install.packages("devtools")
devtools::install_github("MyKo101/typos")
```
## Example
For example, without `typos` installed, mistyping the functions `names()` as `nameS()` will throw an error.
```{r nameS-error, error=T}
nameS(mtcars)
```
But, with `typos`, the function is still evaluated, and rather than an Error, a Warning is produced.
```{r nameS-typo}
library(typos)
nameS(mtcars)
```
## Generating typos
The key to `typo` is the `.typo()` function. To generate a typo, we use the following syntax:
```
<incorrect spelling> <- .typo(<correct spelling>)
```
For example, the above `nameS` typo is generated with
```
nameS <- .typo(names)
```
## Wrapping
The way `.typo()` works is to generate a wrapper function around the correctly spelled function. This wrapper function sends a warning to the user, but still evaluates the "proper" function.
The wrapper function, `nameS` looks like this:
```{r Wrapper-nameS}
nameS
```
Notice that all the arguments passed to `nameS(...)` are forwarded on to `names(...)`
## Other packages
As well as the correctly spelled function, the `.typo()` function can take a `.package` argument (this will *always* be the second unnamed argument, so code can be neater). By default, this will be the `base` package, but *any* other package will need to be specified (this includes default packages like `stats`).
```{r}
Rnorm <- .typo(rnorm,stats)
```
Within the wrapper function, this changes two things. The argument passed to `requireNamespace()` will match this package, as will the "proper" function call
```{r Wrapper-Rnorm}
Rnorm
```
## Warning
Caution should be used if the misspelled version of your function already exists as a function in it's own right. The `.typo()` will overwrite the other "correct" function with the new typo function. For this reason, it is recommended that `typos` be the first package loaded to ensure functions loaded in other packages can overwrite the Exported typos provided here.
## Code of Conduct
Please note that the typos project is released with a [Contributor Code of Conduct](https://michaelbarrowman.co.uk/typos/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.