R Under development (unstable) (2024-12-03 r87418 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > if (getRversion() >= "4.4.0") { + + library(parallelly) + library(parallel) + + cl <- makeClusterSequential() + print(cl) + + y_truth <- lapply(X = 1:3, FUN = sqrt) + y <- parLapply(cl, X = 1:3, fun = sqrt) + str(y) + stopifnot(identical(y, y_truth)) + + pid <- Sys.getpid() + print(pid) + y <- clusterEvalQ(cl, Sys.getpid()) + str(y) + stopifnot(identical(y[[1]], pid)) + + y <- clusterEvalQ(cl, { abc <- 42; abc }) + str(y) + stopifnot(!exists("abc", inherits = FALSE)) + + stopCluster(cl) + print(cl) + + res <- tryCatch({ + y <- clusterEvalQ(cl, { 42 }) + }, error = identity) + print(res) + stopifnot(inherits(res, "error")) + } ## if (getRversion() >= "4.4.0") A 'sequential_cluster' cluster with 1 node List of 3 $ : num 1 $ : num 1.41 $ : num 1.73 [1] 84480 List of 1 $ : int 84480 List of 1 $ : num 42 A 'sequential_cluster' cluster with 1 node > > proc.time() user system elapsed 0.28 0.04 0.29