[R] Problem with a defined function which cannot access a function defined outside of the function

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Thu Apr 16 10:22:36 CEST 2009


>  i have a problem with a function that i defined:
> 
>  the function needs to use a function which is defined outside the 
function
> but
>  i realised that this is not working. a friend told me that this must be 
a
> problem with
>  hidden parameters.
> 
>  a workaround works when i just define all parameters instead of using 
the
> function
>  itself. now the problem is that i want to integrate the function and 
i'm
> not
>  sure how to do it with this workaround since i have a plot of the 
function
> and
>  a big vektor with all points of the plot on the x-axis only.

I suggest you read up a little on the search path and how R does lexical 
scoping (sections 6.3.5 and 10.7 in R-Intro).  The short version of that 
is that unless you specifically name the package that the function is 
from, R will look inside the current function, then in the global 
environment, then some other places. 

If you have problems with names of things being hidden, a quick hack is to 
rename the hidden item.

If you want a less abstract answer then please post a commented, minimal, 
self-contained, reproducible code example.

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}




More information about the R-help mailing list