On 21/06/2020 11:37 a.m., Benjamin Tyner wrote:
On 6/20/20 5:04 PM, Duncan Murdoch wrote:
I think you effectively did that in your original post (all but
encapsulating the expression in a function), so yes, it's possible.
However, it's a really bad idea. Why use non-standard evaluation when
sta
On 6/20/20 5:04 PM, Duncan Murdoch wrote:
I think you effectively did that in your original post (all but
encapsulating the expression in a function), so yes, it's possible.
However, it's a really bad idea. Why use non-standard evaluation when
standard evaluation is fine? Standard evaluation
OK -- you were referring explicitly to the function call. That's what I
missed. Apologies for the noise.
-- Bert
On Sat, Jun 20, 2020 at 3:19 PM Benjamin Tyner wrote:
>
> On 6/20/20 5:49 PM, Bert Gunter wrote:
> > Gents:
> > (with trepidation)
> >
> > f(x = 3, y = g(expr))
> > **already** evalu
On 6/20/20 5:49 PM, Bert Gunter wrote:
Gents:
(with trepidation)
f(x = 3, y = g(expr))
**already** evaluates g in the environment of f, **not** in the
environment of the caller.
(This does not contradict Duncan's example -- 3 is a constant, not a
variable).
e.g.
> f <- function(x = 3, y =
Gents:
(with trepidation)
f(x = 3, y = g(expr))
**already** evaluates g in the environment of f, **not** in the environment
of the caller.
(This does not contradict Duncan's example -- 3 is a constant, not a
variable).
e.g.
> f <- function(x = 3, y = x^2 +k){
+ k <- 3
+ x + y
+ }
Ergo
>
On 20/06/2020 4:44 p.m., Benjamin Tyner wrote:
On 6/20/20 9:00 AM, Duncan Murdoch wrote:
How about
g <- function(x, y = x) {
f(x, y)
}
g(x = 3)
or even
yEqualsX <- function(f) function(x, y = x) f(x, y)
yEqualsX(f)(x = 3)
These are a lot like currying, but aren't currying, so they may be
On 6/20/20 9:00 AM, Duncan Murdoch wrote:
How about
g <- function(x, y = x) {
f(x, y)
}
g(x = 3)
or even
yEqualsX <- function(f) function(x, y = x) f(x, y)
yEqualsX(f)(x = 3)
These are a lot like currying, but aren't currying, so they may be
acceptable to you. Personally I'd choose the f
On 20/06/2020 7:15 a.m., Benjamin Tyner wrote:
Greetings,
Occasionally, I desire to call a function with one argument set to equal
to another. Here is a toy example:
f <- function(x, y) {
x + y
}
f(x = 3, y = x) # Error in f(x = 3, y = x) : object 'x' not found
So far
Hi Ben,
How about something like this:
f <- function(x, y = NULL) {
if (is.null(y))
y <- x
x + y
}
> f(3, 4)
[1] 7
> f(3)
[1] 6
Regards,
Marc Schwartz
> On Jun 20, 2020, at 7:15 AM, Benjamin Tyner wrote:
>
> Greetings,
>
> Occasionally, I desire to call a function with one arg
Greetings,
Occasionally, I desire to call a function with one argument set to equal
to another. Here is a toy example:
f <- function(x, y) {
x + y
}
f(x = 3, y = x) # Error in f(x = 3, y = x) : object 'x' not found
So far, the most concise way I found to accomplish this is:
10 matches
Mail list logo