@@ -50,11 +50,15 @@ StatQuantile <- ggproto("StatQuantile", Stat,
50
50
compute_group = function (data , scales , quantiles = c(0.25 , 0.5 , 0.75 ),
51
51
formula = NULL , xseq = NULL , method = " rq" ,
52
52
method.args = list (), lambda = 1 , na.rm = FALSE ) {
53
- try_require(" quantreg" , " stat_quantile" , attach = TRUE )
53
+ try_require(" quantreg" , " stat_quantile" )
54
54
55
55
if (is.null(formula )) {
56
56
if (method == " rqss" ) {
57
- try_require(" MatrixModels" , " stat_quantile" , attach = TRUE )
57
+ # this should not be needed, since quantreg imports MatrixModels
58
+ # try_require("MatrixModels", "stat_quantile")
59
+
60
+ # we need to attach quantreg for qss to work inside formula
61
+ require(" quantreg" )
58
62
formula <- eval(substitute(y ~ qss(x , lambda = lambda )),
59
63
list (lambda = lambda ))
60
64
} else {
@@ -73,7 +77,13 @@ StatQuantile <- ggproto("StatQuantile", Stat,
73
77
}
74
78
grid <- new_data_frame(list (x = xseq ))
75
79
76
- method <- match.fun(method )
80
+ # if method was specified as a character string, replace with
81
+ # the corresponding function
82
+ if (is.character(method )) {
83
+ if (identical(method , " rq" )) method <- quantreg :: rq
84
+ else if (identical(method , " rqss" )) method <- quantreg :: rqss
85
+ else method <- match.fun(method ) # allow users to supply their own methods
86
+ }
77
87
78
88
rbind_dfs(lapply(quantiles , quant_pred , data = data , method = method ,
79
89
formula = formula , weight = weight , grid = grid , method.args = method.args ))
0 commit comments