|
1 | | -## Restore original state |
2 | | -options(oopts) |
| 1 | +## Undo future strategy |
3 | 2 | future::plan(oplan) |
| 3 | + |
| 4 | + |
| 5 | +## Undo options |
| 6 | +## (a) Added |
| 7 | +added <- setdiff(names(options()), names(oopts0)) |
| 8 | +opts <- vector("list", length = length(added)) |
| 9 | +names(opts) <- added |
| 10 | +options(opts) |
| 11 | +## (b) Modified |
| 12 | +options(oopts) |
| 13 | +## (c) Removed, e.g. future.plan=NULL |
| 14 | +removed <- setdiff(names(oopts0), names(options())) |
| 15 | +opts <- oopts0[removed] |
| 16 | +options(opts) |
| 17 | +## (d) Assert that everything was undone |
| 18 | +stopifnot(identical(options(), oopts0)) |
| 19 | + |
| 20 | + |
| 21 | +## Undo system environment variables |
| 22 | +## (a) Added |
| 23 | +cenvs <- Sys.getenv() |
| 24 | +added <- setdiff(names(cenvs), names(oenvs0)) |
| 25 | +for (name in added) Sys.unsetenv(name) |
| 26 | +## (b) Missing |
| 27 | +missing <- setdiff(names(oenvs0), names(cenvs)) |
| 28 | +if (length(missing) > 0) do.call(Sys.setenv, as.list(oenvs0[missing])) |
| 29 | +## (c) Modified? |
| 30 | +for (name in intersect(names(cenvs), names(oenvs0))) { |
| 31 | + ## WORKAROUND: On Linux Wine, base::Sys.getenv() may |
| 32 | + ## return elements with empty names. /HB 2016-10-06 |
| 33 | + if (nchar(name) == 0) next |
| 34 | + if (!identical(cenvs[[name]], oenvs0[[name]])) { |
| 35 | + do.call(Sys.setenv, as.list(oenvs0[name])) |
| 36 | + } |
| 37 | +} |
| 38 | +## (d) Assert that everything was undone |
| 39 | +stopifnot(identical(Sys.getenv(), oenvs0)) |
| 40 | + |
| 41 | + |
| 42 | +## Undo variables |
4 | 43 | rm(list = c(setdiff(ls(), ovars))) |
| 44 | + |
| 45 | + |
| 46 | +## Travis CI specific: Explicit garbage collection because it |
| 47 | +## looks like Travis CI might run out of memory during 'covr' |
| 48 | +## testing and we now have so many tests. /HB 2017-01-11 |
| 49 | +if ("covr" %in% loadedNamespaces()) gc() |
0 commit comments