| 1 |
library(testit) |
| 2 |
|
| 3 |
assert("loadable() works", { |
| 4 |
(loadable("base")) |
| 5 |
# (loadable("base", new_session = TRUE)) |
| 6 |
(loadable("base", strict = FALSE)) |
| 7 |
(has_error(loadable(c("base", "base2")))) |
| 8 |
(has_error(loadable(character()))) |
| 9 |
(!loadable("#base")) |
| 10 |
# (!loadable("#base", new_session = TRUE)) |
| 11 |
(!loadable("#base", strict = FALSE)) |
| 12 |
}) |
| 13 |
|
| 14 |
assert('pkg_load() loads packages and returns logical vector', { |
| 15 |
res = pkg_load('base', 'stats', error = FALSE) |
| 16 |
(res %==% c(TRUE, TRUE)) |
| 17 |
res2 = pkg_load('#nonexistent#pkg', error = FALSE) |
| 18 |
(!res2) |
| 19 |
}) |
| 20 |
|
| 21 |
assert('pkg_attach() attaches packages', { |
| 22 |
pkg_attach('stats') |
| 23 |
('package:stats' %in% search()) |
| 24 |
}) |
| 25 |
|
| 26 |
assert('pkg_available() checks if a package with a version is available', { |
| 27 |
(pkg_available('base')) |
| 28 |
(pkg_available('base', '1.0.0')) |
| 29 |
(!pkg_available('#nonexistent#pkg')) |
| 30 |
}) |
| 31 |
|
| 32 |
assert('base_pkgs() returns base package names', { |
| 33 |
pkgs = base_pkgs() |
| 34 |
(is.character(pkgs)) |
| 35 |
(c('base', 'stats', 'utils', 'methods', 'tools') %in% pkgs) |
| 36 |
}) |
| 37 |
|
| 38 |
assert('pkg_load() with error = TRUE stops on missing package', { |
| 39 |
(has_error(pkg_load('#nonexistent#pkg', error = TRUE))) |
| 40 |
}) |
| 41 |
|
| 42 |
if (getRversion() >= '3.3.0') assert('pkg_attach() with message = FALSE suppresses messages', { |
| 43 |
out = capture.output(type = 'message', pkg_attach('stats', message = FALSE)) |
| 44 |
(length(out) %==% 0L) |
| 45 |
}) |
| 46 |
|
| 47 |
assert('loadable() with strict = FALSE checks .packages(TRUE)', { |
| 48 |
(loadable('base', strict = FALSE)) |
| 49 |
(!loadable('#nonexistent#', strict = FALSE)) |
| 50 |
}) |
| 51 |
|
| 52 |
assert('pkg_available() with version constraint works', { |
| 53 |
(pkg_available('base', '0.0.1')) |
| 54 |
(!pkg_available('xfun', '999999.999.999')) |
| 55 |
}) |