[R] File > Save As...

Duncan Murdoch murdoch.duncan at gmail.com
Wed Mar 16 02:38:43 CET 2011


On 11-03-15 9:10 PM, Hadley Wickham wrote:
>>> Could getSrcFilename() gain a default argument so that
>>> getSrcFilename() would by default return the path of the executing
>>> script?
>>
>> No, it needs to see a function defined in that script.
>
> But I thought default arguments were evaluated in the parent
> environment?  Does that not follow for source attributes as well?

No, defaults are evaluated in the evaluation frame of the function. 
That's why you can use local variables in them, e.g. the way rgamma uses 
1/rate as a default for scale.

But the point isn't evaluation here:  the point is the parsing.  A 
function gets its source attribute when it is parsed, so getSrcFilename 
needs to be passed something that was parsed in the script.

Duncan Murdoch



More information about the R-help mailing list