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
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.