[Bioc-devel] testing class and length of function args

Michael Love michaelisaiahlove at gmail.com
Thu Jul 23 20:25:41 CEST 2015


Thanks all for the pointers
On Jul 23, 2015 10:51 AM, "Charles C. Berry" <ccberry at ucsd.edu> wrote:

> On Wed, 22 Jul 2015, Michael Love wrote:
>
>  it's slightly annoying to write
>>
>> foo <- function(x) {
>>  if ( ! is.numeric(x) ) stop("x should be numeric")
>>  if ( ! length(x) == 2 ) stop("x should be length 2")
>>  c(x[2], x[1])
>> }
>>
>> i wonder if we could have some core functions that test the class and
>> the length in one and give the appropriate stop message.
>>
>> maybe this exists already
>>
>
>
> Not what you are asking, but perhaps this saves you a step:
>
>         stopifnot( is.numeric(x), length(x)==2 )
>
> stopifnot( ... ) will stop and issue an error msg for the first arg that
> is FALSE.
>
> HTH,
>
> Chuck
>

	[[alternative HTML version deleted]]



More information about the Bioc-devel mailing list