Skip to content

Commit d48fd61

Browse files
committed
update docs and vignettes
1 parent 6688c70 commit d48fd61

File tree

6 files changed

+111
-78
lines changed

6 files changed

+111
-78
lines changed

R/map.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@
8080
#' If \code{.x} is a matrix or dataframe (or other object with \sQuote{dim}
8181
#' attributes), \emph{multiple} map is performed over its \strong{rows}.
8282
#'
83-
#' In this case, \code{.f} should accept at least as many arguments as the
84-
#' length of each row. If the dataframe has names, or the matrix column
85-
#' dimnames, named arguments are provided to \code{.f}.
83+
#' This allows map over 2 or more arguments, and \code{.f} should accept at
84+
#' least as many arguments as there are columns. If the dataframe has names, or
85+
#' the matrix column dimnames, named arguments are provided to \code{.f}.
8686
#'
8787
#' To map over \strong{columns} instead, first wrap a dataframe in
8888
#' \code{\link{as.list}}, or transpose a matrix using \code{\link{t}}.

man/mirai_map.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/mirai.Rmd

Lines changed: 72 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ To wait for and collect the return value, use the mirai's `[]` method:
6262

6363
``` r
6464
m[]
65-
#> [1] 4.787818 5.374806 5.581499 4.097772 3.906010
65+
#> [1] 3.081159 5.130453 3.361243 3.899214 3.578723
6666
```
6767
As a mirai represents an async operation, it is never necessary to wait for it. Other code can continue to be run. Once it completes, the return value automatically becomes available at `$data`.
6868

6969
``` r
7070
m
7171
#> < mirai [$data] >
7272
m$data
73-
#> [1] 4.787818 5.374806 5.581499 4.097772 3.906010
73+
#> [1] 3.081159 5.130453 3.361243 3.899214 3.578723
7474
```
7575
For easy programmatic use of `mirai()`, '.expr' accepts a pre-constructed language object, and also a list of named arguments passed via '.args'. So, the following would be equivalent to the above:
7676

@@ -82,7 +82,7 @@ args <- list(time = x$time, mean = x$mean)
8282

8383
m <- mirai(.expr = expr, .args = args)
8484
m[]
85-
#> [1] 3.893310 3.842836 2.445046 2.791802 3.027402
85+
#> [1] 4.066422 2.925708 3.895417 3.189227 4.322313
8686
```
8787

8888
[&laquo; Back to ToC](#table-of-contents)
@@ -162,8 +162,8 @@ for (i in 1:10) {
162162
#> iteration 4 successful
163163
#> iteration 5 successful
164164
#> iteration 6 successful
165-
#> iteration 7 successful
166165
#> Error: random error
166+
#> iteration 7 successful
167167
#> iteration 8 successful
168168
#> iteration 9 successful
169169
#> iteration 10 successful
@@ -203,7 +203,7 @@ status()
203203
#> [1] 6
204204
#>
205205
#> $daemons
206-
#> [1] "abstract://7fe5045dfc2baab276769663"
206+
#> [1] "abstract://61f3b00995a8c1e081a9fb98"
207207
#>
208208
#> $mirai
209209
#> awaiting executing completed
@@ -237,7 +237,7 @@ status()
237237
#> [1] 6
238238
#>
239239
#> $daemons
240-
#> [1] "abstract://885a215708562b79a052854b"
240+
#> [1] "abstract://c910c5fc17b314069fe962e6"
241241
```
242242
This implementation sends tasks immediately, and ensures that tasks are evenly-distributed amongst daemons. This means that optimal scheduling is not guaranteed as the duration of tasks cannot be known *a priori*. As an example, tasks could be queued at a daemon behind a long-running task, whilst other daemons are idle having already completed their tasks.
243243

