@@ -145,13 +145,13 @@ color_scheme_set <- function(scheme = "blue") {
145
145
# ' @rdname bayesplot-colors
146
146
# ' @md
147
147
# ' @export
148
- # ' @param i For `color_scheme_get()`, a subset of the integers from `1`
148
+ # ' @param i For `color_scheme_get()`, an optional subset of the integers from `1`
149
149
# ' (lightest) to `6` (darkest) indicating which of the colors in the
150
150
# ' scheme to return. If `i` is not specified then all six colors in the
151
151
# ' scheme are included.
152
152
# '
153
- color_scheme_get <- function (scheme , i ) {
154
- if (! missing (scheme )) {
153
+ color_scheme_get <- function (scheme = NULL , i = NULL ) {
154
+ if (! is.null (scheme )) {
155
155
scheme <- scheme_from_string(scheme )
156
156
} else {
157
157
x <- .bayesplot_aesthetics $ scheme
@@ -160,7 +160,8 @@ color_scheme_get <- function(scheme, i) {
160
160
attr(scheme , " scheme_name" ) <- attr(x , " scheme_name" )
161
161
}
162
162
class(scheme ) <- c(" bayesplot_scheme" , " list" )
163
- if (missing(i )) {
163
+
164
+ if (is.null(i )) {
164
165
return (scheme )
165
166
} else if (is.character(i )) {
166
167
return (get_color(i ))
@@ -179,7 +180,6 @@ color_scheme_view <- function(scheme = NULL) {
179
180
if (is.null(scheme ) || length(scheme ) == 1 ){
180
181
return (plot_scheme(scheme ))
181
182
}
182
-
183
183
bayesplot_grid(
184
184
plots = lapply(scheme , plot_scheme ),
185
185
grid_args = list (ncol = length(scheme ))
@@ -192,6 +192,7 @@ print.bayesplot_scheme <- function(x, ...) {
192
192
colnames(tab ) <- attr(x , " scheme_name" ) %|| % " hex_color"
193
193
print(tab , ... )
194
194
}
195
+
195
196
# ' @export
196
197
plot.bayesplot_scheme <- function (x , ... ) {
197
198
scheme <- attr(x , " scheme_name" ) %|| % stop(" Scheme name not found." )
@@ -339,8 +340,9 @@ prepare_custom_colors <- function(scheme) {
339
340
not_found <- character (0 )
340
341
for (j in seq_along(scheme )) {
341
342
clr <- scheme [j ]
342
- if (! is_hex_color(clr ) && ! clr %in% grDevices :: colors())
343
+ if (! is_hex_color(clr ) && ! clr %in% grDevices :: colors()) {
343
344
not_found <- c(not_found , clr )
345
+ }
344
346
}
345
347
if (length(not_found )) {
346
348
stop(
0 commit comments