no visible binding for global variable 'x'
Closed this issue · 2 comments
When code includes a call to graphics::curve
, R CMD check produces a NOTE re "no visible binding for global variable 'x' ". This is a known issue because of the non-standard way that curve
uses 'x', but it does mean that the package will not be accepted by CRAN.
The work-around suggested by Duncan Murdoch on nabble is to insert function(x)
before/as the first argument to curve
. For example,
curve(plogis(beta0 + beta1*x), ...
becomes
curve(function(x) plogis(beta0 + beta1*x), ...
which does the same thing but doesn't set R CMD check barking.
Unfortunately Duncan's work-around doesn't always work, and in any case it makes a mess of the y
axis label, which curve
generates from its first argument.
So I've implemented the kludge suggested by Henrik Bengtsson in the same R-help discussion, adding
x <- NULL ; rm(x) # Dummy to trick R CMD check
at the very start of the function which calls curve
(at the start to avoid zapping any other object called x
in the code).
Maybe an even better kludge is
if(FALSE) x <- NULL
which does precisely nothing (and won't zap any object called x
) but does keep R CMD check
happy.