[R] R CMD methods and ggplot2 advice
Rolf Turner
r.turner at auckland.ac.nz
Thu May 28 11:28:15 CEST 2015
On 27/05/15 23:37, Thierry Onkelinx wrote:
> Dear Glenn,
>
> Suppose this function
>
> test <- function(df){
> ggplot(df, aes(x = gp, y = y)) + geom_point()
> }
>
> Then R CMD check will consider gp and y as global variables since they are
> undefined. Because R CMD check cannot detect that gp and y will be
> extracted from df by ggplot2.
>
> Possible workarounds
>
> # now gp and y are defined within the function. ggplot2 still looks for gp
> and y in df.
> test <- function(df){
> gp <- NULL
> y <- NULL
> ggplot(df, aes(x = gp, y = y)) + geom_point()
> }
>
> # now "gp" and "y" are strings and hence defined
> test <- function(df){
> ggplot(df, aes_string(x = "gp", y = "y")) + geom_point()
> }
<SNIP>
Why not use utils::globalVariables?
cheers,
Rolf Turner
--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
More information about the R-help
mailing list