Skip to content
Prev 294098 / 398503 Next

as.function parameters

Hello,
Yes, there is one way, just do nothing. R always uses call-by-value.
I'm not completely sure about this, but when you create f() the parameter x
default value
is a promise, not an actual, evaluated value. Courtesy lazy evaluation.
It's only when you need it that it's evaluated.

For instance, using your code, you don't need to create tmp before creating
f().
Since R is not evaluating tmp, there's no error to throw.
You'll only get an error  if you try to *use* f() without creating tmp or
without a default value override.

rm(f, tmp) # just to be sure
f <- as.function(alist(y=, x=tmp, y + x))
f(1)	# error
f(1, 3) # no error
tmp <- 2
f(1) # 3

Hope this helps,
Rui Barradas



jackl wrote
--
View this message in context: http://r.789695.n4.nabble.com/as-function-parameters-tp4620390p4621903.html
Sent from the R help mailing list archive at Nabble.com.