Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions R/getDoPar.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,22 @@ getDoParVersion <- function() {
}

# used internally to get the currently registered parallel backend
getDoPar <- function() {
getDoPar <- function(warn = TRUE) {
if (exists('fun', where=.foreachGlobals, inherits=FALSE)) {
list(fun=.foreachGlobals$fun, data=.foreachGlobals$data)
structure(list(
fun=.foreachGlobals$fun,
data=.foreachGlobals$data,
info=.foreachGlobals$info
), class="DoPar")
} else {
if (!exists('parWarningIssued', where=.foreachGlobals, inherits=FALSE)) {
warning('executing %dopar% sequentially: no parallel backend registered',
call.=FALSE)
assign('parWarningIssued', TRUE, pos=.foreachGlobals, inherits=FALSE)
if (warn) {
if (!exists('parWarningIssued', where=.foreachGlobals, inherits=FALSE)) {
warning('executing %dopar% sequentially: no parallel backend registered',
call.=FALSE)
assign('parWarningIssued', TRUE, pos=.foreachGlobals, inherits=FALSE)
}
}
list(fun=doSEQ, data=NULL)
structure(list(fun=doSEQ, data=NULL, info=NULL), class=c("DoPar", "DoSeq"))
}
}

8 changes: 6 additions & 2 deletions R/getDoSeq.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ getDoSeqVersion <- function() {
# used internally to get the currently registered parallel backend
getDoSeq <- function() {
if (exists('seqFun', where=.foreachGlobals, inherits=FALSE)) {
list(fun=.foreachGlobals$seqFun, data=.foreachGlobals$seqdata)
structure(list(
fun=.foreachGlobals$seqFun,
data=.foreachGlobals$seqData,
info=.foreachGlobals$seqInfo
), class="DoSeq")
} else {
list(fun=doSEQ, data=NULL)
structure(list(fun=doSEQ, data=NULL, info=NULL), class=c("DoPar", "DoSeq"))
}
}

12 changes: 12 additions & 0 deletions R/setDoPar.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@
#' @param fun A function that implements the functionality of `%dopar%`.
#' @param data Data to be passed to the registered function.
#' @param info Function that retrieves information about the backend.
#' @return (invisible) The previously registered `DoPar` settings.
#' @seealso
#' [`%dopar%`]
#' @keywords utilities
#' @export
setDoPar <- function(fun, data=NULL, info=function(data, item) NULL) {
if (inherits(fun, "DoPar")) {
dopar <- fun
fun <- dopar$fun
info <- dopar$info
data <- dopar$data
}

dopar <- getDoPar(warn=FALSE)

tryCatch(
{
assign('fun', fun, pos=.foreachGlobals, inherits=FALSE)
Expand All @@ -43,5 +53,7 @@ setDoPar <- function(fun, data=NULL, info=function(data, item) NULL) {
remove('info', envir=.foreachGlobals)
e
})

invisible(dopar)
}

14 changes: 13 additions & 1 deletion R/setDoSeq.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@
#' @param fun A function that implements the functionality of `%dopar%`.
#' @param data Data to be passed to the registered function.
#' @param info Function that retrieves information about the backend.
#' @return (invisible) The previously registered `DoSeq` settings.
#' @seealso
#' [`%dopar%`]
#' [`%do%`]
#' @keywords utilities
#' @export
setDoSeq <- function(fun, data=NULL, info=function(data, item) NULL) {
if (inherits(fun, "DoSeq")) {
doseq <- fun
fun <- doseq$fun
info <- doseq$info
data <- doseq$data
}

doseq <- getDoSeq()

tryCatch(
{
assign('seqFun', fun, pos=.foreachGlobals, inherits=FALSE)
Expand All @@ -43,5 +53,7 @@ setDoSeq <- function(fun, data=NULL, info=function(data, item) NULL) {
remove('info', envir = .foreachGlobals)
e
})

invisible(doseq)
}

3 changes: 3 additions & 0 deletions man/setDoPar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/setDoSeq.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.