Hi everyone, One suggestion would be import ggplot2 and using tidy eval operators to create a function. One simple reproducible example would be
library(ggplot2) my_hist <- function(df, var){ ggplot(df, aes({{var}})) + geom_histogram() } df <- data.frame(my_var = rnorm(400, 10, 2)) my_hist(df = df, var = my_var) All the best Tiago Em sex., 23 de abr. de 2021 às 09:04, Mike Collyer <mlcoll...@gmail.com> escreveu: > Hi Kevin, > > I recently developed a plot function in a package that used ggplot and ran > into the same problem. I overcame the problem with a first line of > (useless) code as > > myX <- myY <- NULL > > I found the solution inelegant but it worked. > > cheers! > Mike > > > On Apr 22, 2021, at 4:28 PM, Kevin R. Coombes <kevin.r.coom...@gmail.com> > wrote: > > > > 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 > > > > ______________________________________________ > > R-package-devel@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-package-devel > > ______________________________________________ > R-package-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-package-devel > [[alternative HTML version deleted]] ______________________________________________ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel