在下面的R
函数中,我希望始终可见输出对象output
。但是我想知道是否有一种方法可以无形但可提取输出对象cl
,也就是函数调用吗?
如果不可能,如何将cl
明显地添加到output
上,以便在执行cl
之后与output
一起提取foo <- function(one = T){
cl <- match.call()
output <- if(one) data.frame(d = 6:8, long = c(F, F,F)) else
list(Study1 = data.frame(d = 6:8, long = c(F, F,F)), Study2 = data.frame(d = 9:11, long = c(T, T, F)) )
return(output)
}
# Example of use:
foo()
?
var html = '';
$('#pro').html('');
$.each(pro, function( index, value ) {
if (value.name + " - Price: " + value.unit_cost==event.target.textContent) {
html += value.description;
html += value.unit_cost;
html += '</br>';
html += '<img src="'+value.image_url+'">';
}
});
$('#pro').html(html);
答案 0 :(得分:0)
您可以return
list
的功能输出
foo <- function(one = T){
cl <- match.call()
output <- if(one) data.frame(d = 6:8, long = c(F, F,F)) else
list(Study1 = data.frame(d = 6:8, long = c(F, F,F)),
Study2 = data.frame(d = 9:11, long = c(T, T, F)) )
return(list(output = output, cl = cl))
}
,然后使用eval
评估函数
a = foo(TRUE)
eval(a$cl)
#$output
# d long
#1 6 FALSE
#2 7 FALSE
#3 8 FALSE
#$cl
#foo(one = TRUE)