repr
repr copied to clipboard
improve short-circuit logic
i just checked the code of capabilities(), and what @randy3k did in #62 is probably not that fast after all. this is the code:
capabilities <- function (what = NULL) {
z <- .Internal(capabilities())
if (!is.null(what))
z <- z[match(what, names(z), 0L)]
if (.Platform$OS.type == 'windows')
return(z)
nas <- names(z[is.na(z)])
if (any(nas %in% c('X11', 'jpeg', 'png', 'tiff'))) {
z[nas] <- tryCatch(.Internal(capabilitiesX11()), error = function(e) FALSE)
}
z
}
so there are 1-2 internal calls:
.Internal(capabilities()).Internal(capabilitiesX11())(ifany(nas %in% c('X11', 'jpeg', 'png', 'tiff')))
Perhaps, just separate the X11 and non-X11 checking.
Yea, first all non-X11 in one go, then X11...
BTW: why don't we do the checks on startup instead of each time? the only problem I can think of is when user installs something during the session and things like check_capability('png') can't be changed from within the session, as all these are compiled into R, aren't they?
We could do it on startup, but we'll have to use an environment I think. In .onLoad I think?
Simply assigning to a variable at top level happens at compile time, so the check would return whatever capabilities the building system had at build time.