<- function(code) {
capture.output2 <- tempfile()
temp on.exit(file.remove(temp), add = TRUE, after = TRUE)
sink(temp)
on.exit(sink(), add = TRUE, after = TRUE)
force(code)
readLines(temp)
}capture.output2(cat("a", "b", "c", sep = "\n"))
#> [1] "a" "b" "c"
#> [1] "a" "b" "c"