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
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 23 additions & 8 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 @@ -107,10 +107,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 +131,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
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
Loading
Loading