@@ -166,122 +166,6 @@ eval_mirai <- function(.expr, ..., .args = list(), .timeout = NULL) {
166
166
# '
167
167
mirai <- eval_mirai
168
168
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
-
285
169
# ' daemons (Background and Remote Processes)
286
170
# '
287
171
# ' Set or view the number of daemons (server processes). Create persistent
@@ -373,7 +257,6 @@ daemons <- function(n, .url) {
373
257
374
258
is.numeric(n ) || stop(" invalid input - non-numeric value supplied for 'n'" )
375
259
n > = 0L || stop(" 'n' must be zero or greater" )
376
-
377
260
delta <- as.integer(n ) - proc
378
261
delta == 0L && return (delta )
379
262
@@ -384,7 +267,6 @@ daemons <- function(n, .url) {
384
267
arg <<- c(" --vanilla" , " -e" , shQuote(sprintf(" mirai::server(%s)" , deparse(url ))))
385
268
local <<- TRUE
386
269
}
387
-
388
270
if (delta > 0L ) {
389
271
if (local ) {
390
272
for (i in seq_len(delta ))
@@ -416,56 +298,107 @@ daemons <- function(n, .url) {
416
298
}
417
299
}
418
300
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
+ # ' }
420
364
# '
421
- print.mirai <- function (x , ... ) {
422
-
423
- cat(" < mirai >\n - $data for evaluated result\n " , file = stdout())
424
- invisible (x )
425
-
426
- }
427
-
428
365
# ' @export
429
366
# '
430
- print.miraiError <- function (x , ... ) {
431
-
432
- cat(" 'miraiError' chr " , x , " \n " , file = stdout())
433
- invisible (x )
434
-
435
- }
367
+ call_mirai <- call_aio
436
368
437
- # ' Is mirai Error
369
+ # ' mirai (Stop Evaluation)
438
370
# '
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.
443
372
# '
444
- # ' @param x an object .
373
+ # ' @param aio a 'mirai' (mirai are nanonext 'aio' objects) .
445
374
# '
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.
447
381
# '
448
382
# ' @examples
449
383
# ' if (interactive()) {
450
384
# ' # Only run examples in interactive R sessions
451
385
# '
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)
455
388
# '
456
389
# ' }
457
390
# '
458
391
# ' @export
459
392
# '
460
- is_mirai_error <- function ( x ) inherits( x , " miraiError " )
393
+ stop_mirai <- stop_aio
461
394
462
395
# ' Query if a Mirai is Unresolved
463
396
# '
464
397
# ' Query whether a mirai or mirai value remains unresolved. Unlike
465
398
# ' \code{\link{call_mirai}}, this function does not wait for completion.
466
399
# '
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).
469
402
# '
470
403
# ' @return Logical TRUE or FALSE.
471
404
# '
@@ -507,6 +440,67 @@ unresolved <- unresolved
507
440
# '
508
441
is_error_value <- is_error_value
509
442
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
+
510
504
# internals --------------------------------------------------------------------
511
505
512
506
mk_mirai_error <- function (e ) `class<-`(if (length(call <- .subset2(e , " call" )))
0 commit comments