Skip to content

Commit c2dba9f

Browse files
author
Bruno Rodrigues
committed
fix for CRAN
1 parent d3785e1 commit c2dba9f

7 files changed

+55
-55
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ Config/testthat/edition: 3
4141
Encoding: UTF-8
4242
LazyData: true
4343
Roxygen: list(markdown = TRUE)
44-
RoxygenNote: 7.2.3
44+
RoxygenNote: 7.3.1

dev/flat_chronicle.Rmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ test_that("first and only error message is ok", {
130130
r_select(bm)
131131
132132
133-
expect_true(grepl("Can't subset columns that don't exist", result_pipe$log_df$message))
133+
expect_true(grepl("Can't select columns that don't exist", result_pipe$log_df$message))
134134
135135
})
136136
@@ -147,7 +147,7 @@ test_that("if multiple error messages, next ones are 'pipe failed'", {
147147
r_mutate(bm = 3)
148148
149149
150-
expect_true(grepl("Can't subset columns that don't exist", result_pipe$log_df$message[1]))
150+
expect_true(grepl("Can't select columns that don't exist", result_pipe$log_df$message[1]))
151151
expect_true(grepl("Pipeline failed upstream", result_pipe$log_df$message[2]))
152152
expect_true(grepl("Pipeline failed upstream", result_pipe$log_df$message[3]))
153153

tests/testthat/test-record.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test_that("first and only error message is ok", {
88
r_select(bm)
99

1010

11-
expect_true(grepl("Can't subset columns that don't exist", result_pipe$log_df$message))
11+
expect_true(grepl("Can't select columns that don't exist", result_pipe$log_df$message))
1212

1313
})
1414

@@ -25,7 +25,7 @@ test_that("if multiple error messages, next ones are 'pipe failed'", {
2525
r_mutate(bm = 3)
2626

2727

28-
expect_true(grepl("Can't subset columns that don't exist", result_pipe$log_df$message[1]))
28+
expect_true(grepl("Can't select columns that don't exist", result_pipe$log_df$message[1]))
2929
expect_true(grepl("Pipeline failed upstream", result_pipe$log_df$message[2]))
3030
expect_true(grepl("Pipeline failed upstream", result_pipe$log_df$message[3]))
3131

vignettes/a-non-mathematician-s-introduction-to-monads.Rmd

+26-26
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ library(chronicler)
2020

2121
<!-- WARNING - This vignette is generated by {fusen} from dev/advanced-topics.Rmd: do not edit by hand -->
2222

23-
```{r include = FALSE}
23+
```{r parsermd-chunk-1, include = FALSE}
2424
library(chronicler)
2525
library(testthat)
2626
```
@@ -45,7 +45,7 @@ Suppose for instance that you wish for your functions to provide a log when
4545
they're run. If your function looks like this:
4646

4747

48-
```{r}
48+
```{r parsermd-chunk-2}
4949
my_sqrt <- function(x){
5050
5151
sqrt(x)
@@ -57,7 +57,7 @@ my_sqrt <- function(x){
5757
Then you would need to rewrite this function like this:
5858

5959

60-
```{r}
60+
```{r parsermd-chunk-3}
6161
my_sqrt <- function(x, log = ""){
6262
6363
list(sqrt(x),
@@ -76,7 +76,7 @@ There are two problems with such an implementation:
7676
What do I mean with "these functions don't compose"? Consider another such function `my_log()`:
7777

7878

79-
```{r}
79+
```{r parsermd-chunk-4}
8080
my_log <- function(x, log = ""){
8181
8282
list(log(x),
@@ -90,7 +90,7 @@ my_log <- function(x, log = ""){
9090
`sqrt()` and `log()` compose, or rather, they can be chained:
9191

9292

93-
```{r}
93+
```{r parsermd-chunk-5}
9494
10 |>
9595
sqrt() |>
9696
log()
@@ -100,7 +100,7 @@ my_log <- function(x, log = ""){
100100
while this is not true for `my_sqrt()` and `my_log()`:
101101

102102

103-
```{r eval = FALSE}
103+
```{r parsermd-chunk-6, eval = FALSE}
104104
10 |>
105105
my_sqrt() |>
106106
my_log()
@@ -120,7 +120,7 @@ having to rewrite every function, can be tackled using
120120
Let's write one for our problem:
121121

122122

123-
```{r}
123+
```{r parsermd-chunk-7}
124124
log_it <- function(.f, ..., log = NULL){
125125
126126
fstring <- deparse(substitute(.f))
@@ -138,7 +138,7 @@ log_it <- function(.f, ..., log = NULL){
138138
We can now create our functions easily:
139139

140140

141-
```{r}
141+
```{r parsermd-chunk-8}
142142
l_sqrt <- log_it(sqrt)
143143
144144
l_sqrt(10)
@@ -155,7 +155,7 @@ The second issue remains though; `l_sqrt()` and `l_log()` can't be composed/chai
155155
this issue, we need another function, called `bind()`:
156156

157157

158-
```{r}
158+
```{r parsermd-chunk-9}
159159
bind <- function(.l, .f, ...){
160160
161161
.f(.l$result, ..., .log = .l$log)
@@ -166,7 +166,7 @@ bind <- function(.l, .f, ...){
166166
Using `bind()`, it is now possible to compose `l_sqrt()` and `l_log()`:
167167

168168

169-
```{r}
169+
```{r parsermd-chunk-10}
170170
10 |>
171171
l_sqrt() |>
172172
bind(l_log)
@@ -178,7 +178,7 @@ We can check that the result is correct by comparing it the `$result` value
178178
from the returned object to `log(sqrt(10))`:
179179

180180

181-
```{r}
181+
```{r parsermd-chunk-11}
182182
log(sqrt(10))
183183
```
184184

@@ -210,7 +210,7 @@ I did not focus on `return`/`unit`. Also, using our function factory, it is easy
210210
to implement `return/unit`:
211211

212212

213-
```{r}
213+
```{r parsermd-chunk-12}
214214
unit <- log_it(identity)
215215
```
216216

@@ -228,7 +228,7 @@ data frames, so I used `flatten()` instead).
228228
applies this undecorated function to the monadic value:
229229

230230

231-
```{r}
231+
```{r parsermd-chunk-13}
232232
fmap <- function(m, f, ...){
233233
234234
fstring <- deparse(substitute(f))
@@ -243,7 +243,7 @@ fmap <- function(m, f, ...){
243243
Let's first define a monadic value:
244244

245245

246-
```{r}
246+
```{r parsermd-chunk-14}
247247
# Let’s use unit(), which we defined above, for this.
248248
249249
(m <- unit(10))
@@ -252,7 +252,7 @@ Let's first define a monadic value:
252252
Let's now use `fmap()` to apply a non-decorated function to `m`:
253253

254254

255-
```{r}
255+
```{r parsermd-chunk-15}
256256
fmap(m, log)
257257
```
258258

@@ -261,7 +261,7 @@ Suppose that instead of `log()` we used `l_log()` with `fmap()`
261261
(so we’re using a decorated function instead of an undecorated one):
262262

263263

264-
```{r}
264+
```{r parsermd-chunk-16}
265265
fmap(m, l_log)
266266
```
267267

@@ -270,7 +270,7 @@ itself a monadic value. We would like `flatten()/join()` to take care of this fo
270270
be an implementation of `flatten()`:
271271

272272

273-
```{r}
273+
```{r parsermd-chunk-17}
274274
flatten <- function(m){
275275
276276
list(result = m$result$result,
@@ -283,7 +283,7 @@ flatten <- function(m){
283283
Let's try now:
284284

285285

286-
```{r}
286+
```{r parsermd-chunk-18}
287287
flatten(fmap(m, l_log))
288288
```
289289

@@ -292,7 +292,7 @@ Great! Now, as explained earlier, `flatmap()` and `bind()` are the same thing. B
292292
`flatmap()` is the composition of `flatten()` and `fmap()`:
293293

294294

295-
```{r}
295+
```{r parsermd-chunk-19}
296296
# I first define a composition operator for functions
297297
`%.%` <- \(f,g)(function(...)(f(g(...))))
298298
@@ -305,7 +305,7 @@ flatmap <- flatten %.% fmap
305305
So this means that we can now replace:
306306

307307

308-
```{r}
308+
```{r parsermd-chunk-20}
309309
10 |>
310310
l_sqrt() |>
311311
bind(l_log)
@@ -315,7 +315,7 @@ So this means that we can now replace:
315315
by:
316316

317317

318-
```{r}
318+
```{r parsermd-chunk-21}
319319
10 |>
320320
l_sqrt() |>
321321
flatmap(l_log)
@@ -334,7 +334,7 @@ and `purrr::flatten()` is `flatten()`. This means we can obtain `flatmap()` from
334334
`purrr::flatten()` and `purrr::map()`:
335335

336336

337-
```{r}
337+
```{r parsermd-chunk-22}
338338
# Since I'm using `{purrr}`, might as well use purrr::compose() instead of my own implementation
339339
flatmap_list <- purrr::compose(purrr::flatten, purrr::map)
340340
@@ -374,7 +374,7 @@ The first law states that passing a monadic value to a monadic function using `b
374374
function is the same.
375375

376376

377-
```{r}
377+
```{r parsermd-chunk-23}
378378
a <- as_chronicle(10)
379379
r_sqrt <- record(sqrt)
380380
@@ -395,7 +395,7 @@ this package, in other words, the function that coerces values to chronicler obj
395395
nothing. Here again we have an issue with the log, that's why I focus on the value:
396396

397397

398-
```{r}
398+
```{r parsermd-chunk-24}
399399
test_that("second monadic law", {
400400
expect_equal(bind_record(a, as_chronicle)$value, a$value)
401401
})
@@ -408,7 +408,7 @@ The third law is about associativity; applying monadic functions successively or
408408
first gives the same result.
409409

410410

411-
```{r}
411+
```{r parsermd-chunk-25}
412412
a <- as_chronicle(10)
413413
414414
r_sqrt <- record(sqrt)
@@ -436,7 +436,7 @@ For exhaustivity's sake, I check that I can get `flatmap_record()` by composing
436436
`fmap_record()`:
437437

438438

439-
```{r}
439+
```{r parsermd-chunk-26}
440440
441441
r_sqrt <- record(sqrt)
442442
r_exp <- record(exp)

0 commit comments

Comments
 (0)