| 1 |
has_fun = function(name, envir = baseenv()) exists(name, envir, inherits = FALSE) |
| 2 |
|
| 3 |
# for R < 4.0 |
| 4 |
if (!has_fun('isFALSE')) isFALSE = function(x) { |
| 5 |
is.logical(x) && length(x) == 1 && !is.na(x) && !x |
| 6 |
} |
| 7 |
if (!has_fun('startsWith')) startsWith = function(x, s) { |
| 8 |
substring(x, 1, nchar(s)) == s |
| 9 |
} |
| 10 |
if (!has_fun('endsWith')) endsWith = function(x, s) { |
| 11 |
n = nchar(x) |
| 12 |
substring(x, n - nchar(s) + 1, n) == s |
| 13 |
} |
| 14 |
if (!has_fun('strrep')) strrep = function(x, times) { |
| 15 |
mapply(function(x, n) paste(rep(x, n), collapse = ''), x, times, USE.NAMES = FALSE) |
| 16 |
} |
| 17 |
if (!has_fun('packageDate', asNamespace('utils'))) packageDate = function(...) { |
| 18 |
as.Date(packageDescription(..., fields = 'Date/Publication')) |
| 19 |
} |
| 20 |
|
| 21 |
if (!'timeout' %in% names(formals(system2))) |
| 22 |
system2 = function(..., timeout = 0) base::system2(...) |
| 23 |
|
| 24 |
.onLoad = function(libname, pkgname) { |
| 25 |
# Register a finalizer so the background proxy is killed if the parent R |
| 26 |
# session exits without calling stop_app() (e.g., on crash or q()). |
| 27 |
reg.finalizer(asNamespace(pkgname), function(e) .onUnload(), onexit = TRUE) |
| 28 |
} |
| 29 |
|
| 30 |
.onUnload = function(libpath) { |
| 31 |
if (length(.proxy$apps) > 0L) stop_app() |
| 32 |
if (length(.proxy$help) > 0L) .stop_help_proxy() |
| 33 |
} |