[R] Recyclable

Hadley Wickham hadley at rice.edu
Mon Aug 23 18:26:47 CEST 2010


I should note that I realise this function is pretty trivial to write
(see below), I just want to avoid reinventing the wheel.

recyclable <- function(...) {
  lengths <- vapply(list(...), length, 1)

  all(max(lengths) %% lengths == 0)
}

Hadley

On Mon, Aug 23, 2010 at 10:33 AM, Hadley Wickham <hadley at rice.edu> wrote:
> Hi all,
>
> Is there a function to determine whether a set of vectors is cleanly
> recyclable? i.e. is there a common function for detecting the
> error/warnings that underlie the following two function calls?
>
>> 1:3 + 1:2
> [1] 2 4 4
> Warning message:
> In 1:3 + 1:2 :
>  longer object length is not a multiple of shorter object length
>
>> data.frame(1:3, 1:2)
> Error in data.frame(1:3, 1:2) :
>  arguments imply differing number of rows: 3, 2
>
>
> Hadley
>
> --
> Assistant Professor / Dobelman Family Junior Chair
> Department of Statistics / Rice University
> http://had.co.nz/
>



-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list