Skip to content
Prev 246924 / 398502 Next

Evaluation of variable assigned to a function name

Let the following definitions:


# my definition
my.func <- function (x,y,z){
....
return (v)
}

# user-defined definition
my.func <- function (x){
...
return(v)
}

Considering that my.func can have different parameters but always return a 
vector, how to use v in bar by initializing parameters when calling my.func (x = 
2 or a = 3,y=4,z=5)? How can my.func could be invoked in bar and v could be 
used?

bar<- function(x, ....., foo){
----- Original Message ----
From: Uwe Ligges <ligges at statistik.tu-dortmund.de>
To: carol white <wht_crl at yahoo.com>
Cc: r-help at stat.math.ethz.ch
Sent: Mon, January 10, 2011 2:48:04 PM
Subject: Re: [R] Evaluation of variable assigned to a function name
On 10.01.2011 14:39, carol white wrote:
in
It depends.

1. The output of a function can always be wrapped in a list.
2. You should always pass objects that you want to use in another 
environment unless you really know what you are doing - and reading does 
not suggest you are too sure about it.
3. In this case, if your package has a Namespace, your own function 
rather than a user generated one in the .GlobalEnv will be found.

Note that defining stuff in .GlobalEnv and relying on the fact that this 
version is found by another function would imply you really have to get 
it from the specific environment.

Best,
Uwe