[Rd] scoping goes wrong when some functions are used within others.

Joris Meys jorismeys at gmail.com
Fri Oct 1 18:00:46 CEST 2010


I'm following the r tag on stackoverflow.com, and couldn't but notice
there are quite some questions popping up that deal with scoping in
relation to custom functions. I grinded my teeth on it already, and I
have absolutely no clue what goes wrong. The general pattern is as
follows :

ff <- function(x){
    y <- some_value

> ff(x)
Error in eval(expr, envir, enclos) : object 'y' not found

I tried to report this as a bug earlier, but got the message I used
the wrong channel. I also don't know how to formalize it into a bug
report on the report site. That's why I bring it to your attention
this way, and want to ask you whether this is by design and we're all
doing something wrong, whether these are problems within certain
packages/situations, ...

I solve these problems now by adding an environment to my global
environment, and delete it after the function finished running. But
this can't be the correct way.

The problem is described here :

Links to different reports, all having that same pattern but with
different functions :


Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
Joris.Meys at Ugent.be
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

More information about the R-devel mailing list