Skip to content

Commit 0374439

Browse files
committed
add locum
1 parent c511d8a commit 0374439

File tree

138 files changed

+2283
-1452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+2283
-1452
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: wrapr
22
Type: Package
33
Title: Wrap R Tools for Debugging and Parametric Programming
4-
Version: 1.8.9
5-
Date: 2019-07-24
4+
Version: 1.9.0
5+
Date: 2019-09-28
66
Authors@R: c(
77
person("John", "Mount", email = "[email protected]", role = c("aut", "cre")),
88
person("Nina", "Zumel", email = "[email protected]", role = c("aut")),

Examples/Locum/Locum.Rmd

Lines changed: 16 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -8,73 +8,16 @@ to both be an effective [`R`](https://www.r-project.org) function application pi
88
pipe effects.
99

1010
Let's take a look at implementing a new effect from a user perspective. The idea we want to implement is delayed evaluation through a
11-
collecting object we call a "locum" or stand-in. The locum is intended to collect operations without executing them, for later use.
11+
collecting object we call a "locum" or stand-in. The locum is intended to collect operations without executing them, for later use. This is similar to a lambda or function abstraction. The [code is now in the `wrapr` package](https://github.com/WinVector/wrapr/blob/master/R/locum.R), but could be implemented by any user as it uses only public or semi-public `wrapr` interfaces.
1212

13-
Let's start loading the `wrapr` package and defining our new `locum` class and its display methods.
13+
Let's start loading the `wrapr` package.
1414

1515
```{r}
1616
library(wrapr)
17-
18-
19-
locum <- function() {
20-
locum <- list(stages = list())
21-
class(locum) <- 'locum'
22-
return(locum)
23-
}
24-
25-
26-
format.locum <- function(x, ...) {
27-
args <- list(...)
28-
locum <- x
29-
start_name <- 'locum()'
30-
if('start' %in% names(args)) {
31-
start_name <- format(args[['start']])
32-
}
33-
stage_strs <- vapply(
34-
locum$stages,
35-
function(si) {
36-
format(si$pipe_right_arg)
37-
}, character(1))
38-
stage_strs <- c(list(start_name),
39-
stage_strs)
40-
return(paste(stage_strs,
41-
collapse = " %.>%\n "))
42-
}
43-
44-
45-
as.character.locum <- function(x, ...) {
46-
return(format(x, ...))
47-
}
48-
49-
50-
print.locum <- function(x, ...) {
51-
cat(format(x, ...))
52-
}
5317
```
5418

55-
Using the `wrapr` `apply_left` interface we can define an object that collects pipe stages from the left.
56-
57-
```{r}
58-
apply_left.locum <- function(
59-
pipe_left_arg,
60-
pipe_right_arg,
61-
pipe_environment,
62-
left_arg_name,
63-
pipe_string,
64-
right_arg_name) {
65-
locum <- pipe_left_arg
66-
capture <- list(
67-
pipe_right_arg = force(pipe_right_arg),
68-
pipe_environment = force(pipe_environment),
69-
left_arg_name = force(left_arg_name),
70-
pipe_string = force(pipe_string),
71-
right_arg_name = force(right_arg_name))
72-
locum$stages <- c(locum$stages, list(capture))
73-
return(locum)
74-
}
75-
```
7619

77-
We can now use the `locum` to collect the operations, and then print them.
20+
We can use the `locum` to collect the operations, and then print them.
7821

7922
```{r}
8023
y <- 4
@@ -86,46 +29,22 @@ p <- locum() %.>%
8629
print(p)
8730
```
8831

89-
We can use `wrapr`'s `apply_right` interface to define how the `locum` itself operates on values.
90-
91-
```{r}
92-
apply_right.locum <- function(
93-
pipe_left_arg,
94-
pipe_right_arg,
95-
pipe_environment,
96-
left_arg_name,
97-
pipe_string,
98-
right_arg_name) {
99-
force(pipe_left_arg)
100-
locum <- pipe_right_arg
101-
for(s in locum$stages) {
102-
pipe_left_arg <- pipe_impl(
103-
pipe_left_arg,
104-
s$pipe_right_arg,
105-
s$pipe_environment,
106-
pipe_string = s$pipe_string)
107-
}
108-
return(pipe_left_arg)
109-
}
110-
```
111-
112-
And we can now replace the `locum` with the value we want to apply the pipeline to.
32+
We can now replace the `locum` with the value we want to apply the pipeline to.
11333

11434
```{r}
11535
5 %.>% p
11636
```
11737

11838
This yields the same answer as the following function application.
11939

120-
12140
```{r}
12241
atan2(cos(sin(5)), 4)
12342
```
12443

12544
We can also add later intended arguments to the pipeline formatting.
12645

12746
```{r}
128-
print(p, 'start' = 5)
47+
print(p, 'start' = 4)
12948
```
13049

13150
We can do some fun things, such as combining `locum` pipelines.
@@ -134,10 +53,20 @@ We can do some fun things, such as combining `locum` pipelines.
13453
p1 <- locum() %.>% sin(.)
13554
p2 <- locum() %.>% cos(.)
13655
137-
p1 %.>% p2
56+
p12 <- p1 %.>% p2
57+
p12
58+
```
59+
60+
```{r}
61+
4 %.>% p12
62+
```
63+
64+
```{r}
65+
cos(sin(4))
13866
```
13967

14068

69+
14170
The idea is: `wrapr` dot arrow pipe is designed for expansion through the `apply_right`, `apply_left` `S3` interfaces, and the `apply_right_S4` `S4` interface. And users can access the implementation through the `pipe_impl` function. [This example](https://github.com/WinVector/wrapr/blob/master/Examples/Locum/Locum.md) and [the formal article](https://journal.r-project.org/archive/2018/RJ-2018-042/index.html) should give users a good place to start. [`rquery`](https://github.com/WinVector/rquery), [`rqdatatable`](https://github.com/WinVector/rqdatatable), and [`cdata`](https://github.com/WinVector/cdata) already use the extension interfaces to implement interesting features.
14271

14372

Examples/Locum/Locum.md

Lines changed: 24 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -10,76 +10,19 @@ effects.
1010
Let’s take a look at implementing a new effect from a user perspective.
1111
The idea we want to implement is delayed evaluation through a collecting
1212
object we call a “locum” or stand-in. The locum is intended to collect
13-
operations without executing them, for later use.
13+
operations without executing them, for later use. This is similar to a
14+
lambda or function abstraction. The [code is now in the `wrapr`
15+
package](https://github.com/WinVector/wrapr/blob/master/R/locum.R), but
16+
could be implemented by any user as it uses only public or semi-public
17+
`wrapr` interfaces.
1418

15-
Let’s start loading the `wrapr` package and defining our new `locum`
16-
class and its display methods.
19+
Let’s start loading the `wrapr` package.
1720

1821
``` r
1922
library(wrapr)
20-
21-
22-
locum <- function() {
23-
locum <- list(stages = list())
24-
class(locum) <- 'locum'
25-
return(locum)
26-
}
27-
28-
29-
format.locum <- function(x, ...) {
30-
args <- list(...)
31-
locum <- x
32-
start_name <- 'locum()'
33-
if('start' %in% names(args)) {
34-
start_name <- format(args[['start']])
35-
}
36-
stage_strs <- vapply(
37-
locum$stages,
38-
function(si) {
39-
format(si$pipe_right_arg)
40-
}, character(1))
41-
stage_strs <- c(list(start_name),
42-
stage_strs)
43-
return(paste(stage_strs,
44-
collapse = " %.>%\n "))
45-
}
46-
47-
48-
as.character.locum <- function(x, ...) {
49-
return(format(x, ...))
50-
}
51-
52-
53-
print.locum <- function(x, ...) {
54-
cat(format(x, ...))
55-
}
5623
```
5724

58-
Using the `wrapr` `apply_left` interface we can define an object that
59-
collects pipe stages from the left.
60-
61-
``` r
62-
apply_left.locum <- function(
63-
pipe_left_arg,
64-
pipe_right_arg,
65-
pipe_environment,
66-
left_arg_name,
67-
pipe_string,
68-
right_arg_name) {
69-
locum <- pipe_left_arg
70-
capture <- list(
71-
pipe_right_arg = force(pipe_right_arg),
72-
pipe_environment = force(pipe_environment),
73-
left_arg_name = force(left_arg_name),
74-
pipe_string = force(pipe_string),
75-
right_arg_name = force(right_arg_name))
76-
locum$stages <- c(locum$stages, list(capture))
77-
return(locum)
78-
}
79-
```
80-
81-
We can now use the `locum` to collect the operations, and then print
82-
them.
25+
We can use the `locum` to collect the operations, and then print them.
8326

8427
``` r
8528
y <- 4
@@ -96,31 +39,7 @@ print(p)
9639
## cos(.) %.>%
9740
## atan2(., y)
9841

99-
We can use `wrapr`’s `apply_right` interface to define how the `locum`
100-
itself operates on values.
101-
102-
``` r
103-
apply_right.locum <- function(
104-
pipe_left_arg,
105-
pipe_right_arg,
106-
pipe_environment,
107-
left_arg_name,
108-
pipe_string,
109-
right_arg_name) {
110-
force(pipe_left_arg)
111-
locum <- pipe_right_arg
112-
for(s in locum$stages) {
113-
pipe_left_arg <- pipe_impl(
114-
pipe_left_arg,
115-
s$pipe_right_arg,
116-
s$pipe_environment,
117-
pipe_string = s$pipe_string)
118-
}
119-
return(pipe_left_arg)
120-
}
121-
```
122-
123-
And we can now replace the `locum` with the value we want to apply the
42+
We can now replace the `locum` with the value we want to apply the
12443
pipeline to.
12544

12645
``` r
@@ -140,10 +59,10 @@ atan2(cos(sin(5)), 4)
14059
We can also add later intended arguments to the pipeline formatting.
14160

14261
``` r
143-
print(p, 'start' = 5)
62+
print(p, 'start' = 4)
14463
```
14564

146-
## 5 %.>%
65+
## 4 %.>%
14766
## sin(.) %.>%
14867
## cos(.) %.>%
14968
## atan2(., y)
@@ -154,13 +73,26 @@ We can do some fun things, such as combining `locum` pipelines.
15473
p1 <- locum() %.>% sin(.)
15574
p2 <- locum() %.>% cos(.)
15675

157-
p1 %.>% p2
76+
p12 <- p1 %.>% p2
77+
p12
15878
```
15979

16080
## locum() %.>%
16181
## sin(.) %.>%
16282
## cos(.)
16383

84+
``` r
85+
4 %.>% p12
86+
```
87+
88+
## [1] 0.7270351
89+
90+
``` r
91+
cos(sin(4))
92+
```
93+
94+
## [1] 0.7270351
95+
16496
The idea is: `wrapr` dot arrow pipe is designed for expansion through
16597
the `apply_right`, `apply_left` `S3` interfaces, and the
16698
`apply_right_S4` `S4` interface. And users can access the implementation

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
# wrapr 1.9.0 2019-09-28
3+
4+
* Add locum ( https://github.com/WinVector/wrapr/blob/master/Examples/Locum/Locum.md ).
5+
26
# wrapr 1.8.9 2019-07-24
37

48
* More unit tests.

cran-comments.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,36 @@
55

66
### Windows
77

8-
devtools::check_win_devel()
9-
* using R Under development (unstable) (2019-07-05 r76784)
10-
* using platform: x86_64-w64-mingw32 (64-bit)
11-
Status: OK
12-
8+
rhub::check_for_cran()
9+
507#> * using R Under development (unstable) (2019-09-18 r77193)
10+
508#> * using platform: x86_64-w64-mingw32 (64-bit)
11+
509#> * using session charset: ISO8859-1
12+
510#> * using option '--as-cran'
13+
511#> * checking for file 'wrapr/DESCRIPTION' ... OK
14+
512#> * checking extension type ... Package
15+
513#> * this is package 'wrapr' version '1.9.0'
16+
514#> * package encoding: UTF-8
17+
515#> * checking CRAN incoming feasibility ... Note_to_CRAN_maintainers
18+
516#> Maintainer: 'John Mount '
19+
558#> * checking sizes of PDF files under 'inst/doc' ... NOTE
20+
559#> Unable to find GhostScript executable to run checks on size reduction
21+
574#> Status: 1 NOTE
22+
Note: is property of the check installation, not the package.
23+
1324
### MacOS
1425

15-
R CMD check --as-cran wrapr_1.8.9.tar.gz
26+
R CMD check --as-cran wrapr_1.9.0.tar.gz
1627
* using R version 3.6.0 (2019-04-26)
1728
* using platform: x86_64-apple-darwin15.6.0 (64-bit)
1829
* using session charset: UTF-8
1930
* using option ‘--as-cran’
2031
* checking for file ‘wrapr/DESCRIPTION’ ... OK
2132
* checking extension type ... Package
22-
* this is package ‘wrapr’ version ‘1.8.9
33+
* this is package ‘wrapr’ version ‘1.9.0
2334
* package encoding: UTF-8
2435
* checking CRAN incoming feasibility ... Note_to_CRAN_maintainers
2536
Maintainer: ‘John Mount <[email protected]>’
26-
* checking top-level files ... WARNING
27-
Conversion of ‘README.md’ failed:
28-
pandoc: Could not fetch https://www.r-pkg.org/badges/version/wrapr
29-
TlsException (HandshakeFailed (Error_Protocol ("expecting server hello, got alert : [(AlertLevel_Fatal,HandshakeFailure)]",True,HandshakeFailure)))
30-
Status: 1 WARNING
31-
Link WARNING is spurious, URL https://www.r-pkg.org/badges/version/wrapr is correct and working.
37+
Status: OK
3238

3339
## Downstream dependencies
3440

0 commit comments

Comments
 (0)