在R中,我试图创建一种方法来将函数参数转换...为闭包函数中预定列表中的值.
我希望能够做到这样的事情:
function_generator <- function(args_list = list(a = "a",
b = "b",
c = list(d = "d",
e = "e")){
g <- function(...){
## ... will have same names as args list
## e.g. a = "changed_a", d = "changed_d"
## if absent, then args_list stays the same e.g. b="b", e="e"
arguments <- list(...)
modified_args_list <- amazing_function(arguments, args_list)
return(modified_args_list)
}
}
Run Code Online (Sandbox Code Playgroud)
args_list每次都会有所不同 - 它是一个在httr请求中发送的正文对象.
如果列表没有嵌套列表,我有一个有效的函数:
substitute.list <- function(template, replace_me){
template[names(replace_me)] <-
replace_me[intersect(names(template),names(replace_me))]
return(template)
}
t …Run Code Online (Sandbox Code Playgroud)