Stop lapply from printing to console
Use l_ply
from plyr:
library(plyr)
FUN <- function(x) {
FUN2 <- function(z) message(z)
l_ply(1:3, function(i) FUN2(paste(x, i)))
}
FUN("hello")
Use invisible
, eg:
invisible(FUN("hello"))
hello 1
hello 2
hello 3
You can wrap it around the lapply
call in the function too to make it tidier.
You could use a plain ol' for loop instead of lapply()
:
FUN <- function(x) {
for (i in 1:3) {
message(paste0(x, i))
}
}
FUN("hello")