diff --git a/.Rbuildignore b/.Rbuildignore index b98c885..7712cbd 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,4 @@ ^pkgdown$ ^\.github$ ^LICENSE\.md$ +^\.lintr$ diff --git a/.lintr b/.lintr new file mode 100644 index 0000000..d9ae154 --- /dev/null +++ b/.lintr @@ -0,0 +1,10 @@ +linters: linters_with_defaults( + line_length_linter(120), + assignment_linter( + allow_cascading_assign = TRUE, + allow_right_assign = TRUE, + allow_trailing = TRUE, + allow_pipe_assign = FALSE + ), + object_length_linter(length = 100L) + ) diff --git a/R/fonts.R b/R/fonts.R index 2221987..b34927b 100644 --- a/R/fonts.R +++ b/R/fonts.R @@ -7,12 +7,12 @@ #' @export #' ggeo_install_fonts_macos <- function(system_wide = FALSE) { - new_font_path <- "~/Library/Fonts/" + new_font_path <- "~/Library/Fonts/" # nolint: object_usage_linter if (system_wide) new_font_path <- "/Library/Fonts/" fs::dir_ls(path = ggeo_file("fonts/")) |> purrr::walk( - .f = ~fs::file_copy( + .f = ~ fs::file_copy( path = .x, new_path = new_font_path, overwrite = TRUE @@ -29,7 +29,7 @@ ggeo_install_fonts_macos <- function(system_wide = FALSE) { ggeo_install_fonts_linux <- function() { fs::dir_ls(path = ggeo_file("fonts/")) |> purrr::walk( - .f = ~fs::file_copy( + .f = ~ fs::file_copy( path = .x, new_path = "~/.local/share/fonts/", overwrite = TRUE @@ -38,7 +38,7 @@ ggeo_install_fonts_linux <- function() { fs::dir_ls(path = ggeo_file("fonts/")) |> purrr::walk( - .f = ~fs::file_copy( + .f = ~ fs::file_copy( path = .x, new_path = "~/.local/share/fonts/", overwrite = TRUE @@ -51,7 +51,13 @@ ggeo_install_fonts_linux <- function() { #' @export #' @keywords internal ggeo_register_fonts <- function() { - sysfonts::font_add("Fira Sans", regular = "FiraSans-Regular.otf", bold = "FiraSans-Bold.otf", italic = "FiraSans-Italic.otf") - sysfonts::font_add("Fira Sans Light", regular = "FiraSans-Light.otf", italic = "FiraSans-LightItalic.otf") + sysfonts::font_add("Fira Sans", + regular = "FiraSans-Regular.otf", + bold = "FiraSans-Bold.otf", italic = "FiraSans-Italic.otf" + ) + sysfonts::font_add("Fira Sans Light", + regular = "FiraSans-Light.otf", + italic = "FiraSans-LightItalic.otf" + ) sysfonts::font_add("Helvetica", regular = "Helvetica.ttc") } diff --git a/R/ggeo-package.R b/R/ggeo-package.R index a736324..3ebdb77 100644 --- a/R/ggeo-package.R +++ b/R/ggeo-package.R @@ -5,9 +5,6 @@ ## usethis namespace: end NULL -# Globals -# utils::globalVariables(c("")) - #' @importFrom magrittr %>% #' @export magrittr::`%>%` diff --git a/R/ggplot_themes.R b/R/ggplot_themes.R index e495540..c3b8c15 100644 --- a/R/ggplot_themes.R +++ b/R/ggplot_themes.R @@ -20,84 +20,81 @@ #' ggplot2::geom_point() + #' ggeotheme("ghibli_mononoke") #' -ggeotheme <- function(theme = c("ghibli_mononoke", "islamic_samarquand", - "pomological_green", "pomological_red", - "nord_blue", "swiss_red", "purple", - "doc", "oc_exams"), - main = "main", - plot = "plot", - ..., - mode = c("light", "dark"), - base = ggplot2::theme_bw()) { - +ggeotheme <- function( + theme = c( + "ghibli_mononoke", "islamic_samarquand", + "pomological_green", "pomological_red", + "nord_blue", "swiss_red", "purple", + "doc", "oc_exams" + ), + main = "main", + plot = "plot", + ..., + mode = c("light", "dark"), + base = ggplot2::theme_bw()) { theme <- match.arg(theme) mode <- match.arg(mode) main <- match.arg(main, choices = c("main", "main_exa", "main_latex", "main_svg")) plot <- match.arg(plot, choices = c("plot", "plot_exa", "plot_latex", "plot_svg")) theme <- (base + - ggplot2::theme(rect = - ggplot2::element_rect(fill = "transparent", color = NA), - line = - ggplot2::element_line(color = ggeodata$themes[[theme]][[mode]]$line), - text = - ggplot2::element_text(family = ggeodata$themes[[main]]$text$family, - size = ggeodata$themes[[main]]$text$size, - face = ggeodata$themes[[main]]$text$face, - color = ggeodata$themes[[theme]][[mode]]$text), - title = - ggplot2::element_text(family = ggeodata$themes[[main]]$title$family, - size = ggeodata$themes[[main]]$title$size, - face = ggeodata$themes[[main]]$title$face, - color = ggeodata$themes[[theme]][[mode]]$title), - - axis.text = - ggplot2::element_text(family = ggeodata$themes[[main]]$text$family, - size = ggeodata$themes[[main]]$text$size, - face = ggeodata$themes[[main]]$text$face, - color = ggeodata$themes[[theme]][[mode]]$text), - - legend.key = - ggplot2::element_blank(), - legend.text = - ggplot2::element_text(family = ggeodata$themes[[main]]$text$family, - size = ggeodata$themes[[main]]$text$size, - face = ggeodata$themes[[main]]$text$face, - color = ggeodata$themes[[theme]][[mode]]$text), - - panel.background = - ggplot2::element_rect(fill = "transparent", color = NA), - panel.border = - ggplot2::element_rect(color = ggeodata$themes[[theme]][[mode]]$line), - panel.grid = - ggplot2::element_blank(), - #ggplot2::element_line(color = ggeodata$themes[[theme]][[mode]]$grid), - - plot.background = - ggplot2::element_rect(fill = "transparent", color = NA), - plot.caption = - ggplot2::element_text(family = ggeodata$themes[[plot]]$caption$family, - size = ggeodata$themes[[plot]]$caption$size, - face = ggeodata$themes[[plot]]$caption$face, - color = ggeodata$themes[[theme]][[mode]]$text), - plot.margin = - ggeodata$themes[[plot]]$margin, + ggplot2::theme( + rect = ggplot2::element_rect(fill = "transparent", color = NA), + line = ggplot2::element_line(color = ggeodata$themes[[theme]][[mode]]$line), + text = ggplot2::element_text( + family = ggeodata$themes[[main]]$text$family, + size = ggeodata$themes[[main]]$text$size, + face = ggeodata$themes[[main]]$text$face, + color = ggeodata$themes[[theme]][[mode]]$text + ), + title = ggplot2::element_text( + family = ggeodata$themes[[main]]$title$family, + size = ggeodata$themes[[main]]$title$size, + face = ggeodata$themes[[main]]$title$face, + color = ggeodata$themes[[theme]][[mode]]$title + ), + axis.text = ggplot2::element_text( + family = ggeodata$themes[[main]]$text$family, + size = ggeodata$themes[[main]]$text$size, + face = ggeodata$themes[[main]]$text$face, + color = ggeodata$themes[[theme]][[mode]]$text + ), + legend.key = ggplot2::element_blank(), + legend.text = ggplot2::element_text( + family = ggeodata$themes[[main]]$text$family, + size = ggeodata$themes[[main]]$text$size, + face = ggeodata$themes[[main]]$text$face, + color = ggeodata$themes[[theme]][[mode]]$text + ), + panel.background = ggplot2::element_rect(fill = "transparent", color = NA), + panel.border = ggplot2::element_rect( + color = ggeodata$themes[[theme]][[mode]]$line + ), + panel.grid = ggplot2::element_blank(), - plot.title = - ggplot2::element_text(family = ggeodata$themes[[plot]]$title$family, - size = ggeodata$themes[[plot]]$title$size, - face = ggeodata$themes[[plot]]$title$face, - color = ggeodata$themes[[theme]][[mode]]$title), - plot.title.position = - "plot", - plot.subtitle = - ggplot2::element_text(family = ggeodata$themes[[plot]]$subtitle$family, - size = ggeodata$themes[[plot]]$subtitle$size, - face = ggeodata$themes[[plot]]$subtitle$face, - color = ggeodata$themes[[theme]][[mode]]$title, - margin = ggeodata$themes[[plot]]$subtitle_margin) - ) + - ggplot2::theme(...) + plot.background = ggplot2::element_rect(fill = "transparent", color = NA), + plot.caption = ggplot2::element_text( + family = ggeodata$themes[[plot]]$caption$family, + size = ggeodata$themes[[plot]]$caption$size, + face = ggeodata$themes[[plot]]$caption$face, + color = ggeodata$themes[[theme]][[mode]]$text + ), + plot.margin = ggeodata$themes[[plot]]$margin, + plot.title = ggplot2::element_text( + family = ggeodata$themes[[plot]]$title$family, + size = ggeodata$themes[[plot]]$title$size, + face = ggeodata$themes[[plot]]$title$face, + color = ggeodata$themes[[theme]][[mode]]$title + ), + plot.title.position = "plot", + plot.subtitle = ggplot2::element_text( + family = ggeodata$themes[[plot]]$subtitle$family, + size = ggeodata$themes[[plot]]$subtitle$size, + face = ggeodata$themes[[plot]]$subtitle$face, + color = ggeodata$themes[[theme]][[mode]]$title, + margin = ggeodata$themes[[plot]]$subtitle_margin + ) + ) + ggplot2::theme(...) ) return(theme) diff --git a/R/ggplot_utils.R b/R/ggplot_utils.R index 4889b29..3791e7c 100644 --- a/R/ggplot_utils.R +++ b/R/ggplot_utils.R @@ -21,29 +21,30 @@ ggeosave <- function(filename, ..., units = "cm", extension = "pdf", device = grDevices::cairo_pdf) { - lifecycle::deprecate_warn("1.0.0", "ggeosave()", "ggeo_save()") format <- match.arg(format) switch(format, - keynote = { - width <- 63.5 - height <- 28.57 - dpi <- 72 - } + keynote = { + width <- 63.5 + height <- 28.57 + dpi <- 72 + } ) - if(stringr::str_detect(filename, "^/")) { + if (stringr::str_detect(filename, "^/")) { filepath <- filename } else { filepath <- glue::glue("out/{filename}.{extension}") } - ggplot2::ggsave(filename = filepath, - width = width, height = height, dpi = dpi, units = units, - bg = "transparent", device = device, - ...) + ggplot2::ggsave( + filename = filepath, + width = width, height = height, dpi = dpi, units = units, + bg = "transparent", device = device, + ... + ) } #' Save function @@ -75,7 +76,6 @@ ggeo_save <- function(plot, dpi = 72, units = "cm", ...) { - ggplot2::ggsave( filename = filename, width = width, diff --git a/R/palettes.R b/R/palettes.R index 672c8ae..a5857a8 100644 --- a/R/palettes.R +++ b/R/palettes.R @@ -14,7 +14,7 @@ palette_chooser <- function(n, params) { lifecycle::deprecate_warn("1.0.0", "palette_chooser()", "ggeo_palette_chooser()") - ggeo_palette_chooser(n, params) + ggeopal_chooser(n, params) } #' Return a paletteer palette depending on @@ -31,17 +31,23 @@ palette_chooser <- function(n, params) { #' @return A vector of colors ggeopal_chooser <- function(n, params) { if (params$type == "cont") { - paletteer::paletteer_c(palette = params$palette, - n = n, - direction = params$dir) + paletteer::paletteer_c( + palette = params$palette, + n = n, + direction = params$dir + ) } else if (params$type == "dis") { - paletteer::paletteer_d(palette = params$palette, - n = n, - direction = params$dir) + paletteer::paletteer_d( + palette = params$palette, + n = n, + direction = params$dir + ) } else if (params$type == "dyn") { - paletteer::paletteer_dynamic(palette = params$palette, - n = n, - direction = params$dir) + paletteer::paletteer_dynamic( + palette = params$palette, + n = n, + direction = params$dir + ) } else { stop("Palette type is unmatched") } @@ -89,7 +95,6 @@ ggeopal_center <- function(n, center, params) { } else if (center > (n / 2)) { colors <- palette_chooser((center - 1) * 2 + 1, params) utils::head(colors, n) - } else { stop("Can't create color palette. Check parameters!") } @@ -121,11 +126,13 @@ ggeopal_hex_to_hcl <- function(hex, n = 4) { color_c <- color@coords[2] color_h <- color@coords[3] - colorspace::sequential_hcl(n = n + 1, - h = color_h, - c = c(color_c, color_c, NA), - l = c(color_l, 100), - power = 1.75)[seq_len(n)] + colorspace::sequential_hcl( + n = n + 1, + h = color_h, + c = c(color_c, color_c, NA), + l = c(color_l, 100), + power = 1.75 + )[seq_len(n)] } #' Create gradient for palette colors diff --git a/R/zzz.R b/R/zzz.R index 75a0b61..de4ff2d 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -6,11 +6,11 @@ #' #' @keywords internal #' @export -ggeo_file = function(...) { - system.file(..., package = 'ggeo', mustWork = TRUE) +ggeo_file <- function(...) { + system.file(..., package = "ggeo", mustWork = TRUE) } -.onLoad = function(lib, pkg) { +.onLoad <- function(lib, pkg) { # Use showtext ------------------------------------------------------------ showtext::showtext_auto() diff --git a/README.md b/README.md index d8dcebf..4b73f76 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ remotes::install_github("Nenuial/ggeo") Or from r-universe: ``` r -install.packages("ggeo", repos = c("https://nenuial.r-universe.dev")) +install.packages('geographer', repos = c('https://nenuial.r-universe.dev', 'https://cloud.r-project.org')) ``` ## Documentation diff --git a/data-raw/ggeodata.R b/data-raw/ggeodata.R index 67c4abb..977cff9 100644 --- a/data-raw/ggeodata.R +++ b/data-raw/ggeodata.R @@ -2,7 +2,6 @@ ggeodata <- list( themes = list( # Theme main elements ----------------------------------------------------- - main = list( text = list( size = 24, @@ -15,7 +14,6 @@ ggeodata <- list( family = "Fira Sans" ) ), - main_svg = list( text = list( size = 12, @@ -28,7 +26,6 @@ ggeodata <- list( family = "Fira Sans" ) ), - main_exa = list( text = list( size = 11, @@ -41,7 +38,6 @@ ggeodata <- list( family = "Helvetica" ) ), - main_latex = list( text = list( size = 11, @@ -79,7 +75,6 @@ ggeodata <- list( ), margin = ggplot2::margin(l = .1, t = 1, b = .5, r = 1, unit = "cm") ), - plot_svg = list( title = list( size = 28, @@ -102,7 +97,6 @@ ggeodata <- list( ), margin = ggplot2::margin(l = .1, t = .2, b = .2, r = .1, unit = "cm") ), - plot_exa = list( title = list( size = 14, @@ -125,7 +119,6 @@ ggeodata <- list( ), margin = ggplot2::margin(l = .1, t = .1, b = .1, r = .5, unit = "cm") ), - plot_latex = list( title = list( size = 11, @@ -165,7 +158,6 @@ ggeodata <- list( grid = "#3b4457" ) ), - ghibli_mononoke = list( light = list( text = "#762b19", @@ -180,7 +172,6 @@ ggeodata <- list( grid = "#8891aa" ) ), - pomological_green = list( light = list( text = "#2b323f", @@ -195,7 +186,6 @@ ggeodata <- list( grid = "#818585" ) ), - pomological_red = list( light = list( text = "#2b323f", @@ -210,7 +200,6 @@ ggeodata <- list( grid = "#818585" ) ), - islamic_samarquand = list( light = list( text = "#a58c60", @@ -225,7 +214,6 @@ ggeodata <- list( grid = "#b7daec" ) ), - swiss_red = list( light = list( text = "#3a3e3f", @@ -240,7 +228,6 @@ ggeodata <- list( grid = "#b2b3b3" ) ), - purple = list( light = list( text = "#303088", @@ -255,7 +242,6 @@ ggeodata <- list( grid = "#faeff1" ) ), - doc = list( light = list( text = "black", @@ -270,7 +256,6 @@ ggeodata <- list( grid = "#696969" ) ), - oc_exam = list( light = list( text = "black", @@ -289,5 +274,6 @@ ggeodata <- list( ) usethis::use_data(ggeodata, - internal = TRUE, - overwrite = TRUE) + internal = TRUE, + overwrite = TRUE +)