Kevin, This vignette from ggplot2 itself gives the "officially recommended" ways to avoid the warnings from R CMD check
https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html Cheers, -Robert On Thu, Apr 22, 2021 at 4:39 PM Paul SAVARY <[email protected]> wrote: > Hi Kevin, > > I was faced to the same problem and I used 'aes_string()' instead of > 'aes()'. You can then just write the name of the columns containing the > data to plot as character strings. > > Example: > > myPlot <- function(myData, ...) { > # get ready > ggplot(myData, aes_string(x = "myX", y = "myY")) + > # add my decorations > theme_bw() > } > > It is probably already the case for your function but you need to include > #' @import ggplot2 in your function preamble (if I am not wrong). > > Kind regards > Paul > > ----- Mail original ----- > De: "Kevin R. Coombes" <[email protected]> > À: "r-package-devel" <[email protected]> > Envoyé: Jeudi 22 Avril 2021 22:28:55 > Objet: [R-pkg-devel] Using ggplot2 within another package > > Hi, > > I'm trying to help clean up an R package for someone else to submit to > CRAN. He has used ggplot2 to implement a plotting function for the kinds > of things that his packages generates. His plotting routine basically > looks like (after changing names to protect the innocent): > > myPlot <- fucntion(myData, ...) { > # get ready > ggplot(myData, aes(x = myX, y = myY)) + > # add my decorations > theme_bw() > } > > Of course, "R CMD check --as-cran" complains that there is no global > binding for "myX" or "myY" since they are columns defined in the > data.frame "myData". > > What is the best way to work around this issue? > > Of course, dinosaurs like myself might be tempted to suggest just using > plain old "plot", so I don't need to see those suggestions. > > Do I just ignore the usual ggplot conventions and write "myData$myX" > inside "aes" in order to appease the CRAN checker? Or is there some > tidy-er way to solve this problem? > > Thanks, > Kevin > > ______________________________________________ > [email protected] mailing list > https://stat.ethz.ch/mailman/listinfo/r-package-devel > > ______________________________________________ > [email protected] mailing list > https://stat.ethz.ch/mailman/listinfo/r-package-devel > [[alternative HTML version deleted]] ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