@@ -263,14 +263,14 @@ By super-assignment, the conenction 'con' will be available in the global enviro
263263
``` r
264264
m <- mirai(capture.output(str(con)))
265265
m[]
266-
#> [1] "Formal class 'SQLiteConnection' [package \"RSQLite\"] with 8 slots"
267-
#> [2] " ..@ ptr :<externalptr> "
268-
#> [3] " ..@ dbname : chr \"/tmp/Rtmpue3X97/file7bf11fbaa8c8\""
269-
#> [4] " ..@ loadable.extensions: logi TRUE"
270-
#> [5] " ..@ flags : int 70"
271-
#> [6] " ..@ vfs : chr \"\""
272-
#> [7] " ..@ ref :<environment: 0x5cdacd816e50> "
273-
#> [8] " ..@ bigint : chr \"integer64\""
266+
#> [1] "Formal class 'SQLiteConnection' [package \"RSQLite\"] with 8 slots"
267+
#> [2] " ..@ ptr :<externalptr> "
268+
#> [3] " ..@ dbname : chr \"/tmp/RtmpBA6yAD/file17a914db50cf1\""
269+
#> [4] " ..@ loadable.extensions: logi TRUE"
270+
#> [5] " ..@ flags : int 70"
271+
#> [6] " ..@ vfs : chr \"\""
272+
#> [7] " ..@ ref :<environment: 0x5661b9d35fa8> "
273+
#> [8] " ..@ bigint : chr \"integer64\""
274274
#> [9] " ..@ extended_types : logi FALSE"
275275
```
276276
Disconnect from the database everywhere, and set the number of daemons to zero to reset.
@@ -321,7 +321,7 @@ status()
321321
#> [1] 0
322322
#>
323323
#> $daemons
324-
#> [1] "tcp://hostname:42357"
324+
#> [1] "tcp://hostname:34711"
325325
#>
326326
#> $mirai
327327
#> awaiting executing completed
@@ -415,10 +415,10 @@ daemons(url = host_url())
415415
#> [1] 0
416416
launch_remote(2)
417417
#> [1]
418-
#> Rscript -e 'mirai::daemon("tcp://hostname:43719",rs=c(10407,2122168296,1693125833,-861376010,-492650497,-2146258380,876173221),dispatcher=TRUE)'
418+
#> Rscript -e 'mirai::daemon("tcp://hostname:34495",rs=c(10407,-1548736186,795843343,1112403460,-75379403,-879623054,1922652491),dispatcher=TRUE)'
419419
#>
420420
#> [2]
421-
#> Rscript -e 'mirai::daemon("tcp://hostname:43719",rs=c(10407,802952157,2130119868,1507853841,34753586,-552261268,322495961),dispatcher=TRUE)'
421+
#> Rscript -e 'mirai::daemon("tcp://hostname:34495",rs=c(10407,177393518,-240118901,227679337,1647891508,-951127399,-86322505),dispatcher=TRUE)'
422422
daemons(0)
423423
#> [1] 0
424424
```
@@ -445,37 +445,37 @@ The generated self-signed certificate is available via `launch_remote()`. This f
445445
``` r
446446
launch_remote(1)
447447
#> [1]
448-
#> Rscript -e 'mirai::daemon("tls+tcp://hostname:42683",tls=c("-----BEGIN CERTIFICATE-----
448+
#> Rscript -e 'mirai::daemon("tls+tcp://hostname:46223",tls=c("-----BEGIN CERTIFICATE-----
449449
#> MIIFNzCCAx+gAwIBAgIBATANBgkqhkiG9w0BAQsFADAzMREwDwYDVQQ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iRW4zQX+AlVlKgudSG4rPuniJwUDitt06CTxUJnKo04FyUKJVq0tl
472+
#> kOvvGKh2kHO2i0FGbZf/pozwe5HAdvcP2WMEIH16ikoHzDmIMKg0drhJBrNfz0wC
473+
#> EEXtaMQQu7dOcvQvkud0BXJQqk6NXM6PyqGUc1VgtWnKYjUC4+XB3EBCTdYR922V
474+
#> PBtGDEvis0NzvrF++dGWKnACK7Z6VE2U/flmj4TRTLHYj14MVAcNopN/aV7aEp3P
475+
#> yVcLzpj+Cnm4rWrKjTrLihH2+/0O5PCQy5VutXcjOMA2tqilE706Kl6IMXDt7eLF
476+
#> 4DfVuE/NpVL7gDfvlRSg2vvmgSj5zzC7NFOVcU5fyRUHg3mI3TvPZONfwg==
477477
#> -----END CERTIFICATE-----
478-
#> ",""),rs=c(10407,-1204738537,610380652,-1017724547,-1781970406,1963829459,374728696),dispatcher=TRUE)'
478+
#> ",""),rs=c(10407,-1811307506,-1390734025,335202316,-2079928931,-545218630,567695859),dispatcher=TRUE)'
479479
```
480480
The printed value may be deployed directly on a remote machine.
481481

@@ -560,6 +560,18 @@ m3$data$stack.trace
560560
#> [[2]]
561561
#> [1] "f(1)"
562562
```
563+
Elements of the original error condition are also accessible via `$` on the error object. For example, additional metadata recorded by `rlang::abort()` is preserved:
564+
565+
``` r
566+
f <- function(x) if (x > 0) stop("positive")
567+
568+
m4 <- mirai(rlang::abort("aborted", meta_uid = "UID001"))
569+
m4[]
570+
#> 'miraiError' chr Error: aborted
571+
572+
m4$data$meta_uid
573+
#> [1] "UID001"
574+
```
563575
If a daemon instance is sent a user interrupt, the mirai will resolve to an object of class 'miraiInterrupt' and 'errorValue'. `is_mirai_interrupt()` may be used to test for such interrupts.
564576

