Skip to content

CRAN check failing due to ggplot2 errors (only on Windows devel) #5702

Closed
@samuel-marsh

Description

@samuel-marsh

Hi ggplot2 team,

I'm author and maintainer of CRAN package scCustomize. Starting yesterday (feb-21) I'm getting ggplot2 related errors when running devtools::check_win_devel() but did not receive same error when running on Friday Feb-16. The errors are coming from a function that I have never had issue with before and my debugging attempts have left me a little stumped.

The functions in question related to use of a custom ggplot2 theme. See here for full plotting code in function context plotting elements are as follows:

# "group.by" is user supplied variable/column name used in the created of data.frame "merged".
plot <- ggplot(data = merged, mapping = aes(x = .data[[group_by]], y = .data[["Median_nFeature_RNA"]], fill = .data[[group_by]])) +
      geom_boxplot(fill = "white") +
      geom_dotplot(binaxis ='y', stackdir = 'center', dotsize = dot_size) +
      scale_fill_manual(values = colors_use) +
      theme_ggprism_mod() +
      ggtitle(plot_title) +
      ylab(y_axis_label) +
      xlab("")

The error (that again was not present when running checks last week) is:

Error 1
* checking examples ... [25s] ERROR
Running examples in 'scCustomize-Ex.R' failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: Plot_Median_Genes
> ### Title: Plot Median Genes per Cell per Sample
> ### Aliases: Plot_Median_Genes
> 
> ### ** Examples
> 
> library(Seurat)
> # Create example groups
> pbmc_small$sample_id <- sample(c("sample1", "sample2"), size = ncol(pbmc_small), replace = TRUE)
> 
> # Plot
> Plot_Median_Genes(seurat_object = pbmc_small, sample_col = "orig.ident",  group_by = "sample_id")
Bin width defaults to 1/30 of the range of the data. Pick better value with
`binwidth`.
Error in `plot_theme()`:
! The `legend.text.align` theme element is not defined in the element
  hierarchy.
Backtrace:1. ├─base (local) `<fn>`(x)
  2. └─ggplot2:::print.ggplot(x)
  3.   ├─ggplot2::ggplot_gtable(data)
  4.   └─ggplot2:::ggplot_gtable.ggplot_built(data)
  5.     └─ggplot2:::plot_theme(plot)
  6.       └─ggplot2:::validate_theme(theme)
  7.         └─base::mapply(...)
  8.           └─ggplot2 (local) `<fn>`(...)
  9.             └─cli::cli_abort(...)
 10.               └─rlang::abort(...)
Execution halted
* checking PDF version of manual ... [17s] OK
* checking HTML version of manual ... [21s] OK
* DONE
Status: 1 ERROR

The theme theme_ggprism_mod is extension of this theme from CRAN package ggprism (which does define legend.text.align)

My function extending this theme can be found here and the code is:

theme_ggprism_mod <- function(
  palette = "black_and_white",
  base_size = 14,
  base_family = "sans",
  base_fontface = "bold",
  base_line_size = base_size / 20,
  base_rect_size = base_size / 20,
  axis_text_angle = 0,
  border = FALSE
) {
  theme_prism(palette = palette,
              base_size = base_size,
              base_family = base_family,
              base_fontface = base_fontface,
              base_line_size = base_line_size,
              base_rect_size = base_rect_size,
              axis_text_angle = axis_text_angle,
              border = border) %+replace%
    theme(legend.title = element_text(hjust = 0),
          axis.text = element_text(size = rel(0.95), face = "plain")
    )
}

To debug things as this error does not occur on testing with any other platform I simply added dontrun to the examples and ran check again.

The identical error came back testing the example code of the theme extension in my package theme_ggprism_mod

library(ggplot2)
df <- data.frame(x = rnorm(n = 100, mean = 20, sd = 2), y = rbinom(n = 100, size = 100, prob = 0.2))
p <- ggplot(data = df, mapping = aes(x = x, y = y)) + geom_point(mapping = aes(color = 'red'))
p + theme_ggprism_mod()

To debug further I removed dontrun and swapped out my modified theme for the original theme from ggprism:

    plot <- ggplot(merged, aes(x = .data[["samples_plotting"]], y = .data[["Median_nFeature_RNA"]])) +
      geom_boxplot(fill = "white", outlier.color = NA) +
      geom_quasirandom() +
      ggtitle(plot_title) +
      ylab(y_axis_label) +
      xlab("") +
      theme_prism()

However, I still get the same error.

So at this point I'm a bit stumped because it seems my theme modification is fine and the plotting functions, theme modification, and ggprism have all been through multiple previous CRAN releases without issue.

Also as I mentioned these errors were not present in checks run on Feb 16th. Is this potentially just an issue of instability in the Windows R dev build? Since the errors were coming from ggplot2 that seemed unlikely to me but maybe you have more insight.

Hoping you might be able to provide some insight.
Thanks in advance!!
Sam

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions