Re: [R] lapply without return values?

From: Rainer M Krug <r.m.krug_at_gmail.com>
Date: Fri, 25 Jan 2008 11:06:59 +0200

Berwin A Turlach wrote:
> 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)} ))

thanks - that's an option.
But the idea is to prevent the creation of an object - and even if I don't assign it to a variable, isn't that object already created in the function lapply()? I would like to save on time and memory (I know - not necessary, but I would prefer to.)

But I will remember the suggestion about the invisible()

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

true - I should do
 > rm(tmp) afterwards

>
> 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


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:13:12 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 - 10: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