Skip to content

Commit 25d112a

Browse files
authored
Add compute_env() helper (#404)
* Add compute_env() helper * Refresh readme
1 parent 89bc64d commit 25d112a

File tree

6 files changed

+14
-23
lines changed

6 files changed

+14
-23
lines changed

R/daemons.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,8 @@ with.miraiDaemons <- function(data, expr, ...) {
368368
#' @export
369369
#'
370370
status <- function(.compute = NULL) {
371-
if (is.null(.compute)) .compute <- .[["cp"]]
372371
is.list(.compute) && return(status(attr(.compute, "id")))
373-
envir <- ..[[.compute]]
372+
envir <- compute_env(.compute)
374373
is.null(envir) && return(list(connections = 0L, daemons = 0L))
375374
is.null(envir[["dispatcher"]]) || return(dispatcher_status(envir))
376375
list(connections = as.integer(stat(envir[["sock"]], "pipes")), daemons = envir[["url"]])
@@ -393,10 +392,7 @@ status <- function(.compute = NULL) {
393392
#'
394393
#' @export
395394
#'
396-
daemons_set <- function(.compute = NULL) {
397-
if (is.null(.compute)) .compute <- .[["cp"]]
398-
!is.null(..[[.compute]])
399-
}
395+
daemons_set <- function(.compute = NULL) !is.null(compute_env(.compute))
400396

401397
#' Require Daemons
402398
#'
@@ -552,6 +548,8 @@ register_serial <- function(class, sfunc, ufunc) {
552548

553549
# internals --------------------------------------------------------------------
554550

551+
compute_env <- function(x) ..[[if (is.null(x)) .[["cp"]] else x]]
552+
555553
configure_tls <- function(url, tls, pass, envir, config = TRUE) {
556554
purl <- parse_url(url)
557555
sch <- purl[["scheme"]]

R/launchers.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545
#' @export
4646
#'
4747
launch_local <- function(n = 1L, ..., tls = NULL, .compute = NULL) {
48-
if (is.null(.compute)) .compute <- .[["cp"]]
49-
envir <- ..[[.compute]]
48+
envir <- compute_env(.compute)
5049
is.null(envir) && stop(._[["daemons_unset"]])
5150
url <- envir[["url"]]
5251
write_args <- if (is.null(envir[["dispatcher"]])) args_daemon_direct else args_daemon_disp
@@ -83,13 +82,12 @@ launch_local <- function(n = 1L, ..., tls = NULL, .compute = NULL) {
8382
#' @export
8483
#'
8584
launch_remote <- function(n = 1L, remote = remote_config(), ..., tls = NULL, .compute = NULL) {
86-
if (is.null(.compute)) .compute <- .[["cp"]]
8785
if (!is.numeric(n) && inherits(n, c("miraiCluster", "miraiNode"))) {
8886
.compute <- attr(n, "id")
8987
n <- max(length(n), 1L)
9088
}
9189
n <- as.integer(n)
92-
envir <- ..[[.compute]]
90+
envir <- compute_env(.compute)
9391
is.null(envir) && stop(._[["daemons_unset"]])
9492
url <- envir[["url"]]
9593
write_args <- if (is.null(envir[["dispatcher"]])) args_daemon_direct else args_daemon_disp

R/map.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
#' @export
155155
#'
156156
mirai_map <- function(.x, .f, ..., .args = list(), .promise = NULL, .compute = NULL) {
157+
if (is.null(.compute)) .compute <- .[["cp"]]
157158
require_daemons(.compute = .compute, call = environment())
158159
is.function(.f) || stop(sprintf(._[["function_required"]], typeof(.f)))
159160

R/mirai.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@
140140
#'
141141
mirai <- function(.expr, ..., .args = list(), .timeout = NULL, .compute = NULL) {
142142
missing(.expr) && stop(._[["missing_expression"]])
143-
if (is.null(.compute)) .compute <- .[["cp"]]
144-
envir <- ..[[.compute]]
143+
envir <- compute_env(.compute)
145144

146145
expr <- substitute(.expr)
147146
globals <- list(...)

README.Rmd

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ knitr::opts_chunk$set(
3131
Minimalist Async Evaluation Framework for R
3232
<br /><br />
3333

34-
mirai is a comprehensive solution for performing computationally-intensive tasks efficiently.
35-
3634
→ Run R code in parallel in the background, without blocking your session
3735

3836
→ Distribute workloads across local or remote machines
@@ -117,13 +115,13 @@ mirai is designed from the ground up to provide a production-grade experience.
117115

118116
→ Error Handling: Robust error handling and reporting, with full stack traces for debugging.
119117

120-
→ RNG Management: L'Ecuyer-CMRG RNG streams for reproducible random number generation in parallel execution.
118+
→ RNG Management: L'Ecuyer-CMRG RNG streams for reproducible parallel random number generation.
121119

122120
### Powering the Ecosystem
123121

124122
mirai serves as a foundation for asynchronous and parallel computing in the R ecosystem:
125123

126-
[<img alt="R parallel" src="https://www.r-project.org/logo/Rlogo.png" width="40" height="31" />](https://mirai.r-lib.org/articles/v04-parallel.html) &nbsp; Implements the first official alternative communications backend for Rthe 'MIRAI' parallel cluster fulfilling a feature request by R-Core at R Project Sprint 2023.
124+
[<img alt="R parallel" src="https://www.r-project.org/logo/Rlogo.png" width="40" height="31" />](https://mirai.r-lib.org/articles/v04-parallel.html) &nbsp; Implements the first official alternative communications backend for R, the 'MIRAI' parallel cluster, fulfilling a feature request by R-Core at R Project Sprint 2023.
127125

128126
[<img alt="purrr" src="https://purrr.tidyverse.org/logo.png" width="40" height="46" />](https://purrr.tidyverse.org) &nbsp; Powers parallel map for the purrr functional programming toolkit, a core tidyverse package.
129127

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ coverage](https://codecov.io/gh/r-lib/mirai/graph/badge.svg)](https://app.codeco
2020
<br /> みらい 未来 <br /><br /> Minimalist Async Evaluation Framework
2121
for R <br /><br />
2222

23-
mirai is a comprehensive solution for performing
24-
computationally-intensive tasks efficiently.
25-
2623
→ Run R code in parallel in the background, without blocking your
2724
session
2825

@@ -125,17 +122,17 @@ objects such as Arrow Tables, Polars DataFrames or torch tensors.
125122
→ Error Handling: Robust error handling and reporting, with full stack
126123
traces for debugging.
127124

128-
→ RNG Management: L’Ecuyer-CMRG RNG streams for reproducible random
129-
number generation in parallel execution.
125+
→ RNG Management: L’Ecuyer-CMRG RNG streams for reproducible parallel
126+
random number generation.
130127

131128
### Powering the Ecosystem
132129

133130
mirai serves as a foundation for asynchronous and parallel computing in
134131
the R ecosystem:
135132

136133
[<img alt="R parallel" src="https://www.r-project.org/logo/Rlogo.png" width="40" height="31" />](https://mirai.r-lib.org/articles/v04-parallel.html)
137-
  Implements the first official alternative communications backend for R
138-
the ‘MIRAI’ parallel cluster fulfilling a feature request by R-Core
134+
  Implements the first official alternative communications backend for
135+
R, the ‘MIRAI’ parallel cluster, fulfilling a feature request by R-Core
139136
at R Project Sprint 2023.
140137

141138
[<img alt="purrr" src="https://purrr.tidyverse.org/logo.png" width="40" height="46" />](https://purrr.tidyverse.org)

0 commit comments

Comments
 (0)