-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
67 lines (55 loc) · 2.04 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
---
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-"
)
```
[](https://cran.r-project.org/package=types)
[](https://travis-ci.org/jimhester/types)
[](https://codecov.io/github/jimhester/types?branch=master)
[](https://ci.appveyor.com/project/jimhester/types)
## Types for R ##
This package provides a simple type annotation for R that is usable in scripts,
in the R console and in packages. It is intended as a convention to allow other
packages or IDE's to use the type information to provide error checking,
automatic documentation or optimizations.
The annotations are syntactically valid R code rather than comments, which
provides additional assurance they are specified properly. However this package
does not do anything with the type annotations, they have no effect on the
calculated result.
`?` when used on the command line continues to work as before, accessing the R
help pages for the topic requested.
## Examples ##
Function arguments can be annotated with types
```{r}
f <- function(x = 1 ? numeric) {
x + 1
}
```
Default arguments can also be annotated (the `=` is required however)
```{r}
f <- function(x = ? numeric) {
x + 1
}
```
Function statements can be annotated with types
```{r}
f <- function(x = "Yay") {
paste(x, "types!") ? character
}
```
Function return values can be annotated with types
```{r}
f <- function(x = 1) {
x %% 2 == 0
} ? boolean
```
## Prior work ##
The [argufy package](https://github.com/gaborcsardi/argufy#readme) by Gábor
Csárdi was an exploration of typed arguments and was the original impetus of
the `?` syntax.