File: end.R

package info (click to toggle)
r-cran-progressr 0.15.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,132 kB
  • sloc: sh: 13; makefile: 7
file content (63 lines) | stat: -rw-r--r-- 2,262 bytes parent folder | download | duplicates (2)
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
## Undo options
## (a) Reset
options(oopts0)
## (b) Remove added
added <- setdiff(names(options()), names(oopts0))
opts <- vector("list", length = length(added))
names(opts) <- added
options(opts)
## (c) Assert that everything was undone
if (!identical(options(), oopts0)) {
  message("Failed to undo options:")
  oopts <- options()
  message(sprintf(" - Expected options: [n=%d] %s",
                  length(oopts0), hpaste(sQuote(names(oopts0)))))
  extra <- setdiff(names(oopts), names(oopts0))
  message(paste(sprintf(" - Options still there: [n=%d]", length(extra)),
                hpaste(sQuote(extra))))
  missing <- setdiff(names(oopts0), names(oopts))
  message(paste(sprintf(" - Options missing: [n=%d]", length(missing)),
                hpaste(sQuote(missing))))
  message("Differences option by option:")                
  for (name in names(oopts0)) {
    value0 <- oopts0[[name]]
    value  <- oopts[[name]]
    if (!identical(value, value0)) {
      utils::str(list(name = name, expected = value0, actual = value))
    }
  }
}
stopifnot(identical(options(), oopts0))


## Undo system environment variables
## (a) Reset
do.call(Sys.setenv, args=as.list(oenvs0))
## (b) Removed added
added <- setdiff(names(Sys.getenv()), names(oenvs0))
Sys.unsetenv(added)
## (c) Assert that everything was undone
if (!identical(Sys.getenv(), oenvs0)) {
  message("Failed to undo environment variables:")
  oenvs <- Sys.getenv()
  message(sprintf(" - Expected environment variables: [n=%d] %s",
                  length(oenvs0), hpaste(sQuote(names(oenvs0)))))
  extra <- setdiff(names(oenvs), names(oenvs0))
  message(paste(sprintf(" - Environment variables still there: [n=%d]", length(extra)),
                hpaste(sQuote(extra))))
  missing <- setdiff(names(oenvs0), names(oenvs))
  message(paste(sprintf(" - Environment variables missing: [n=%d]", length(missing)),
                hpaste(sQuote(missing))))
  message("Differences environment variable by environment variable:")
  for (name in names(oenvs0)) {
    value0 <- unname(oenvs0[name])
    value  <- unname(oenvs[name])
    if (!identical(value, value0)) {
      utils::str(list(name = name, expected = value0, actual = value))
    }
  }
}


## Undo variables
rm(list = c(setdiff(ls(), ovars)))