inconsistent behaviour of ifelse and if ... else

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

inconsistent behaviour of ifelse and if ... else

joerg van den hoff
is the behaviour

val <- ifelse(TRUE, numeric(0), 123)
val  #NA

intended or is it a bug, i.e. should an empty object be returned as
might be expected(also in comparsion to what an explicit
val <- {if(TRUE) numeric(0) else 123} yields)?

thanks,

joerg

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: inconsistent behaviour of ifelse and if ... else

Liaw, Andy
When in doubt, check the doc first.  In this case, ?ifelse says in no fewer
than three places why what you described is intended and not a bug.

Andy

From: Joerg van den Hoff

>
> is the behaviour
>
> val <- ifelse(TRUE, numeric(0), 123)
> val  #NA
>
> intended or is it a bug, i.e. should an empty object be returned as
> might be expected(also in comparsion to what an explicit
> val <- {if(TRUE) numeric(0) else 123} yields)?
>
> thanks,
>
> joerg
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html