no visible binding for global variable
On Tue, 17 Apr 2007, Robin Hankin wrote:
Hello everyone I am trying to get one of my packages through R's QC. The package is clean for me under R-2.4.1, R-2.5.0, and R-devel, but Kurt gets
Do you have _R_CHECK_USE_CODETOOLS_ set to something true (and for 2.4.1, codetools installed)? See `Writing R Extensions'.
* checking R code for possible problems ... WARNING hypercube: no visible binding for global variable ?f?
Function hypercube() [cut-&-pasted below] is intended to return an adjacency matrix for an n-dimensional hypercube with 2^n nodes. hypercube(n) returns a 2^n -by- 2^n matrix, and works as intended for me. Can someone explain what the error message means?
If the arguments of outer() were evaluated in the frame of hypercube, there is no visible object 'f'. So if 'wrapper' actually made use of its 'my.fun' argument, this would fail. As it is, lazy evaluation postpones the error (for ever). Try removing the unused argument from wrapper(), and running the same test that Kurt did before and after. BTW, it looks like updating one of your packages has broken another (untb).
"hypercube" <- function(n){
jj <- as.matrix(expand.grid(rep(list(0:1),n)))
wrapper <- function(x, y, my.fun) {
f <- function(x,y,tol=1e-4){
abs(sum(abs(jj[x,]-jj[y,]))-1)<tol
}
sapply(seq(along = x), FUN = function(i){f(x[i], y[i])})
}
o <- -outer(1:(2^n),1:(2^n), wrapper, my.fun=f)
jj.names <- apply(jj,1,paste,collapse="")
rownames(o) <- jj.names
colnames(o) <- jj.names
diag(o) <- -apply(o,1,sum,na.rm=TRUE)
return(o)
}
-- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595