Is there a method to stop lapply() from returning NULL values for each element of the list when a function doesn’t have a return().
Here’s a pretty basic example:
x <- function(x) {
return(NULL) }
a.list <- list(a=1,b=2,c=3)
lapply(a.list, x)
The output is:
$a
NULL
$b
NULL
$c
NULL
My goal is to not have that output, at all.
Update: my usage case is as follows. I’m using lapply() to pump out xtable() text and I’m sink()‘ing it to an Rnw file. So this NULL output is bugging up my automation.
two options come to mind:
Either
or
The first one makes me wonder if there is an analog of Linux’s
/dev/nullinRthat you can use to redirect stuff that you don’t want. The only problem with creating the variabletrash_canis that it will hang around and use up memory unless yourm(trash_can). But I don’t think that’s a problem here.