将函数更改为不可见地返回,并用于print按所需顺序显示事物:
print
f <- function(x) { out <- mean(rnorm(x)) print(out) print(paste("x is:", x)) invisible(out) }