Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forthcoming ggplot2 release and PepsNMR #12

Closed
paleolimbot opened this issue May 9, 2019 · 2 comments
Closed

Forthcoming ggplot2 release and PepsNMR #12

paleolimbot opened this issue May 9, 2019 · 2 comments

Comments

@paleolimbot
Copy link

We're in the process of preparing a ggplot2 release. As part of the release process, we run the R CMD check on packages that use ggplot2 to make sure we don't accidentally break code for downstream packages.

In running the R CMD check on PepsNMR, we identified the following issue:

  • checking examples ... ERROR
    Running examples in ‘PepsNMR-Ex.R’ failed
    The error most likely occurred in:
    
    > ### Name: DrawPCA
    > ### Title: Draw the PCA scores or loadings of the signals
    > ### Aliases: DrawPCA
    > ### Keywords: hplot
    >
    > ### ** Examples
    >
    > require(PepsNMRData)
    Loading required package: PepsNMRData
    > # Draw loadings
    > DrawPCA(FinalSpectra_HS, main = "PCA loadings plot",
    +       Class = NULL, axes =c(1,3, 5), type ="loadings", loadingstype="l",
    +       num.stacked=4, xlab="ppm", createWindow = TRUE)
    dev.new(): using pdf(file="Rplots2.pdf")
    Error: Aesthetics must be either length 1 or the same as the data (9): label
    Execution halted
    

This error is occuring because PepsNMR was relying on undefined behaviour of annotate(), which isn't designed to draw different items on each facet. To fix this error, we suggest using a geom_*() function with its own data. Note that using .data$col_name within aes() is the preferred way to avoid CMD check issues about undefined variables when mapping columns (make sure you include #' importFrom rlang .data in at least one roxygen documentation block to avoid an error about the name .data being undefined).

library(ggplot2)

plot_data <- data.frame(
  facet = c("facet 1", "facet 2"),
  x = c(1, 2),
  y = c(1, 2)
)

facet_labels <- data.frame(
  facet = c("facet 1", "facet 2"),
  label = c("Text on facet 1", "Text on facet 2")
)

# to silence CMD check
# in the future you will be able to use ggplot2::vars(.data$facet)
# but this is currently not supported (tidyverse/ggplot2#2963)
facet <- NULL; rm(facet)

ggplot2::ggplot(plot_data, aes(x = .data$x, y = .data$y)) +
  ggplot2::geom_point() +
  ggplot2::geom_text(
    ggplot2::aes(label = .data$label, x = .data$x, y = .data$y),
    data = facet_labels,
    x = 1.5,
    y = 1.5
  ) +
  ggplot2::facet_wrap(ggplot2::vars(facet))

We hope to release the new version of ggplot2 in the next two weeks, at which point you will get a note from CRAN that your package checks are failing. Let me know if I can help!

@ManonMartin
Copy link
Owner

Hi,
Thank you for the check on PepsNMR, I followed your directives to prevent the future issue of happening and it should work now!

@paleolimbot
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants