Skip to content

Commit

Permalink
Lint cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nenuial committed May 5, 2024
1 parent ffb6c07 commit 56d864c
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 129 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
^pkgdown$
^\.github$
^LICENSE\.md$
^\.lintr$
10 changes: 10 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -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)
)
18 changes: 12 additions & 6 deletions R/fonts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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")
}
3 changes: 0 additions & 3 deletions R/ggeo-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
## usethis namespace: end
NULL

# Globals
# utils::globalVariables(c(""))

#' @importFrom magrittr %>%
#' @export
magrittr::`%>%`
Expand Down
139 changes: 68 additions & 71 deletions R/ggplot_themes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions R/ggplot_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,7 +76,6 @@ ggeo_save <- function(plot,
dpi = 72,
units = "cm",
...) {

ggplot2::ggsave(
filename = filename,
width = width,
Expand Down
39 changes: 23 additions & 16 deletions R/palettes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
Expand Down Expand Up @@ -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!")
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 56d864c

Please sign in to comment.