565577
``` r
@@ -570,15 +582,15 @@ is_mirai_interrupt(m4[])
570582
If execution of a mirai surpasses the timeout set via the '.timeout' argument, the mirai will resolve to an 'errorValue' of 5L (timed out). This can, amongst other things, guard against mirai processes that have the potential to hang and never return.
571583

572584
``` r
573-
m4 <- mirai(nanonext::msleep(1000), .timeout = 500)
574-
m4[]
585+
m5 <- mirai(nanonext::msleep(1000), .timeout = 500)
586+
m5[]
575587
#> 'errorValue' int 5 | Timed out
576588

577-
is_mirai_error(m4$data)
589+
is_mirai_error(m5$data)
578590
#> [1] FALSE
579-
is_mirai_interrupt(m4$data)
591+
is_mirai_interrupt(m5$data)
580592
#> [1] FALSE
581-
is_error_value(m4$data)
593+
is_error_value(m5$data)
582594
#> [1] TRUE
583595
```
584596
`is_error_value()` tests for all mirai execution errors, user interrupts and timeouts.
@@ -711,10 +723,10 @@ daemons(4)
711723
vec <- c(1, 1, 4, 4, 1, 1, 1, 1)
712724
system.time(mirai_map(vec, Sys.sleep)[])
713725
#> user system elapsed
714-
#> 0.004 0.003 4.007
726+
#> 0.001 0.004 4.006
715727
system.time(parLapply(cl, vec, Sys.sleep))
716728
#> user system elapsed
717-
#> 0.012 0.005 8.013
729+
#> 0.016 0.077 8.091
718730
```
719731
`.args` is used to specify further constant arguments to `.f` - the 'mean' and 'sd' in the example below:
720732

@@ -724,13 +736,13 @@ with(
724736
mirai_map(1:3, rnorm, .args = list(mean = 20, sd = 2))[]
725737
)
726738
#> [[1]]
727-
#> [1] 17.97769
739+
#> [1] 21.67525
728740
#>
729741
#> [[2]]
730-
#> [1] 19.69199 22.18763
742+
#> [1] 20.10329 19.76841
731743
#>
732744
#> [[3]]
733-
#> [1] 18.35564 21.54589 18.61806
745+
#> [1] 20.36542 20.73644 19.38807
734746
```
735747
Use `...` to further specify objects referenced but not defined in `.f` - the 'do' in the anonymous function below:
736748

@@ -742,16 +754,16 @@ ml <- mirai_map(
742754
)
743755
#> Warning: mirai is launching one local daemon for a map operation as none previously set
744756
ml
745-
#> < mirai map [3/3] >
757+
#> < mirai map [1/3] >
746758
ml[]
747759
#> $a
748-
#> [1] "d7"
760+
#> [1] "47"
749761
#>
750762
#> $b
751-
#> [1] ab a5
763+
#> [1] f4 de
752764
#>
753765
#> $c
754-
#> [1] "02f85a"
766+
#> [1] "9accab"
755767
```
756768
Use of `mirai_map()` assumes that `daemons()` have previously been set. If not then one (non-dispatcher) daemon is set to allow the function to proceed. This ensures safe behaviour, but is unlikely to be optimal, so please ensure daemons are set beforehand.
757769

@@ -760,7 +772,7 @@ Use of `mirai_map()` assumes that `daemons()` have previously been set. If not t
760772
When collecting the results, optionally specify arguments to `[]`:
761773

762774
- `x[.flat]` collects and flattens the results, checking that they are of the same type to avoid coercion.
763-
- `x[.progress]` collects results using a `cli` progress bar, if available, showing completion percentage and ETA, or else a simple text progress indicator of parts completed of the total.
775+
- `x[.progress]` collects results using a `cli` progress bar, if available, showing completion percentage and ETA, or else a simple text progress indicator of parts completed of the total. If the map operation completes quickly, the `cli` progress bar may not show at all, and this is by design.
764776
- `x[.stop]` collects the results applying early stopping, which stops at the first failure and cancels remaining computations. If the `cli` package is available, it will be used for displaying the error message.
765777

