【发布时间】:2015-07-07 13:20:57
【问题描述】:
我准备了一个运行良好的相当复杂的 R 函数。但是,每次运行时,R 都会使用以下表达式填充屏幕:
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
我想知道是否有办法避免 R 的这种提示。这里我可以给你一个函数的例子:
y=function(x){
results=rep(0, length(x))
for (i in (1:length(x))) {
if (x[i]>0) {
results[i]=u(x)
}
}
}
u=function(x){
output=x+1
return(output)
}
【问题讨论】:
-
y不返回任何东西给我。u只返回一个值。 -
用
invisible(output)替换return(output) -
你也可以用
ifelse替换循环