Skip to content

Commit 52514fb

Browse files
Add internal parse_prologue()
1 parent 2861a5b commit 52514fb

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future
2-
Version: 1.69.0-9012
2+
Version: 1.69.0-9013
33
Title: Unified Parallel and Distributed Processing in R for Everyone
44
Depends:
55
R (>= 3.2.0)

R/backend_api-Future-class.R

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,10 @@ Future <- function(expr = NULL, prologue = TRUE, envir = parent.frame(), substit
138138
if (is.logical(prologue)) {
139139
stop_if_not(length(prologue) == 1L, !is.na(prologue))
140140
if (isTRUE(prologue)) {
141-
if (identical(expr[[1]], as.symbol("{")) && !is.symbol(expr[[2]])) {
142-
## The prologue() expression should be the first subexpression, if at all
143-
prologue_expression <- expr[[2]]
144-
prologue_call <- prologue_expression[[1]]
145-
if (is.symbol(prologue_call)) {
146-
if (identical(prologue_call, as.symbol("prologue"))) {
147-
prologue <- prologue_expression[[2L]]
148-
expr <- expr[-2L]
149-
}
150-
}
141+
res <- parse_prologue(expr)
142+
if (res[["exists"]]) {
143+
prologue <- res[["prologue"]]
144+
expr <- res[["expr"]]
151145
}
152146
} else {
153147
prologue <- NULL
@@ -1054,3 +1048,23 @@ getExpression.Future <- local({
10541048

10551049
NextMethod()
10561050
}
1051+
1052+
1053+
1054+
parse_prologue <- function(expr) {
1055+
prologue <- NULL
1056+
exists <- FALSE
1057+
if (identical(expr[[1]], as.symbol("{")) && !is.symbol(expr[[2]])) {
1058+
## The prologue() expression should be the first subexpression, if at all
1059+
prologue_expression <- expr[[2]]
1060+
prologue_call <- prologue_expression[[1]]
1061+
if (is.symbol(prologue_call)) {
1062+
if (identical(prologue_call, as.symbol("prologue"))) {
1063+
prologue <- prologue_expression[[2L]]
1064+
expr <- expr[-2L]
1065+
exists <- TRUE
1066+
}
1067+
}
1068+
}
1069+
list(expr = expr, prologue = prologue, exists = exists)
1070+
} ## parse_prologue()

0 commit comments

Comments
 (0)