Skip to content

Commit

Permalink
preare for CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMount committed Aug 24, 2017
1 parent 87101ea commit 272a87f
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 71 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Authors@R: c(
URL: https://github.com/WinVector/wrapr, http://winvector.github.io/wrapr/
Maintainer: John Mount <[email protected]>
BugReports: https://github.com/WinVector/wrapr/issues
Description: Provides 'DebugFnW()' to capture function context on error for
debugging, and 'let()' which converts non-standard evaluation interfaces to
parametric standard evaluation interfaces.
Description: Useful advanced R notations. Provides: 'let()' which converts non-standard evaluation interfaces to
parametric standard evaluation interface, 'DebugFnW()' to capture function context on error for
debugging, and ':=' named map builder, and lambda-abstraction.
License: GPL-3
Encoding: UTF-8
LazyData: true
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# wrapr 0.4.1 2017-08-24

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

# wrapr 0.4.0 2017-07-22

Expand Down
55 changes: 43 additions & 12 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ options(width =100)

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

Note: `wrapr` is meant only for "tame names" that is variables and column names that are also valid *simple* (without quotes) `R` variables names.
Note: `wrapr` is meant only for "tame names", that is: variables and column names that are also valid *simple* (without quotes) `R` variables names.

## Introduction

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

Primary `wrapr` services include:

* `wrapr::let()`
* `wrapr::%.>%` (dot arrow pipe)
* `wrapr::DebugFnW()`
* `let()`
* `%.>%` (dot arrow pipe)
* `:=` (named map builder)
* `λ()` (anonymous function builder)
* `DebugFnW()`


## `wrapr::let()`
## `let()`

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

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

Expand All @@ -55,7 +57,7 @@ let(

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

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

```{r exwp}
let(
Expand All @@ -77,17 +79,17 @@ let(

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

## `wrapr::%.>%` (dot arrow pipe)
## `%.>%` (dot arrow pipe)

`wrapr::%.>%` dot arrow pipe is a strict pipe with intended semantics:
`%.>%` dot arrow pipe is a strict pipe with intended semantics:


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

The effect looks is show below.

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

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

## `:=`

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

`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.
```{r nmv1}
c('a', 'b') := c('x', 'y')
c('a' := 'x', 'b' := 'y')
```

The important property of named map builder is it accepts values on the left-hand side allowing the following:

```{r nmb2}
name <- 'variableNameFromElseWhere'
name := 'newBinding'
```

## `λ()`

`λ()` is a concise abstract function creator. It is a placeholder
that allows the use of the λ-character for very concise function
abstraction.

Example:

```{r lambda1}
# square numbers 1 through 4
sapply(1:4, λ(x, x^2))
```

## `DebugFnW()`

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

69 changes: 54 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- README.md is generated from README.Rmd. Please edit that file -->
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")`).

Note: `wrapr` is meant only for "tame names" that is variables and column names that are also valid *simple* (without quotes) `R` variables names.
Note: `wrapr` is meant only for "tame names", that is: variables and column names that are also valid *simple* (without quotes) `R` variables names.

Introduction
------------
Expand All @@ -13,14 +13,16 @@ Introduction

Primary `wrapr` services include:

- `wrapr::let()`
- `wrapr::%.>%` (dot arrow pipe)
- `wrapr::DebugFnW()`
- `let()`
- `%.>%` (dot arrow pipe)
- `:=` (named map builder)
- `λ()` (anonymous function builder)
- `DebugFnW()`

`wrapr::let()`
--------------
`let()`
-------

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

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

Expand All @@ -39,7 +41,7 @@ let(

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

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

``` r
let(
Expand Down Expand Up @@ -68,14 +70,14 @@ let(

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

`wrapr::%.>%` (dot arrow pipe)
------------------------------
`%.>%` (dot arrow pipe)
-----------------------

`wrapr::%.>%` dot arrow pipe is a strict pipe with intended semantics:
`%.>%` dot arrow pipe is a strict pipe with intended semantics:

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

The effect looks is show below.

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

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

`wrapr::DebugFnW()`
-------------------
`:=`
----

`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.
`:=` is the "named map builder". It allows code such as the following.

``` r
c('a', 'b') := c('x', 'y')
# a b
# "x" "y"

c('a' := 'x', 'b' := 'y')
# a b
# "x" "y"
```

The important property of named map builder is it accepts values on the left-hand side allowing the following:

``` r
name <- 'variableNameFromElseWhere'
name := 'newBinding'
# variableNameFromElseWhere
# "newBinding"
```

`λ()`
-----

`λ()` is a concise abstract function creator. It is a placeholder that allows the use of the λ-character for very concise function abstraction.

Example:

``` r
# square numbers 1 through 4
sapply(1:4, λ(x, x^2))
# [1] 1 4 9 16
```

`DebugFnW()`
------------

`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.
2 changes: 1 addition & 1 deletion docs/articles/DebugFnW.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 272a87f

Please sign in to comment.