Hi, I was wondering if there is a way to stop R looking outside the scope of a function, if it can't find the variable inside the function. I seem to waste hours debugging functions only to find I've used a wrong variable name somewhere, but the function still works because the variable exists higher up the hierachy. It seems it would be easier to debug if the function just went splat when it couldn't find the variable. Thanks James
On Wed, 12 Apr 2006, James Kirkby wrote:> Hi, > > I was wondering if there is a way to stop R looking outside the scope of > a function, if it can't find the variable inside the function. > > I seem to waste hours debugging functions only to find I've used a wrong > variable name somewhere, but the function still works because the > variable exists higher up the hierachy. It seems it would be easier to > debug if the function just went splat when it couldn't find the variable.Sounds as if codetools (http://www.stat.uiowa.edu/~luke/R/codetools) would help. (You don't want to stop this in general, but this will tell you if symbols in your functions will not be visible locally.) -- 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
Use local or codetools package as in: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/69694.html http://finzi.psych.upenn.edu/R/Rhelp02a/archive/69695.html On 4/12/06, James Kirkby <james at ma.hw.ac.uk> wrote:> Hi, > > I was wondering if there is a way to stop R looking outside the scope of > a function, if it can't find the variable inside the function. > > I seem to waste hours debugging functions only to find I've used a wrong > variable name somewhere, but the function still works because the > variable exists higher up the hierachy. It seems it would be easier to > debug if the function just went splat when it couldn't find the variable. > > Thanks > > James > > ______________________________________________ > R-help at 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 >
On 4/12/2006 5:49 AM, James Kirkby wrote:> Hi, > > I was wondering if there is a way to stop R looking outside the scope of > a function, if it can't find the variable inside the function. > > I seem to waste hours debugging functions only to find I've used a wrong > variable name somewhere, but the function still works because the > variable exists higher up the hierachy. It seems it would be easier to > debug if the function just went splat when it couldn't find the variable.You don't want to do this, because very little in R is built-in to the language, many things (e.g. "+", "if", etc.) are functions stored in some environment outside your function. Duncan Murdoch