[R] Problem with scoping a variable value

From: Tolga Uzuner <tolga_at_coubros.com>
Date: Fri 17 Feb 2006 - 06:38:18 EST

Hi there,

I have a function which has a variable called show as an input:

richardson.grad <- function(func, x, d=0.01, eps=1e-4, r=6, show=F){ # do some things

   if(show) {

        cat("\n","first order approximations", "\n")       
        print(a.mtr, 12)

#do more things and return

The show variable is being used as a flag to show intermediate results.

Interestingly enough, I have downloaded a package recently which defines the show variable as a function:

> show

standardGeneric for "show" defined from package "methods"

function (object)
<environment: 01676F7C>
Methods may be defined for arguments: object


Now, all of a sudden, the function I had defined earlier is scoping up to this new value, and is thus not working:

> richardson.grad(function(x) x^2,2)
Error in if (show) { : argument is not interpretable as logical

I could always redefine show in richardson.grad to be something else but something seems wrong: why is richardson.grad not looking up show's value in the function ? How would I fix this ?

Thanks in advance,

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Feb 17 07:20:24 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:31 EST