是否有一些相当于在r中表达let表达式?举个例子来看看这个简单的haskell代码:
let x = 1 in x + 1
Run Code Online (Sandbox Code Playgroud)
提前谢谢了.
一个等价物是lambda函数,您可以在一个语句中定义和调用它:
(function(x) x+1)(x = 1)
Run Code Online (Sandbox Code Playgroud)
第一()部分定义一个函数,而第二()部分调用该函数,1为名为的参数提供值x.
以下是一些:
x <- 100
# 1
with(list(x = 1), x + 1)
## [1] 2
# 2
local(x + 1, list(x = 1))
## [1] 2
# 2a
local({
x <- 1
x + 1
})
## [1] 2
# 3
eval(substitute(x + 1, list(x = 1)))
## [1] 2
# 4
library(wrapr)
let(c(x = "1"),
x + 1,
subsMethod = "stringsubs",
strict = FALSE)
## [1] 2
x
## [1] 100
Run Code Online (Sandbox Code Playgroud)
lambda.r 包中还有一个未解决的问题let要添加.