Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-11-29 Thread Suharto Anggono Suharto Anggono via R-devel
Interspersed below. Subject: Re: ifelse() woes ... can we agree on a ifelse2() ? To: r-de...@lists.r-project.org Date: Sunday, 27 November, 2016, 12:14 AM On current 'ifelse' code in R: ... * If 'test' is a factor, doing storage.mode(test) <- "log

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-11-28 Thread Gabriel Becker
Well, that's embarrassing. Sorry for the noise on that front, everyone. I misunderstood something from the aforementioned unrelated conversation I was having, but not double checking is on me (I rarely use if else and when I do I avoid that situation in my own code, which is why I didn't already kn

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-11-28 Thread Martin Maechler
> Suharto Anggono Suharto Anggono via R-devel > on Sat, 26 Nov 2016 17:14:01 + writes: > Just stating, in 'ifelse', 'test' is not recycled. As I said in "R-intro: length of 'ifelse' result" (https://stat.ethz.ch/pipermail/r-devel/2016-September/073136.html), ifelse(conditio

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-11-28 Thread Martin Maechler
> Related to the length of 'ifelse' result, I want to say that "example of > different return modes" in ?ifelse led me to perceive a wrong thing in the > past. > ## example of different return modes: > yes <- 1:3 > no <- pi^(0:3) > typeof(ifelse(NA,yes, no)) # logical >

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-11-26 Thread Suharto Anggono Suharto Anggono via R-devel
Related to the length of 'ifelse' result, I want to say that "example of different return modes" in ?ifelse led me to perceive a wrong thing in the past. ## example of different return modes: yes <- 1:3 no <- pi^(0:3) typeof(ifelse(NA,yes, no)) # logical typeof(ifelse

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-11-26 Thread Suharto Anggono Suharto Anggono via R-devel
For S Ellison, just clarifying, I am Suharto Anggono, not Martin Maechler. "Martin et al.," from my previous E-mail was the beginning of message from Gabriel Becker, that I quoted. The quoted "still a bit disappointed that nobody has taken a look" is from Martin Maechler. In all of the proposed

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-11-26 Thread S Ellison
> Just stating, in 'ifelse', 'test' is not recycled. As I said in "R-intro: > length of 'ifelse' result" > (https://stat.ethz.ch/pipermail/r-devel/2016-September/073136.html), > ifelse(condition, a, b) > returns a vector of the length of 'condition', even if 'a' or 'b' is longer. That is indee

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-11-26 Thread Suharto Anggono Suharto Anggono via R-devel
Just stating, in 'ifelse', 'test' is not recycled. As I said in "R-intro: length of 'ifelse' result" (https://stat.ethz.ch/pipermail/r-devel/2016-September/073136.html), ifelse(condition, a, b) returns a vector of the length of 'condition', even if 'a' or 'b' is longer. On current 'ifelse' cod

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-11-22 Thread Gabriel Becker
Martin et al., On Tue, Nov 22, 2016 at 2:12 AM, Martin Maechler wrote: > > Note that my premise was really to get *away* from inheriting > too much from 'test'. > Hence, I have *not* been talking about replacing ifelse() but > rather of providing a new ifelse2() > >[ or if_else() if

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-11-22 Thread Martin Maechler
> Gabriel Becker > on Tue, 15 Nov 2016 11:56:04 -0800 writes: > All, > Martin: Thanks for this and all the other things you are doing to both > drive R forward and engage more with the community about things like this. > Apologies for missing this discussion the first

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-11-15 Thread Gabriel Becker
All, Martin: Thanks for this and all the other things you are doing to both drive R forward and engage more with the community about things like this. Apologies for missing this discussion the first time it came around and if anything here has already been brought up, but I wonder what exactly yo

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-11-15 Thread Martin Maechler
Finally getting back to this : > Hadley Wickham > on Mon, 15 Aug 2016 07:51:35 -0500 writes: > On Fri, Aug 12, 2016 at 11:31 AM, Hadley Wickham > wrote: >>> >> One possibility would also be to consider a >>> "numbers-only" or >> rather "same type"-only {e.g., >>>

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-08-15 Thread Hadley Wickham
On Fri, Aug 12, 2016 at 11:31 AM, Hadley Wickham wrote: >> >> One possibility would also be to consider a "numbers-only" or >> >> rather "same type"-only {e.g., would also work for characters} >> >> version. >> >> > I don't know what you mean by these. >> >> In the mean time, Bob

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-08-12 Thread Hadley Wickham
> >> One possibility would also be to consider a "numbers-only" or > >> rather "same type"-only {e.g., would also work for characters} > >> version. > > > I don't know what you mean by these. > > In the mean time, Bob Rudis mentioned dplyr::if_else(), > which is very relevant, th

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-08-12 Thread Martin Maechler
Excuse for the delay; I had waited for other / additional comments and reactions (and been distracted with other urgent issues), but do want to keep this thread alive [inline] .. > Duncan Murdoch > on Sat, 6 Aug 2016 11:30:08 -0400 writes: > On 06/08/2016 10:18 AM, Martin Maech

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-08-08 Thread Martin Maechler
> Uwe Ligges > on Sun, 7 Aug 2016 09:51:58 +0200 writes: > On 06.08.2016 17:30, Duncan Murdoch wrote: >> On 06/08/2016 10:18 AM, Martin Maechler wrote: [.] >>> Of course, an ifelse2() should also be more efficient than >>> ifelse() in typical "ato

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-08-07 Thread Uwe Ligges
On 06.08.2016 17:30, Duncan Murdoch wrote: On 06/08/2016 10:18 AM, Martin Maechler wrote: Dear R-devel readers, ( = people interested in the improvement and development of R). This is not the first time that this topic is raised. and I am in now state to promise that anything will result from

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-08-06 Thread Duncan Murdoch
On 06/08/2016 10:18 AM, Martin Maechler wrote: Dear R-devel readers, ( = people interested in the improvement and development of R). This is not the first time that this topic is raised. and I am in now state to promise that anything will result from this thread ... Still, I think the majority

Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-08-06 Thread Bob Rudis
have you tried seeing if `dplyr::if_else` behaves more to your liking? On Sat, Aug 6, 2016 at 10:20 AM Martin Maechler wrote: > Dear R-devel readers, > ( = people interested in the improvement and development of R). > > This is not the first time that this topic is raised. > and I am in now stat

[Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-08-06 Thread Martin Maechler
Dear R-devel readers, ( = people interested in the improvement and development of R). This is not the first time that this topic is raised. and I am in now state to promise that anything will result from this thread ... Still, I think the majority among us has agreed that 1) you should never use

Re: [Rd] ifelse can't return a list? Please explain (R-2.15.3)

2013-03-25 Thread Patrick Burns
When you what you hope for turns out to be wrong, then have a look at 'The R Inferno'. http://www.burns-stat.com/documents/books/the-r-inferno/ It does talk about 'ifelse'. Pat On 25/03/2013 02:21, Paul Johnson wrote: I hope you are doing well. For me, this was an unexpected problem. I've ho

Re: [Rd] ifelse can't return a list? Please explain (R-2.15.3)

2013-03-24 Thread Joshua Wiley
Hi Paul, Wonder why this is an R devel thing? ifelse is vectorizedthere should be logical conditions matching the length of the output. ifelse(c(1, 1, 1), list(a=2, b=3, c=4), list(d=1, e=2, f=3)) otherwise it is truncated. Also note that both results have to be valid, because both are typ

[Rd] ifelse can't return a list? Please explain (R-2.15.3)

2013-03-24 Thread Paul Johnson
I hope you are doing well. For me, this was an unexpected problem. I've hoped for quite a few wrong things today, but I'm only asking you about this one. Why does ifelse(1, list(a, b, c), list(x, y, z)) return a list with only a, not list(a, b, c) as I hoped. I wish it would either cause an err

Re: [Rd] ifelse

2008-08-25 Thread Tim Hesterberg
Others have commented on why this holds. There is an alternative, 'ifelse1', part of the splus2R package, that does what you'd like here. Tim Hesterberg >I find it slightly surprising, that > ifelse(TRUE, character(0), "") >returns NA instead of character(0). > >-- >Heikki Kaskelma

Re: [Rd] ifelse

2008-08-18 Thread Peter Dalgaard
Prof Brian Ripley wrote: Another way of looking at this is that ifelse(TRUE, character(0), "") asks for a length-one result Just to rub it in: The length of an ifelse() computation is the length of the "test" argument, so there is no way you should expect character(0) as the result. (The clas

Re: [Rd] ifelse

2008-08-18 Thread Prof Brian Ripley
Another way of looking at this is that ifelse(TRUE, character(0), "") asks for a length-one result containing the first element of yes=character(0), and character(0)[1] is NA_character_ I suspect if(TRUE) character(0) else "" was intended. On Mon, 18 Aug 2008, Marc Schwartz wrote: on 08/18/2

Re: [Rd] ifelse

2008-08-18 Thread Marc Schwartz
on 08/18/2008 06:35 PM Heikki Kaskelma wrote: > I find it slightly surprising, that > > ifelse(TRUE, character(0), "") > > returns NA instead of character(0). > > [WNT 2.6.2 Patched] Time to upgrade... :-) The same behavior is in: R version 2.7.2 beta (2008-08-16 r46368) The reason for

[Rd] ifelse

2008-08-18 Thread Heikki Kaskelma
I find it slightly surprising, that ifelse(TRUE, character(0), "") returns NA instead of character(0). [WNT 2.6.2 Patched] -- Heikki Kaskelma __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel

[Rd] ifelse drops classes

2008-02-29 Thread Hilmar Berger
Hi all, I guess that this is rather a feature request than a bug report, but I'm not really sure: I stumbled over this today (R 2.6.2, WinXP): > c=c(as.Date("2007-01-01")) > class(c) [1] "Date" > ifelse(is.na(c),as.Date(Sys.time()), c) [1] 13514 > typeof(ifelse(is.na(c),as.Date(Sys.time()),

Re: [Rd] ifelse behaviour

2007-04-26 Thread ml-it-r-devel
Duncan Murdoch wrote: > On 4/26/2007 9:53 AM, [EMAIL PROTECTED] wrote: >> Hi! >> >> I'm puzzled by the return value of ifelse >> >> consider >> >> x<-integer(0) >> ifelse(is(x, "character"), paste(x), x) >> [1] NA > > The test evaluates to a length 1 logical vector containing FALSE. So > ifelse(

Re: [Rd] ifelse behaviour

2007-04-26 Thread Tony Plate
A simpler version of your "puzzling call to ifelse" is ifelse(FALSE, character(0), integer(0)) The most obvious way to satisfy the requirements stated in the documentation is to extend integer(0) to length 1 by creating an NA value, and that's what you get as a return value (here the 'test' ar

Re: [Rd] ifelse behaviour

2007-04-26 Thread Duncan Murdoch
On 4/26/2007 9:53 AM, [EMAIL PROTECTED] wrote: > Hi! > > I'm puzzled by the return value of ifelse > > consider > > x<-integer(0) > ifelse(is(x, "character"), paste(x), x) > [1] NA The test evaluates to a length 1 logical vector containing FALSE. So ifelse() tries to return the first entry of

[Rd] ifelse behaviour

2007-04-26 Thread ml-it-r-devel
Hi! I'm puzzled by the return value of ifelse consider x<-integer(0) ifelse(is(x, "character"), paste(x), x) [1] NA whereas if (is(x, "character")) return(paste(x)) else x [1] integer(0) or x<-integer(1) ifelse(is(x, "character"), paste(x), x) [1] 0 work as I had anticipated. Is this correct