Skip to content

Commit 67404ee

Browse files
committed
don't attach external packages; step 1: don't attach hexbin
1 parent 43dcd63 commit 67404ee

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

R/fortify-map.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fortify.map <- function(model, data, ...) {
7575
#' coord_map("albers", at0 = 45.5, lat1 = 29.5)
7676
#' }
7777
map_data <- function(map, region = ".", exact = FALSE, ...) {
78-
try_require("maps", "map_data")
78+
try_require("maps", "map_data", attach = TRUE)
7979
map_obj <- maps::map(map, region, exact = exact, plot = FALSE, fill = TRUE, ...)
8080
fortify(map_obj)
8181
}

R/stat-quantile.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ StatQuantile <- ggproto("StatQuantile", Stat,
5050
compute_group = function(data, scales, quantiles = c(0.25, 0.5, 0.75),
5151
formula = NULL, xseq = NULL, method = "rq",
5252
method.args = list(), lambda = 1, na.rm = FALSE) {
53-
try_require("quantreg", "stat_quantile")
53+
try_require("quantreg", "stat_quantile", attach = TRUE)
5454

5555
if (is.null(formula)) {
5656
if (method == "rqss") {
57-
try_require("MatrixModels", "stat_quantile")
57+
try_require("MatrixModels", "stat_quantile", attach = TRUE)
5858
formula <- eval(substitute(y ~ qss(x, lambda = lambda)),
5959
list(lambda = lambda))
6060
} else {

R/utilities.r

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,18 @@ clist <- function(l) {
4242
paste(paste(names(l), l, sep = " = ", collapse = ", "), sep = "")
4343
}
4444

45-
try_require <- function(package, fun) {
45+
46+
# Test whether package `package` is available. `fun` provides
47+
# the name of the ggplot2 function that uses this package, and is
48+
# used only to produce a meaningful error message if the
49+
# package is not available.
50+
#
51+
# Set `attach = TRUE` if you want to attach the package, not
52+
# just make sure it is available. It is generally recommended to
53+
# not set `attach = TRUE`.
54+
try_require <- function(package, fun, attach = FALSE) {
4655
if (requireNamespace(package, quietly = TRUE)) {
47-
library(package, character.only = TRUE)
56+
if (isTRUE(attach)) library(package, character.only = TRUE)
4857
return(invisible())
4958
}
5059

0 commit comments

Comments
 (0)