You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.Rmd
+43-12Lines changed: 43 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ options(width =100)
18
18
19
19
This document describes `wrapr`, an [R](https://cran.r-project.org) package available from [Github](https://github.com/WinVector/wrapr) (via `devtools::install_github("WinVector/wrapr")`) and [CRAN](https://CRAN.R-project.org/) (via `install.packages("wrapr")`).
20
20
21
-
Note: `wrapr` is meant only for "tame names" that is variables and column names that are also valid *simple* (without quotes) `R` variables names.
21
+
Note: `wrapr` is meant only for "tame names", that is: variables and column names that are also valid *simple* (without quotes) `R` variables names.
22
22
23
23
## Introduction
24
24
@@ -30,14 +30,16 @@ Note: `wrapr` is meant only for "tame names" that is variables and column names
30
30
31
31
Primary `wrapr` services include:
32
32
33
-
*`wrapr::let()`
34
-
*`wrapr::%.>%` (dot arrow pipe)
35
-
*`wrapr::DebugFnW()`
33
+
*`let()`
34
+
*`%.>%` (dot arrow pipe)
35
+
*`:=` (named map builder)
36
+
*`λ()` (anonymous function builder)
37
+
*`DebugFnW()`
36
38
37
39
38
-
## `wrapr::let()`
40
+
## `let()`
39
41
40
-
`wrapr::let()` allows execution of arbitrary code with substituted variable names (note this is subtly different than binding values for names as with `base::substitute()` or `base::with()`).
42
+
`let()` allows execution of arbitrary code with substituted variable names (note this is subtly different than binding values for names as with `base::substitute()` or `base::with()`).
41
43
42
44
The function is simple and powerful. It treats strings as variable names and re-writes expressions as if you had used the denoted variables. For example the following block of code is equivalent to having written "`a + a`".
43
45
@@ -55,7 +57,7 @@ let(
55
57
56
58
This is useful in re-adapting non-standard evaluation interfaces (NSE interfaces) so one can script or program over them.
57
59
58
-
We are trying to make `wrapr::let()` self teaching and self documenting (to the extent that makes sense). For example try the arguments "`eval=FALSE`" prevent execution and see what *would* have been executed, or `debug=TRUE` to have the replaced code printed in addition to being executed:
60
+
We are trying to make `let()` self teaching and self documenting (to the extent that makes sense). For example try the arguments "`eval=FALSE`" prevent execution and see what *would* have been executed, or `debug=TRUE` to have the replaced code printed in addition to being executed:
59
61
60
62
```{r exwp}
61
63
let(
@@ -77,17 +79,17 @@ let(
77
79
78
80
Please see `vignette('let', package='wrapr')` for more examples. For working with `dplyr` 0.7.* we also suggest taking a look at an alternate approach called [`seplyr`](https://github.com/WinVector/seplyr/blob/master/README.md).
79
81
80
-
## `wrapr::%.>%` (dot arrow pipe)
82
+
## `%.>%` (dot arrow pipe)
81
83
82
-
`wrapr::%.>%` dot arrow pipe is a strict pipe with intended semantics:
84
+
`%.>%` dot arrow pipe is a strict pipe with intended semantics:
83
85
84
86
85
87
> "`a %.>% b`" is to be treated
86
88
> as if the user had written "`{ . <- a; b };`"
87
89
> with "`%.>%`" being treated as left-associative,
88
90
> and `.`-side effects removed.
89
91
90
-
That is: `%.>%` does not alter any function arguments that are not explicitly named. It is not defined as `a %.% b ~ b(a)` (roughly `dplyr`'s original pipe) or as the large set of differing cases constituting `magrittr::%>%`. `wrapr::%.>%` is designed to be explicit and simple.
92
+
That is: `%.>%` does not alter any function arguments that are not explicitly named. It is not defined as `a %.% b ~ b(a)` (roughly `dplyr`'s original pipe) or as the large set of differing cases constituting `magrittr::%>%`. `%.>%` is designed to be explicit and simple.
91
93
92
94
The effect looks is show below.
93
95
@@ -101,8 +103,37 @@ cos(exp(sin(4)))
101
103
102
104
Please see ["In Praise of Syntactic Sugar"](http://www.win-vector.com/blog/2017/07/in-praise-of-syntactic-sugar/) for more details.
103
105
106
+
## `:=`
104
107
105
-
## `wrapr::DebugFnW()`
108
+
`:=` is the "named map builder". It allows code such as the following.
106
109
107
-
`wrapr::DebugFnW()` wraps a function for debugging. If the function throws an exception the execution context (function arguments, function name, and more) is captured and stored for the user. The function call can then be reconstituted, inspected and even re-run with a step-debugger. Please see `vignette('DebugFnW', package='wrapr')` for examples.
110
+
```{r nmv1}
111
+
c('a', 'b') := c('x', 'y')
112
+
113
+
c('a' := 'x', 'b' := 'y')
114
+
```
115
+
116
+
The important property of named map builder is it accepts values on the left-hand side allowing the following:
117
+
118
+
```{r nmb2}
119
+
name <- 'variableNameFromElseWhere'
120
+
name := 'newBinding'
121
+
```
122
+
123
+
## `λ()`
124
+
125
+
`λ()` is a concise abstract function creator. It is a placeholder
126
+
that allows the use of the λ-character for very concise function
127
+
abstraction.
128
+
129
+
Example:
130
+
131
+
```{r lambda1}
132
+
# square numbers 1 through 4
133
+
sapply(1:4, λ(x, x^2))
134
+
```
135
+
136
+
## `DebugFnW()`
137
+
138
+
`DebugFnW()` wraps a function for debugging. If the function throws an exception the execution context (function arguments, function name, and more) is captured and stored for the user. The function call can then be reconstituted, inspected and even re-run with a step-debugger. Please see `vignette('DebugFnW', package='wrapr')` for examples.
Copy file name to clipboardExpand all lines: README.md
+54-15Lines changed: 54 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
<!-- README.md is generated from README.Rmd. Please edit that file -->
3
3
This document describes `wrapr`, an [R](https://cran.r-project.org) package available from [Github](https://github.com/WinVector/wrapr) (via `devtools::install_github("WinVector/wrapr")`) and [CRAN](https://CRAN.R-project.org/) (via `install.packages("wrapr")`).
4
4
5
-
Note: `wrapr` is meant only for "tame names" that is variables and column names that are also valid *simple* (without quotes) `R` variables names.
5
+
Note: `wrapr` is meant only for "tame names", that is: variables and column names that are also valid *simple* (without quotes) `R` variables names.
6
6
7
7
Introduction
8
8
------------
@@ -13,14 +13,16 @@ Introduction
13
13
14
14
Primary `wrapr` services include:
15
15
16
-
-`wrapr::let()`
17
-
-`wrapr::%.>%` (dot arrow pipe)
18
-
-`wrapr::DebugFnW()`
16
+
-`let()`
17
+
-`%.>%` (dot arrow pipe)
18
+
-`:=` (named map builder)
19
+
-`λ()` (anonymous function builder)
20
+
-`DebugFnW()`
19
21
20
-
`wrapr::let()`
21
-
--------------
22
+
`let()`
23
+
-------
22
24
23
-
`wrapr::let()` allows execution of arbitrary code with substituted variable names (note this is subtly different than binding values for names as with `base::substitute()` or `base::with()`).
25
+
`let()` allows execution of arbitrary code with substituted variable names (note this is subtly different than binding values for names as with `base::substitute()` or `base::with()`).
24
26
25
27
The function is simple and powerful. It treats strings as variable names and re-writes expressions as if you had used the denoted variables. For example the following block of code is equivalent to having written "`a + a`".
26
28
@@ -39,7 +41,7 @@ let(
39
41
40
42
This is useful in re-adapting non-standard evaluation interfaces (NSE interfaces) so one can script or program over them.
41
43
42
-
We are trying to make `wrapr::let()` self teaching and self documenting (to the extent that makes sense). For example try the arguments "`eval=FALSE`" prevent execution and see what *would* have been executed, or `debug=TRUE` to have the replaced code printed in addition to being executed:
44
+
We are trying to make `let()` self teaching and self documenting (to the extent that makes sense). For example try the arguments "`eval=FALSE`" prevent execution and see what *would* have been executed, or `debug=TRUE` to have the replaced code printed in addition to being executed:
43
45
44
46
```r
45
47
let(
@@ -68,14 +70,14 @@ let(
68
70
69
71
Please see `vignette('let', package='wrapr')` for more examples. For working with `dplyr` 0.7.\* we also suggest taking a look at an alternate approach called [`seplyr`](https://github.com/WinVector/seplyr/blob/master/README.md).
70
72
71
-
`wrapr::%.>%` (dot arrow pipe)
72
-
------------------------------
73
+
`%.>%` (dot arrow pipe)
74
+
-----------------------
73
75
74
-
`wrapr::%.>%` dot arrow pipe is a strict pipe with intended semantics:
76
+
`%.>%` dot arrow pipe is a strict pipe with intended semantics:
75
77
76
78
> "`a %.>% b`" is to be treated as if the user had written "`{ . <- a; b };`" with "`%.>%`" being treated as left-associative, and `.`-side effects removed.
77
79
78
-
That is: `%.>%` does not alter any function arguments that are not explicitly named. It is not defined as `a %.% b ~ b(a)` (roughly `dplyr`'s original pipe) or as the large set of differing cases constituting `magrittr::%>%`. `wrapr::%.>%` is designed to be explicit and simple.
80
+
That is: `%.>%` does not alter any function arguments that are not explicitly named. It is not defined as `a %.% b ~ b(a)` (roughly `dplyr`'s original pipe) or as the large set of differing cases constituting `magrittr::%>%`. `%.>%` is designed to be explicit and simple.
79
81
80
82
The effect looks is show below.
81
83
@@ -91,7 +93,44 @@ cos(exp(sin(4)))
91
93
92
94
Please see ["In Praise of Syntactic Sugar"](http://www.win-vector.com/blog/2017/07/in-praise-of-syntactic-sugar/) for more details.
93
95
94
-
`wrapr::DebugFnW()`
95
-
-------------------
96
+
`:=`
97
+
----
96
98
97
-
`wrapr::DebugFnW()` wraps a function for debugging. If the function throws an exception the execution context (function arguments, function name, and more) is captured and stored for the user. The function call can then be reconstituted, inspected and even re-run with a step-debugger. Please see `vignette('DebugFnW', package='wrapr')` for examples.
99
+
`:=` is the "named map builder". It allows code such as the following.
100
+
101
+
```r
102
+
c('a', 'b') := c('x', 'y')
103
+
# a b
104
+
# "x" "y"
105
+
106
+
c('a':='x', 'b':='y')
107
+
# a b
108
+
# "x" "y"
109
+
```
110
+
111
+
The important property of named map builder is it accepts values on the left-hand side allowing the following:
112
+
113
+
```r
114
+
name<-'variableNameFromElseWhere'
115
+
name:='newBinding'
116
+
# variableNameFromElseWhere
117
+
# "newBinding"
118
+
```
119
+
120
+
`λ()`
121
+
-----
122
+
123
+
`λ()` is a concise abstract function creator. It is a placeholder that allows the use of the λ-character for very concise function abstraction.
124
+
125
+
Example:
126
+
127
+
```r
128
+
# square numbers 1 through 4
129
+
sapply(1:4, λ(x, x^2))
130
+
# [1] 1 4 9 16
131
+
```
132
+
133
+
`DebugFnW()`
134
+
------------
135
+
136
+
`DebugFnW()` wraps a function for debugging. If the function throws an exception the execution context (function arguments, function name, and more) is captured and stored for the user. The function call can then be reconstituted, inspected and even re-run with a step-debugger. Please see `vignette('DebugFnW', package='wrapr')` for examples.
0 commit comments