From ripley at stats.ox.ac.uk  Tue Apr 17 11:28:35 2007
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Tue, 17 Apr 2007 10:28:35 +0100 (BST)
Subject: [Rd] no visible binding for global variable
In-Reply-To: <3B7634A3-D77F-44A9-B9A4-4F51C0644721@soc.soton.ac.uk>
References: <3B7634A3-D77F-44A9-B9A4-4F51C0644721@soc.soton.ac.uk>
Message-ID: <Pine.LNX.4.64.0704171018140.25999@gannet.stats.ox.ac.uk>

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



[Rd] no visible binding for global variable
Prof Brian Ripley