From jorismeys at gmail.com  Fri Oct  1 23:48:53 2010
From: jorismeys at gmail.com (Joris Meys)
Date: Fri, 1 Oct 2010 23:48:53 +0200
Subject: [Rd] scoping goes wrong when some functions are used within
	others.
In-Reply-To: <4CA618B3.4040504@ccbr.umn.edu>
References: <AANLkTimfvgszrjLgHg7Fz=5K3hzJ=9y3=HZoo8McNY1o@mail.gmail.com>
	<4CA618B3.4040504@ccbr.umn.edu>
Message-ID: <AANLkTi=WKkcte6JPEyiM7ywZ8gAqo0tiLCAN=WPrDH65@mail.gmail.com>

Thank you for all your answers, this really helped me out. I've been
digging into scoping rules in R and although I'm going to need quite
some more studying to fully grasp it, I do see where the errors come
from.

Thanks again.

@Erik : I know that some_value was not declared. I just gave some
pseudo-code to illustrate the general pattern of the errors, to
indicate why I thought they were linked. Sorry if I wasn't clear
enough on that one.

Cheers
Joris

On Fri, Oct 1, 2010 at 7:21 PM, Erik Iverson <eriki at ccbr.umn.edu> wrote:
>
>
> Joris Meys wrote:
>>
>> Dear,
>>
>> 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
>> ? ?some_function(y)
>> }
>>
>>> ff(x)
>>
>> Error in eval(expr, envir, enclos) : object 'y' not found
>
> I get:
>
> Error in ff(x) : object 'some_value' not found
>
> which is entirely consistent, since it has not been bound to a value.
>
>
>
>>
>> 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 :
>>
>> http://stackoverflow.com/questions/3840769/scoping-and-functions-in-r-2-11-1-whats-going-wrong
>>
>> Links to different reports, all having that same pattern but with
>> different functions :
>>
>>
>> http://stackoverflow.com/questions/3742415/r-statistical-scoping-error-using-transformby-part-of-the-doby-package
>>
>> http://stackoverflow.com/questions/3768417/how-to-use-acast-reshape2-within-a-function-in-r
>>
>> http://stackoverflow.com/questions/3661500/why-cant-i-pass-a-dataset-to-a-function
>>
>> http://stackoverflow.com/questions/3574858/values-not-being-copied-to-the-next-local-environment
>>
>> http://stackoverflow.com/questions/2646402/using-functions-and-environments
>>
>>
>



-- 
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



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