[R] lapply without return values?

Berwin A Turlach
Fri, 25 Jan 2008 09:05:11 -0000

G'day Rainer,

On Fri, 25 Jan 2008 10:34:32 +0200
Rainer M Krug <r.m.krug at gmail.com> wrote:

[...]

>  > p <- data.frame(runif(10), runif(10), runif(10))
>  > lapply( p, function(ps) {x11(); plot(ps)} )
>
> which results in three graphs and a printout:
[...]
> How can I avoid this printout without using
>
> tmp <- lapply( p, function(ps) {x11(); plot(ps)} )?

?invisible

like in invisible(lapply( p, function(ps) {x11(); plot(ps)} ))

Note, your solution seems to involve less keystroke but has the
disadvantage of creating an object in your workspace.

Of course, you could always do something like:

> ilapply <- function(...) invisible(lapply(...))

## perhaps better:
## ilapply <- function(X, FUN, ...) invisible(lapply(X, FUN, ...))

> ilapply(p, function(ps) {x11(); plot(ps)})

To save keystrokes in the long run. :)

HTH.

Cheers,

	Berwin

=========================== Full address ============================Berwin A
Turlach                            Tel.: +65 6515 4416 (secr)
Dept of Statistics and Applied Probability        +65 6515 6650 (self)
Faculty of Science                          FAX : +65 6872 3919
National University of Singapore
6 Science Drive 2, Blk S16, Level 7          e-mail: statba at nus.edu.sg
Singapore 117546                    http://www.stat.nus.edu.sg/~statba