766778
Combinations of the above may be supplied in the fashion of `x[.stop, .progress]`.
@@ -784,6 +796,8 @@ Multiple map is performed over the **rows** of a dataframe or matrix, as this is
784796

785797
This allows map over 2 or more arguments by specifying a dataframe. One of those may be an index value for indexed map.
786798

799+
The function `.f` must take as many arguments as there are columns, either explicitly or via `...`.
800+
787801

788802
``` r
789803
fruit <- c("melon", "grapes", "coconut")

vignettes/mirai.Rmd.orig

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,19 +436,28 @@ m3[]
436436

437437
m3$data$stack.trace
438438
```
439+
Elements of the original error condition are also accessible via `$` on the error object. For example, additional metadata recorded by `rlang::abort()` is preserved:
440+
```{r metaexample}
441+
f <- function(x) if (x > 0) stop("positive")
442+
443+
m4 <- mirai(rlang::abort("aborted", meta_uid = "UID001"))
444+
m4[]
445+
446+
m4$data$meta_uid
447+
```
439448
If a daemon instance is sent a user interrupt, the mirai will resolve to an object of class 'miraiInterrupt' and 'errorValue'. `is_mirai_interrupt()` may be used to test for such interrupts.
440449
```{r interruptexample}
441450
m4 <- mirai(rlang::interrupt()) # simulates a user interrupt
442451
is_mirai_interrupt(m4[])
443452
```
444453
If execution of a mirai surpasses the timeout set via the '.timeout' argument, the mirai will resolve to an 'errorValue' of 5L (timed out). This can, amongst other things, guard against mirai processes that have the potential to hang and never return.
445454
```{r timeouts}
446-
m4 <- mirai(nanonext::msleep(1000), .timeout = 500)
447-
m4[]
455+
m5 <- mirai(nanonext::msleep(1000), .timeout = 500)
456+
m5[]
448457

449-
is_mirai_error(m4$data)
450-
is_mirai_interrupt(m4$data)
451-
is_error_value(m4$data)
458+
is_mirai_error(m5$data)
459+
is_mirai_interrupt(m5$data)
460+
is_error_value(m5$data)
452461
```
453462
`is_error_value()` tests for all mirai execution errors, user interrupts and timeouts.
454463

@@ -564,7 +573,7 @@ Use of `mirai_map()` assumes that `daemons()` have previously been set. If not t
564573
When collecting the results, optionally specify arguments to `[]`:
565574

566575
- `x[.flat]` collects and flattens the results, checking that they are of the same type to avoid coercion.
567-
- `x[.progress]` collects results using a `cli` progress bar, if available, showing completion percentage and ETA, or else a simple text progress indicator of parts completed of the total.
576+
- `x[.progress]` collects results using a `cli` progress bar, if available, showing completion percentage and ETA, or else a simple text progress indicator of parts completed of the total. If the map operation completes quickly, the `cli` progress bar may not show at all, and this is by design.
568577
- `x[.stop]` collects the results applying early stopping, which stops at the first failure and cancels remaining computations. If the `cli` package is available, it will be used for displaying the error message.
569578

570579
Combinations of the above may be supplied in the fashion of `x[.stop, .progress]`.
@@ -583,6 +592,8 @@ Multiple map is performed over the **rows** of a dataframe or matrix, as this is
583592

584593
This allows map over 2 or more arguments by specifying a dataframe. One of those may be an index value for indexed map.
585594

595+
The function `.f` must take as many arguments as there are columns, either explicitly or via `...`.
596+
586597
```{r mmapmulti}
587598
fruit <- c("melon", "grapes", "coconut")
588599

vignettes/shiny.Rmd

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,20 @@ server <- function(input, output, session) {
322322
# Button to submit a batch of coin flips
323323
observeEvent(input$task, {
324324
flips$flips <- flips$flips + 1000
325-
m <- mirai_map(1:1000, flip_coin, .promise = \(x)
326-
if (x) flips$heads <- flips$heads + 1 else flips$tails <- flips$tails + 1)
325+
mirai_map(
326+
1:1000,
327+
flip_coin,
328+
.promise = \(x) {
329+
if (x) flips$heads <- flips$heads + 1 else flips$tails <- flips$tails + 1
330+
}
331+
)
327332
})
328333

329334
# Print time and task status
330335
output$status <- renderText({
331-
input$task
332336
invalidateLater(millis = 1000)
333337
time <- format(Sys.time(), "%H:%M:%S")
334-
sprintf("%s %s flips submitted", time, flips$flips)
338+
sprintf("%s | %s flips submitted", time, flips$flips)
335339
})
336340

337341
# Print number of heads and tails

0 commit comments

Comments
 (0)