Skip to content

Commit f44953f

Browse files
committed
CRAN release 0.7.0
1 parent 67a0d3a commit f44953f

File tree

8 files changed

+149
-155
lines changed

8 files changed

+149
-155
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: mirai
22
Type: Package
33
Title: Minimalist Async Evaluation Framework for R
4-
Version: 0.6.0.9900
4+
Version: 0.7.0
55
Description: Simple and lightweight parallelism and concurrent code execution,
66
local or distributed across the network, built on 'nanonext' and 'NNG'
77
(Nanomsg Next Gen) technology.

NEWS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# mirai 0.6.0.9900
1+
# mirai 0.7.0
22

33
* `daemons()` now takes 'n' and '.url' arguments. '.url' is an optional client URL allowing mirai tasks to be distributed across the network. Compatibility with existing interface is retained.
44
* The server function `server()` is exported for creating daemon / ephemeral processes on network resources.

R/mirai.R

+139-145
Original file line numberDiff line numberDiff line change
@@ -166,122 +166,6 @@ eval_mirai <- function(.expr, ..., .args = list(), .timeout = NULL) {
166166
#'
167167
mirai <- eval_mirai
168168

169-
#' mirai (Call Value)
170-
#'
171-
#' Call the value of a 'mirai', waiting for the the asynchronous operation to
172-
#' resolve if it is still in progress.
173-
#'
174-
#' @param aio a 'mirai' (also an 'aio' object).
175-
#'
176-
#' @return The passed 'mirai' (invisibly). The retrieved value is stored at \code{$data}.
177-
#'
178-
#' @details This function will wait for the async operation to complete if still
179-
#' in progress (blocking).
180-
#'
181-
#' If an error occurs in evaluation, the error message is returned as a
182-
#' character string of class 'miraiError' and 'errorValue'.
183-
#' \code{\link{is_mirai_error}} may be used to test for this, otherwise
184-
#' \code{\link{is_error_value}} will also include other errors such as
185-
#' timeouts.
186-
#'
187-
#' The 'mirai' updates itself in place, so to access the value of a 'mirai'
188-
#' \code{x} directly, use \code{call_mirai(x)$data}.
189-
#'
190-
#' @section Alternatively:
191-
#'
192-
#' The value of a 'mirai' may be accessed at any time at \code{$data}, and
193-
#' if yet to resolve, an 'unresolved' logical NA will be returned instead.
194-
#'
195-
#' \code{\link{unresolved}} may also be used on a 'mirai', and returns TRUE
196-
#' only if a 'mirai' has yet to resolve and FALSE otherwise. This is suitable
197-
#' for use in control flow statements such as \code{while} or \code{if}.
198-
#'
199-
#' @examples
200-
#' if (interactive()) {
201-
#' # Only run examples in interactive R sessions
202-
#'
203-
#' m <- mirai(x + y + 1, x = 2, y = 3)
204-
#' m
205-
#' m$data
206-
#' Sys.sleep(0.2)
207-
#' m$data
208-
#'
209-
#' df1 <- data.frame(a = 1, b = 2)
210-
#' df2 <- data.frame(a = 3, b = 1)
211-
#' m <- mirai(as.matrix(rbind(df1, df2)), .args = list(df1, df2), .timeout = 1000)
212-
#' call_mirai(m)$data
213-
#'
214-
#' m <- mirai({
215-
#' res <- rnorm(n)
216-
#' res / rev(res)
217-
#' }, n = 1e6)
218-
#' while (unresolved(m)) {
219-
#' cat("unresolved\n")
220-
#' Sys.sleep(0.1)
221-
#' }
222-
#' str(m$data)
223-
#'
224-
#' file <- tempfile()
225-
#' cat("r <- rnorm(n)", file = file)
226-
#' n <- 10L
227-
#' m <- mirai({source(file, local = TRUE); r}, .args = list(file, n))
228-
#' call_mirai(m)[["data"]]
229-
#' unlink(file)
230-
#'
231-
#' }
232-
#'
233-
#' @export
234-
#'
235-
call_mirai <- call_aio
236-
237-
#' mirai (Stop Evaluation)
238-
#'
239-
#' Stop evaluation of a mirai that is in progress.
240-
#'
241-
#' @param aio a 'mirai' (also an 'aio' object).
242-
#'
243-
#' @return Invisible NULL.
244-
#'
245-
#' @details Stops the asynchronous operation associated with 'mirai' by aborting,
246-
#' and then waits for it to complete or to be completely aborted. The 'mirai'
247-
#' is then deallocated and attempting to access the value at \code{$data}
248-
#' will result in an error.
249-
#'
250-
#' @examples
251-
#' if (interactive()) {
252-
#' # Only run examples in interactive R sessions
253-
#'
254-
#' s <- mirai(Sys.sleep(n), n = 5)
255-
#' stop_mirai(s)
256-
#'
257-
#' }
258-
#'
259-
#' @export
260-
#'
261-
stop_mirai <- stop_aio
262-
263-
#' Is mirai
264-
#'
265-
#' Is the object a mirai.
266-
#'
267-
#' @param x an object.
268-
#'
269-
#' @return Logical value TRUE or FALSE.
270-
#'
271-
#' @examples
272-
#' if (interactive()) {
273-
#' # Only run examples in interactive R sessions
274-
#'
275-
#' m <- mirai(as.matrix(df), df = data.frame())
276-
#' is_mirai(m)
277-
#' is_mirai(df)
278-
#'
279-
#' }
280-
#'
281-
#' @export
282-
#'
283-
is_mirai <- function(x) inherits(x, "mirai")
284-
285169
#' daemons (Background and Remote Processes)
286170
#'
287171
#' Set or view the number of daemons (server processes). Create persistent
@@ -373,7 +257,6 @@ daemons <- function(n, .url) {
373257

374258
is.numeric(n) || stop("invalid input - non-numeric value supplied for 'n'")
375259
n >= 0L || stop("'n' must be zero or greater")
376-
377260
delta <- as.integer(n) - proc
378261
delta == 0L && return(delta)
379262

@@ -384,7 +267,6 @@ daemons <- function(n, .url) {
384267
arg <<- c("--vanilla", "-e", shQuote(sprintf("mirai::server(%s)", deparse(url))))
385268
local <<- TRUE
386269
}
387-
388270
if (delta > 0L) {
389271
if (local) {
390272
for (i in seq_len(delta))
@@ -416,56 +298,107 @@ daemons <- function(n, .url) {
416298
}
417299
}
418300

419-
#' @export
301+
#' mirai (Call Value)
302+
#'
303+
#' Call the value of a 'mirai', waiting for the the asynchronous operation to
304+
#' resolve if it is still in progress.
305+
#'
306+
#' @param aio a 'mirai' (mirai are nanonext 'aio' objects).
307+
#'
308+
#' @return The passed 'mirai' (invisibly). The retrieved value is stored at \code{$data}.
309+
#'
310+
#' @details This function will wait for the async operation to complete if still
311+
#' in progress (blocking).
312+
#'
313+
#' If an error occurs in evaluation, the error message is returned as a
314+
#' character string of class 'miraiError' and 'errorValue'.
315+
#' \code{\link{is_mirai_error}} may be used to test for this, otherwise
316+
#' \code{\link{is_error_value}} will also include other errors such as
317+
#' timeouts.
318+
#'
319+
#' The 'mirai' updates itself in place, so to access the value of a 'mirai'
320+
#' \code{x} directly, use \code{call_mirai(x)$data}.
321+
#'
322+
#' @section Alternatively:
323+
#'
324+
#' The value of a 'mirai' may be accessed at any time at \code{$data}, and
325+
#' if yet to resolve, an 'unresolved' logical NA will be returned instead.
326+
#'
327+
#' \code{\link{unresolved}} may also be used on a 'mirai', and returns TRUE
328+
#' only if a 'mirai' has yet to resolve and FALSE otherwise. This is suitable
329+
#' for use in control flow statements such as \code{while} or \code{if}.
330+
#'
331+
#' @examples
332+
#' if (interactive()) {
333+
#' # Only run examples in interactive R sessions
334+
#'
335+
#' m <- mirai(x + y + 1, x = 2, y = 3)
336+
#' m
337+
#' m$data
338+
#' Sys.sleep(0.2)
339+
#' m$data
340+
#'
341+
#' df1 <- data.frame(a = 1, b = 2)
342+
#' df2 <- data.frame(a = 3, b = 1)
343+
#' m <- mirai(as.matrix(rbind(df1, df2)), .args = list(df1, df2), .timeout = 1000)
344+
#' call_mirai(m)$data
345+
#'
346+
#' m <- mirai({
347+
#' res <- rnorm(n)
348+
#' res / rev(res)
349+
#' }, n = 1e6)
350+
#' while (unresolved(m)) {
351+
#' cat("unresolved\n")
352+
#' Sys.sleep(0.1)
353+
#' }
354+
#' str(m$data)
355+
#'
356+
#' file <- tempfile()
357+
#' cat("r <- rnorm(n)", file = file)
358+
#' n <- 10L
359+
#' m <- mirai({source(file, local = TRUE); r}, .args = list(file, n))
360+
#' call_mirai(m)[["data"]]
361+
#' unlink(file)
362+
#'
363+
#' }
420364
#'
421-
print.mirai <- function(x, ...) {
422-
423-
cat("< mirai >\n - $data for evaluated result\n", file = stdout())
424-
invisible(x)
425-
426-
}
427-
428365
#' @export
429366
#'
430-
print.miraiError <- function(x, ...) {
431-
432-
cat("'miraiError' chr ", x, "\n", file = stdout())
433-
invisible(x)
434-
435-
}
367+
call_mirai <- call_aio
436368

437-
#' Is mirai Error
369+
#' mirai (Stop Evaluation)
438370
#'
439-
#' Is the object a 'miraiError'. When execution in a mirai process fails, the
440-
#' error message is returned as a character string of class 'miraiError' and
441-
#' 'errorValue'. To test for all errors, including timeouts etc.,
442-
#' \code{\link{is_error_value}} should be used instead.
371+
#' Stop evaluation of a mirai that is in progress.
443372
#'
444-
#' @param x an object.
373+
#' @param aio a 'mirai' (mirai are nanonext 'aio' objects).
445374
#'
446-
#' @return Logical value TRUE if 'x' is of class 'miraiError', FALSE otherwise.
375+
#' @return Invisible NULL.
376+
#'
377+
#' @details Stops the asynchronous operation associated with 'mirai' by aborting,
378+
#' and then waits for it to complete or to be completely aborted. The 'mirai'
379+
#' is then deallocated and attempting to access the value at \code{$data}
380+
#' will result in an error.
447381
#'
448382
#' @examples
449383
#' if (interactive()) {
450384
#' # Only run examples in interactive R sessions
451385
#'
452-
#' m <- mirai(stop())
453-
#' call_mirai(m)
454-
#' is_mirai_error(m$data)
386+
#' s <- mirai(Sys.sleep(n), n = 5)
387+
#' stop_mirai(s)
455388
#'
456389
#' }
457390
#'
458391
#' @export
459392
#'
460-
is_mirai_error <- function(x) inherits(x, "miraiError")
393+
stop_mirai <- stop_aio
461394

462395
#' Query if a Mirai is Unresolved
463396
#'
464397
#' Query whether a mirai or mirai value remains unresolved. Unlike
465398
#' \code{\link{call_mirai}}, this function does not wait for completion.
466399
#'
467-
#' @param aio A 'mirai' or mirai value stored in \code{$data} (mirai are also
468-
#' aio objects).
400+
#' @param aio A 'mirai' or mirai value stored in \code{$data} (mirai are nanonext
401+
#' 'aio' objects).
469402
#'
470403
#' @return Logical TRUE or FALSE.
471404
#'
@@ -507,6 +440,67 @@ unresolved <- unresolved
507440
#'
508441
is_error_value <- is_error_value
509442

443+
#' Is mirai
444+
#'
445+
#' Is the object a mirai.
446+
#'
447+
#' @param x an object.
448+
#'
449+
#' @return Logical value TRUE or FALSE.
450+
#'
451+
#' @examples
452+
#' if (interactive()) {
453+
#' # Only run examples in interactive R sessions
454+
#'
455+
#' m <- mirai(as.matrix(df), df = data.frame())
456+
#' is_mirai(m)
457+
#' is_mirai(df)
458+
#'
459+
#' }
460+
#'
461+
#' @export
462+
#'
463+
is_mirai <- function(x) inherits(x, "mirai")
464+
465+
#' Is mirai Error
466+
#'
467+
#' Is the object a 'miraiError'. When execution in a mirai process fails, the
468+
#' error message is returned as a character string of class 'miraiError' and
469+
#' 'errorValue'. To test for all errors, including timeouts etc.,
470+
#' \code{\link{is_error_value}} should be used instead.
471+
#'
472+
#' @param x an object.
473+
#'
474+
#' @return Logical value TRUE if 'x' is of class 'miraiError', FALSE otherwise.
475+
#'
476+
#' @examples
477+
#' if (interactive()) {
478+
#' # Only run examples in interactive R sessions
479+
#'
480+
#' m <- mirai(stop())
481+
#' call_mirai(m)
482+
#' is_mirai_error(m$data)
483+
#'
484+
#' }
485+
#'
486+
#' @export
487+
#'
488+
is_mirai_error <- function(x) inherits(x, "miraiError")
489+
490+
#' @export
491+
#'
492+
print.mirai <- function(x, ...) {
493+
cat("< mirai >\n - $data for evaluated result\n", file = stdout())
494+
invisible(x)
495+
}
496+
497+
#' @export
498+
#'
499+
print.miraiError <- function(x, ...) {
500+
cat("'miraiError' chr ", x, "\n", file = stdout())
501+
invisible(x)
502+
}
503+
510504
# internals --------------------------------------------------------------------
511505

512506
mk_mirai_error <- function(e) `class<-`(if (length(call <- .subset2(e, "call")))

README.Rmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Cache data in memory and use `mirai()` to perform periodic write operations conc
117117

118118
A 'mirai' object is returned immediately.
119119

120-
Below, `.args` accepts a list of objects already present in the calling environment to be passed to the mirai.
120+
Below, '.args' accepts a list of objects already present in the calling environment to be passed to the mirai.
121121

122122
```{r exec2}
123123
library(mirai)

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ result.
101101

102102
``` r
103103
m$data |> str()
104-
#> num [1:100000000] 0.0105 24.7102 0.2075 11.365 0.105 ...
104+
#> num [1:100000000] 0.582 0.571 29.254 0.205 0.387 ...
105105
```
106106

107107
Alternatively, explicitly call and wait for the result using
108108
`call_mirai()`.
109109

110110
``` r
111111
call_mirai(m)$data |> str()
112-
#> num [1:100000000] 0.0105 24.7102 0.2075 11.365 0.105 ...
112+
#> num [1:100000000] 0.582 0.571 29.254 0.205 0.387 ...
113113
```
114114

115115
[« Back to ToC](#table-of-contents)
@@ -126,7 +126,7 @@ operations concurrently in a separate process.
126126

127127
A ‘mirai’ object is returned immediately.
128128

129-
Below, `.args` accepts a list of objects already present in the calling
129+
Below, .args accepts a list of objects already present in the calling
130130
environment to be passed to the mirai.
131131

132132
``` r

0 commit comments

Comments
 (0)