You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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`.
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:
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.
243
243
@@ -263,14 +263,14 @@ By super-assignment, the conenction 'con' will be available in the global enviro
263
263
```r
264
264
m<- mirai(capture.output(str(con)))
265
265
m[]
266
-
#> [1] "Formal class 'SQLiteConnection' [package \"RSQLite\"] with 8 slots"
The printed value may be deployed directly on a remote machine.
481
481
@@ -560,6 +560,18 @@ m3$data$stack.trace
560
560
#> [[2]]
561
561
#> [1] "f(1)"
562
562
```
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:
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.
564
576
565
577
```r
@@ -570,15 +582,15 @@ is_mirai_interrupt(m4[])
570
582
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.
571
583
572
584
```r
573
-
m4<- mirai(nanonext::msleep(1000), .timeout=500)
574
-
m4[]
585
+
m5<- mirai(nanonext::msleep(1000), .timeout=500)
586
+
m5[]
575
587
#> 'errorValue' int 5 | Timed out
576
588
577
-
is_mirai_error(m4$data)
589
+
is_mirai_error(m5$data)
578
590
#> [1] FALSE
579
-
is_mirai_interrupt(m4$data)
591
+
is_mirai_interrupt(m5$data)
580
592
#> [1] FALSE
581
-
is_error_value(m4$data)
593
+
is_error_value(m5$data)
582
594
#> [1] TRUE
583
595
```
584
596
`is_error_value()` tests for all mirai execution errors, user interrupts and timeouts.
@@ -711,10 +723,10 @@ daemons(4)
711
723
vec<- c(1, 1, 4, 4, 1, 1, 1, 1)
712
724
system.time(mirai_map(vec, Sys.sleep)[])
713
725
#> user system elapsed
714
-
#> 0.004 0.003 4.007
726
+
#> 0.001 0.004 4.006
715
727
system.time(parLapply(cl, vec, Sys.sleep))
716
728
#> user system elapsed
717
-
#> 0.012 0.005 8.013
729
+
#> 0.016 0.077 8.091
718
730
```
719
731
`.args` is used to specify further constant arguments to `.f` - the 'mean' and 'sd' in the example below:
Use `...` to further specify objects referenced but not defined in `.f` - the 'do' in the anonymous function below:
736
748
@@ -742,16 +754,16 @@ ml <- mirai_map(
742
754
)
743
755
#> Warning: mirai is launching one local daemon for a map operation as none previously set
744
756
ml
745
-
#> < mirai map [3/3] >
757
+
#> < mirai map [1/3] >
746
758
ml[]
747
759
#> $a
748
-
#> [1] "d7"
760
+
#> [1] "47"
749
761
#>
750
762
#> $b
751
-
#> [1] ab a5
763
+
#> [1] f4 de
752
764
#>
753
765
#> $c
754
-
#> [1] "02f85a"
766
+
#> [1] "9accab"
755
767
```
756
768
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.
757
769
@@ -760,7 +772,7 @@ Use of `mirai_map()` assumes that `daemons()` have previously been set. If not t
760
772
When collecting the results, optionally specify arguments to `[]`:
761
773
762
774
-`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.
764
776
-`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.
765
777
766
778
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
784
796
785
797
This allows map over 2 or more arguments by specifying a dataframe. One of those may be an index value for indexed map.
786
798
799
+
The function `.f` must take as many arguments as there are columns, either explicitly or via `...`.
Copy file name to clipboardExpand all lines: vignettes/mirai.Rmd.orig
+17-6Lines changed: 17 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -436,19 +436,28 @@ m3[]
436
436
437
437
m3$data$stack.trace
438
438
```
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:
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.
440
449
```{r interruptexample}
441
450
m4 <- mirai(rlang::interrupt()) # simulates a user interrupt
442
451
is_mirai_interrupt(m4[])
443
452
```
444
453
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.
`is_error_value()` tests for all mirai execution errors, user interrupts and timeouts.
454
463
@@ -564,7 +573,7 @@ Use of `mirai_map()` assumes that `daemons()` have previously been set. If not t
564
573
When collecting the results, optionally specify arguments to `[]`:
565
574
566
575
- `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.
568
577
- `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.
569
578
570
579
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
583
592
584
593
This allows map over 2 or more arguments by specifying a dataframe. One of those may be an index value for indexed map.
585
594
595
+
The function `.f` must take as many arguments as there are columns, either explicitly or via `...`.
0 commit comments