Skip to content

Commit

Permalink
Force RColorBrewer to see grDevices::rgb with env shim
Browse files Browse the repository at this point in the history
fixes #1

Bump to version 0.1.1
  • Loading branch information
MilesMcBain committed Aug 7, 2021
1 parent 5fa2681 commit cc817d7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: paint
Title: paint data.frames summaries in colour
Version: 0.1.0
Version: 0.1.1
Authors@R:
person(given = "Miles",
family = "McBain",
Expand Down
34 changes: 29 additions & 5 deletions R/palettes.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,49 @@ viridis_6 <- function() lapply(viridisLite::viridis(6), crayon::make_style)
#' @rdname paintpals
#' @export
brewer_set3_12 <-
function() lapply(RColorBrewer::brewer.pal(12, name = "Set3"), crayon::make_style)
function() {
lapply(brewer_pal_safely(12, name = "Set3"), crayon::make_style)
}

#' @rdname paintpals
#' @export
brewer_pastel1_8 <-
function() lapply(RColorBrewer::brewer.pal(8, name = "Pastel1"), crayon::make_style)
function() lapply(brewer_pal_safely(8, name = "Pastel1"), crayon::make_style)

#' @rdname paintpals
#' @export
brewer_pastel2_7 <-
function() lapply(RColorBrewer::brewer.pal(7, name = "Pastel2"), crayon::make_style)
function() lapply(brewer_pal_safely(7, name = "Pastel2"), crayon::make_style)

#' @rdname paintpals
#' @export
brewer_dark2_7 <-
function() lapply(RColorBrewer::brewer.pal(7, name = "Dark2"), crayon::make_style)
function() lapply(brewer_pal_safely(7, name = "Dark2"), crayon::make_style)

#' @rdname paintpals
#' @export
brewer_accent_7 <-
function() lapply(RColorBrewer::brewer.pal(7, name = "Accent"), crayon::make_style)
function() lapply(brewer_pal_safely(7, name = "Accent"), crayon::make_style)


brewer_pal_safely <- function(...) {
shim_fun <- RColorBrewer::brewer.pal
shim_env <- new.env(parent = environment(shim_fun))
shim_env$rgb <- grDevices::rgb
environment(shim_fun) <- shim_env
shim_fun(...)
}

set_lib_paths <- function(lib_vec) {

lib_vec <- normalizePath(lib_vec, mustWork = TRUE)

shim_fun <- .libPaths
shim_env <- new.env(parent = environment(shim_fun))
shim_env$.Library <- character()
shim_env$.Library.site <- character()

environment(shim_fun) <- shim_env
shim_fun(lib_vec)

}

0 comments on commit cc817d7

Please sign in to comment.