Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Normalize line endings across platforms.
# Store text files with LF in the repo; check them out with LF everywhere.
* text=auto eol=lf

# Explicit text files
*.R text eol=lf
*.Rmd text eol=lf
*.Rd text eol=lf
*.md text eol=lf
*.Rproj text eol=lf
*.yaml text eol=lf
*.yml text eol=lf
*.csv text eol=lf
DESCRIPTION text eol=lf
NAMESPACE text eol=lf
LICENSE text eol=lf
.gitignore text eol=lf
.Rbuildignore text eol=lf

# Binary files (never touch line endings)
*.rda binary
*.RData binary
*.rds binary
*.png binary
*.jpg binary
*.jpeg binary
*.ico binary
*.svg binary
*.pdf binary
95 changes: 32 additions & 63 deletions .github/workflows/check-standard.yaml
Original file line number Diff line number Diff line change
@@ -1,91 +1,60 @@
# Automatically checks the package on Windows and Mac each time master branch
# (or a pull request to master) gets a new commit.
# Based on <https://github.com/r-lib/actions/blob/master/examples/check-standard.yaml>.
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
# Runs `R CMD check` on macOS, Windows, and Linux, across a matrix of R and
# ggplot2 versions, on pushes to main/master and on pull requests.
# Derived from https://github.com/r-lib/actions/tree/v2/examples (check-standard).
on:
push:
branches:
- main
- master
branches: [main, master]
pull_request:
branches:
- main
- master

name: R-CMD-check

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})
name: ${{ matrix.config.os }} (R ${{ matrix.config.r }}${{ matrix.config.ggplot2 == 'devel' && ', ggplot2-dev' || '' }})

# The ggplot2-devel entry is a forward-compatibility canary: it surfaces
# breakage from upcoming ggplot2 releases (e.g. the `theme_set()` and
# `size`->`linewidth` issues) but is allowed to fail without blocking.
continue-on-error: ${{ matrix.config.allow_failure || false }}

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
#- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
#- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'release', ggplot2: 'devel', allow_failure: true}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-pandoc@v2

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v3
- uses: r-lib/actions/setup-r-dependencies@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

#- name: Install system dependencies
# if: runner.os == 'Linux'
# run: |
# while read -r cmd
# do
# eval sudo $cmd
# done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')

- name: Install XQuartz on macOS
if: runner.os == 'macOS'
run: |
brew install --cask xquartz

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "error", check_dir = "check")
shell: Rscript {0}
extra-packages: >-
any::rcmdcheck
${{ matrix.config.ggplot2 == 'devel' && 'github::tidyverse/ggplot2' || '' }}
needs: check

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
- uses: r-lib/actions/check-r-package@v2
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
args: 'c("--no-manual", "--as-cran")'
error-on: '"error"'
upload-snapshots: true
6 changes: 3 additions & 3 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2

- uses: r-lib/actions/setup-pandoc@v2

- name: Checkout CMAP fonts repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: CMAP-REPOS/cmap-fonts
token: ${{ secrets.CMAP_REPO_FULL_ACCESS }}
Expand All @@ -47,7 +47,7 @@ jobs:
shell: Rscript {0}

- name: Cache R packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
Expand Down
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Encoding: UTF-8
LazyData: true
Depends:
R (>= 3.5.0),
ggplot2
ggplot2 (>= 3.4.0)
Imports:
dplyr,
generics,
Expand All @@ -51,7 +51,6 @@ Imports:
lubridate,
purrr,
ragg,
Rcpp,
rlang,
rstudioapi,
scales,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export(unapply_cmap_default_aes)
export(update_recessions)
export(viz_gradient)
export(viz_palette)
import(Rcpp)
import(dplyr)
import(ggplot2)
import(ggrepel)
Expand Down
57 changes: 42 additions & 15 deletions R/cmapplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#'
#' @name cmapplot
#' @docType package
#' @import dplyr ggplot2 graphics grDevices grid gridtext Rcpp ragg rlang scales systemfonts
#' @import dplyr ggplot2 graphics grDevices grid gridtext ragg rlang scales systemfonts
#' @importFrom glue glue glue_collapse
#' @keywords internal
"_PACKAGE"
Expand Down Expand Up @@ -42,13 +42,25 @@
whitney_paths <- dplyr::filter(systemfonts::system_fonts(), family == "Whitney")
whitney_paths <- whitney_paths[["path"]]

