Skip to content
Prev 317400 / 398506 Next

Help with functions as arguments

On Feb 12, 2013, at 12:38 AM, Rainer M Krug wrote:

            
I assume that some carriage returns have ben lost and that this is meant:
I think there was some switching of capitals there, but assume this was meant:

X <- 3
f2(x=X, z=f1((X))


Also possible would be:
[1] 10

Using f1(x<-3) creates a value of 'x' in the global environment and the result is passed to `f1` (although not as a named argument since f1 is expecting a formal named "b") and then f1(3) is passed to z:
[1] 4
[1] 10

This would seem to be a method of creating mildly obfuscated code, so I'm not really recommending it. I would think the more natural way would be creation of a constrained version of f2

f3 <- function(x) { f2(x, f1(x) }