Re: [R] lapply without return values?

From: Berwin A Turlach <berwin_at_maths.uwa.edu.au>
Date: Fri, 25 Jan 2008 17:05:11 +0800

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


R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 25 Jan 2008 - 09:11:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 25 Jan 2008 - 11:30:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive