Skip to content

Commit 272a87f

Browse files
committed
preare for CRAN
1 parent 87101ea commit 272a87f

File tree

14 files changed

+171
-71
lines changed

14 files changed

+171
-71
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Authors@R: c(
1111
URL: https://github.com/WinVector/wrapr, http://winvector.github.io/wrapr/
1212
Maintainer: John Mount <[email protected]>
1313
BugReports: https://github.com/WinVector/wrapr/issues
14-
Description: Provides 'DebugFnW()' to capture function context on error for
15-
debugging, and 'let()' which converts non-standard evaluation interfaces to
16-
parametric standard evaluation interfaces.
14+
Description: Useful advanced R notations. Provides: 'let()' which converts non-standard evaluation interfaces to
15+
parametric standard evaluation interface, 'DebugFnW()' to capture function context on error for
16+
debugging, and ':=' named map builder, and lambda-abstraction.
1717
License: GPL-3
1818
Encoding: UTF-8
1919
LazyData: true

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# wrapr 0.4.1 2017-08-24
33

44
* Do not insist let-mapping be invertible.
5-
* Migrate named map builder and lambda from seplyr.de
5+
* Migrate named map builder and lambda from seplyr.
66

77
# wrapr 0.4.0 2017-07-22
88

README.Rmd

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ options(width =100)
1818

1919
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")`).
2020

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.
2222

2323
## Introduction
2424

@@ -30,14 +30,16 @@ Note: `wrapr` is meant only for "tame names" that is variables and column names
3030

3131
Primary `wrapr` services include:
3232

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()`
3638

3739

38-
## `wrapr::let()`
40+
## `let()`
3941

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()`).
4143

4244
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`".
4345

@@ -55,7 +57,7 @@ let(
5557

5658
This is useful in re-adapting non-standard evaluation interfaces (NSE interfaces) so one can script or program over them.
5759

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:
5961

6062
```{r exwp}
6163
let(
@@ -77,17 +79,17 @@ let(
7779

7880
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).
7981

80-
## `wrapr::%.>%` (dot arrow pipe)
82+
## `%.>%` (dot arrow pipe)
8183

82-
`wrapr::%.>%` dot arrow pipe is a strict pipe with intended semantics:
84+
`%.>%` dot arrow pipe is a strict pipe with intended semantics:
8385

8486

8587
> "`a %.>% b`" is to be treated
8688
> as if the user had written "`{ . &lt;- a; b };`"
8789
> with "`%.>%`" being treated as left-associative,
8890
> and `.`-side effects removed.
8991
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.
9193

9294
The effect looks is show below.
9395

@@ -101,8 +103,37 @@ cos(exp(sin(4)))
101103

102104
Please see ["In Praise of Syntactic Sugar"](http://www.win-vector.com/blog/2017/07/in-praise-of-syntactic-sugar/) for more details.
103105

106+
## `:=`
104107

105-
## `wrapr::DebugFnW()`
108+
`:=` is the "named map builder". It allows code such as the following.
106109

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.
108139

README.md

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- README.md is generated from README.Rmd. Please edit that file -->
33
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")`).
44

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.
66

77
Introduction
88
------------
@@ -13,14 +13,16 @@ Introduction
1313

1414
Primary `wrapr` services include:
1515

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()`
1921

20-
`wrapr::let()`
21-
--------------
22+
`let()`
23+
-------
2224

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()`).
2426

2527
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`".
2628

@@ -39,7 +41,7 @@ let(
3941

4042
This is useful in re-adapting non-standard evaluation interfaces (NSE interfaces) so one can script or program over them.
4143

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:
4345

4446
``` r
4547
let(
@@ -68,14 +70,14 @@ let(
6870

6971
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).
7072

71-
`wrapr::%.>%` (dot arrow pipe)
72-
------------------------------
73+
`%.>%` (dot arrow pipe)
74+
-----------------------
7375

74-
`wrapr::%.>%` dot arrow pipe is a strict pipe with intended semantics:
76+
`%.>%` dot arrow pipe is a strict pipe with intended semantics:
7577

7678
> "`a %.>% b`" is to be treated as if the user had written "`{ . &lt;- a; b };`" with "`%.>%`" being treated as left-associative, and `.`-side effects removed.
7779
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.
7981

8082
The effect looks is show below.
8183

@@ -91,7 +93,44 @@ cos(exp(sin(4)))
9193

9294
Please see ["In Praise of Syntactic Sugar"](http://www.win-vector.com/blog/2017/07/in-praise-of-syntactic-sugar/) for more details.
9395

94-
`wrapr::DebugFnW()`
95-
-------------------
96+
`:=`
97+
----
9698

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.

docs/articles/DebugFnW.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)