1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
source("incl/start.R")
maxCores <- min(2L, availableCores(methods = "system"))
plan("default")
strategy0 <- plan()
message("*** parseCmdArgs() ...")
args <- parseCmdArgs()
str(args)
options(future.plan = NULL, future.cmdargs = c("-p", 1L))
args <- parseCmdArgs()
str(args)
stopifnot(args$p == 1L)
options(future.plan = NULL, future.cmdargs = c(sprintf("--parallel=%d", maxCores)))
args <- parseCmdArgs()
str(args)
stopifnot(args$p == maxCores)
options(future.plan = NULL, future.cmdargs = c("-p", 1L, sprintf("--parallel=%d", maxCores)))
args <- parseCmdArgs()
str(args)
stopifnot(args$p == maxCores)
options(future.plan = NULL, future.cmdargs = c("-p", 0L))
args <- parseCmdArgs()
stopifnot(is.null(args$p))
res <- tryCatch(parseCmdArgs(), warning = function(w) w)
stopifnot(inherits(res, "warning"))
options(future.plan = NULL, future.cmdargs = c("-p", .Machine$integer.max))
args <- parseCmdArgs()
stopifnot(is.null(args$p))
res <- tryCatch(parseCmdArgs(), warning = function(w) w)
stopifnot(inherits(res, "warning"))
options(future.plan = NULL, future.cmdargs = NULL)
message("*** parseCmdArgs() ... DONE")
message("*** .onLoad() ...")
plan("default")
pkgname <- "future"
message("- .onLoad() w/out command-line options ...")
options(future.plan = NULL, future.cmdargs = NULL)
.onLoad(pkgname, pkgname)
strategy <- plan("next")
print(strategy)
stopifnot(all(class(strategy) == class(strategy0)))
plan("default")
message("- .onLoad() w/out command-line options ... DONE")
message("- .onLoad() w/ -p 1 ...")
options(future.plan = NULL, future.cmdargs = c("-p", 1))
.onLoad(pkgname, pkgname)
strategy <- plan("next")
print(strategy)
## future.plan can be either a string or a future function
default <- getOption("future.plan", "sequential")
if (is.function(default)) default <- class(default)
stopifnot(inherits(strategy, default))
plan("default")
message("- .onLoad() w/ -p 1 ... DONE")
message("- .onLoad() w/ --parallel=1 ...")
plan("default")
options(future.plan = NULL, future.cmdargs = "-parallel=1")
.onLoad(pkgname, pkgname)
strategy <- plan("next")
print(strategy)
## future.plan can be either a string or a future function
default <- getOption("future.plan", "sequential")
if (is.function(default)) default <- class(default)
stopifnot(inherits(strategy, default))
plan("default")
message("- .onLoad() w/ --parallel=1 ... DONE")
message("- .onLoad() w/ -p 2 ...")
options(future.plan = NULL, future.cmdargs = c("-p", 2))
.onLoad(pkgname, pkgname)
strategy <- plan("next")
print(strategy)
if (maxCores >= 2) {
stopifnot(inherits(strategy, "multisession"))
} else {
stopifnot(all(class(strategy) == class(strategy0)))
}
plan("default")
message("- .onLoad() w/ -p 2 ... DONE")
message("- .onLoad() w/ -p 0 ...")
options(future.plan = NULL, future.cmdargs = c("-p", 0))
.onLoad(pkgname, pkgname)
strategy <- plan("next")
print(strategy)
stopifnot(all(class(strategy) == class(strategy0)))
plan("default")
message("- .onLoad() w/ -p 0 ... DONE")
message("- .onLoad() w/ -p -1 ...")
options(future.plan = NULL, future.cmdargs = c("-p", -1))
.onLoad(pkgname, pkgname)
strategy <- plan("next")
print(strategy)
stopifnot(all(class(strategy) == class(strategy0)))
plan("default")
message("- .onLoad() w/ -p -1 ... DONE")
message("- .onLoad() w/ -p foo ...")
options(future.plan = NULL, future.cmdargs = c("-p", "foo"))
.onLoad(pkgname, pkgname)
strategy <- plan("next")
print(strategy)
stopifnot(all(class(strategy) == class(strategy0)))
plan("default")
message("- .onLoad() w/ -p foo ... DONE")
message("- .onLoad() w/ R_FUTURE_PLAN = 'multisession' ...")
Sys.setenv(R_FUTURE_PLAN = "multisession")
options(future.plan = NULL, future.cmdargs = NULL)
.onLoad(pkgname, pkgname)
strategy <- plan("next")
print(strategy)
stopifnot(inherits(strategy, "multisession"))
plan("default")
Sys.setenv(R_FUTURE_PLAN = "")
message("- .onLoad() w/ R_FUTURE_PLAN = 'multisession' ... DONE")
message("- .onLoad() w/ future.plan = 'multisession' ...")
options(future.plan = NULL, future.plan = 'multisession', future.cmdargs = NULL)
.onLoad(pkgname, pkgname)
strategy <- plan("next")
print(strategy)
stopifnot(inherits(strategy, "multisession"))
plan("default")
message("- .onLoad() w/ future.plan = 'multisession' ... DONE")
message("- .onLoad() w/ R_FUTURE_PLAN = 'multisession' & -p 1 ...")
Sys.setenv(R_FUTURE_PLAN = "multisession")
options(future.plan = NULL, future.cmdargs = c("-p", 1))
.onLoad(pkgname, pkgname)
strategy <- plan("next")
print(strategy)
stopifnot(inherits(strategy, "multisession"))
plan("default")
Sys.setenv(R_FUTURE_PLAN = "")
message("- .onLoad() w/ R_FUTURE_PLAN = 'multisession' & -p 1 ... DONE")
message("- .onLoad() w/ future.plan = 'multisession' & -p 1 ...")
options(future.plan = 'multisession', future.cmdargs = c("-p", "1"))
.onLoad(pkgname, pkgname)
strategy <- plan("next")
print(strategy)
stopifnot(inherits(strategy, "multisession"))
plan("default")
message("- .onLoad() w/ future.plan = 'multisession' & -p 1 ... DONE")
message("- .onLoad() w/ future.plan = 'multisession' & -p 1 ...")
options(future.plan = multisession, future.cmdargs = c("-p", "1"))
.onLoad(pkgname, pkgname)
strategy <- plan("next")
print(strategy)
stopifnot(inherits(strategy, "multisession"))
plan("default")
message("- .onLoad() w/ future.plan = 'multisession' & -p 1 ... DONE")
options(future.plan = NULL, future.cmdargs = NULL, future.availableCores.system = NULL, future.availableCores.fallback = NULL)
message("*** .onLoad() ... DONE")
message("*** .onAttach() ...")
pkgname <- "future"
message("- .onAttach() w/ option future.startup.loadScript ...")
for (value in list(NULL, FALSE, TRUE)) {
options(future.startup.loadScript = value)
.onAttach(pkgname, pkgname)
}
message("- .onAttach() w/ option future.startup.loadScript ... DONE")
message("- .onAttach() with ./.future.R ...")
pathname <- ".future.R"
xyz <- 0L
cat("xyz <- 42L; cat('ping\n')\n", file = pathname)
.onAttach(pkgname, pkgname)
print(xyz)
stopifnot(is.integer(xyz), xyz >= 0, xyz == 42L)
file.remove(pathname)
message("- .onAttach() with ./.future.R ... DONE")
message("*** .onAttach() ... DONE")
source("incl/end.R")
|