# On some OSX systems (e.g. pkgdown GHA VM) system_fonts() cannot find fonts
# installed in the user fonts directory. In any case where system_fonts()
# sees no Whitney fonts, if `user_dir` exists, it too is checked for fonts.
user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts")
if(length(whitney_paths) == 0 & dir.exists(user_dir)){
whitney_paths <- list.files(user_dir, full.names = TRUE)
whitney_paths <- grep("Whitney-", whitney_paths, value = TRUE)
# On some systems (e.g. the pkgdown GHA VM) system_fonts() cannot find fonts
# installed in a user fonts directory. Where system_fonts() finds no Whitney
# fonts, also search the platform's user font directories directly:
# macOS: ~/Library/Fonts
# Windows: %LOCALAPPDATA%/Microsoft/Windows/Fonts
# Linux: ~/.local/share/fonts and ~/.fonts
if(length(whitney_paths) == 0){
user_font_dirs <- c(
file.path(Sys.getenv("HOME"), "Library", "Fonts"),
file.path(Sys.getenv("LOCALAPPDATA"), "Microsoft", "Windows", "Fonts"),
file.path(Sys.getenv("HOME"), ".local", "share", "fonts"),
file.path(Sys.getenv("HOME"), ".fonts")
)
user_font_dirs <- user_font_dirs[dir.exists(user_font_dirs)]
if(length(user_font_dirs) > 0){
whitney_paths <- grep("Whitney-",
list.files(user_font_dirs, full.names = TRUE),
value = TRUE)
}
}

# Register preferred fonts using the paths found above. This will only be
Expand Down Expand Up @@ -107,10 +119,18 @@
light = list(family = cmapplot_globals$preferred_font$light, face = "plain")),
envir = cmapplot_globals)

# ... and check on rstudio graphics
if (rstudioapi::isAvailable()){
if(rstudioapi::getVersion() > "1.4"){
if(getOption("RStudioGD.backend", FALSE) != "ragg"){
# ... and set up the graphics backend so Whitney renders in the plot window.
# Detect the IDE via environment variables rather than rstudioapi: Positron
# ships a partial rstudioapi shim, so isAvailable() returns TRUE there and
# getVersion() can error outside RStudio. RStudio sets RSTUDIO=1; Positron
# sets POSITRON_VERSION.
in_rstudio <- Sys.getenv("RSTUDIO") == "1"
in_positron <- Sys.getenv("POSITRON_VERSION") != ""

if (in_rstudio) {
# RStudio >= 1.4 can render registered fonts via the ragg backend.
if (rstudioapi::isAvailable() && rstudioapi::getVersion() > "1.4") {
if (!identical(getOption("RStudioGD.backend"), "ragg")) {
options(RStudioGD.backend = "ragg")
packageStartupMessage(paste(
"cmapplot has set RStudio graphics to `ragg` for the current session.",
Expand All @@ -123,12 +143,19 @@
"cmapplot requires RStudio v1.4 or greater to use Whitney fonts",
"in the R plots window.\nPlease update RStudio."))
}
# If using vanilla R, encourage RStudio installation
} else if (in_positron) {
# Positron's graphics device automatically uses ragg when it is installed.
# ragg is a hard dependency of cmapplot, so no backend option is needed.
packageStartupMessage(
"cmapplot will use Positron's graphics device to render Whitney fonts."
)
# If using vanilla R (no supported IDE), note the limitation.
} else {
packageStartupMessage(paste(
"cmapplot requires RStudio to use Whitney fonts in the R plots window.\n ",
"Please install RStudio. <https://www.rstudio.com>"))
"cmapplot renders Whitney fonts in the plot window when run in RStudio or Positron.\n ",
"In plain R, use finalize_plot()'s export modes to produce graphics with Whitney fonts."))
}

# Otherwise, notify user
} else {
packageStartupMessage(
Expand Down
2 changes: 1 addition & 1 deletion R/default_aes.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ init_cmap_default_aes <- function() {
colour = cmapplot_globals$colors$blackish
),
Line = list(
size = gg_lwd_convert(cmapplot_globals$consts$lwd_plotline)
linewidth = gg_lwd_convert(cmapplot_globals$consts$lwd_plotline)
),
Text = list(
family = cmapplot_globals$font$strong$family,
Expand Down
8 changes: 8 additions & 0 deletions R/finalize_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ finalize_plot <- function(plot = NULL,
caption <- input_caption
}

# gridtext parses `title` and `caption` as markdown. A newline followed by
# indentation is read as an indented code block (an unsupported <pre> tag),
# which errors in textbox_grob(). Collapse any newline plus surrounding
# spaces/tabs to a single space so multi-line strings (often indented in
# source code) render as continuous text. Use <br> for explicit line breaks.
title <- gsub("[ \t]*\n[ \t]*", " ", title)
caption <- gsub("[ \t]*\n[ \t]*", " ", caption)

# Build necessary grobs -----------------------------------------------------
grobs <- list()

Expand Down
4 changes: 2 additions & 2 deletions R/geom_pandemics.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ GeomPandemics <- ggproto(
default_aes = aes(
colour = NA,
alpha = 0.11,
size = 0.5,
linewidth = 0.5,
linetype = 1,
na.rm = TRUE,
show.legend = FALSE
Expand Down Expand Up @@ -334,7 +334,7 @@ GeomPandemics <- ggproto(
gp = gpar(
col = coords$colour,
fill = alpha(coords$fill, coords$alpha),
lwd = coords$size * .pt,
lwd = coords$linewidth * .pt,
lty = coords$linetype,
linejoin = linejoin,
# `lineend` is a workaround for Windows and intentionally kept unexposed
Expand Down
Loading
Loading