Skip to content

fifelse followup #3740

Closed
Closed

Description

@jangorecki
  • names of test could be retained
fifelse(c(a=T,b=F), 1:2, 2:1)
#[1] 1 1
ifelse(c(a=T,b=F), 1:2, 2:1)
#a b 
#1 1 
  • recycling here needs to be fixed, AFAIU might result into segfault - PR propose to remove this feature
fifelse(c(TRUE, FALSE), 1:2, list(0L))
#[1]         1 544979712
ifelse(c(TRUE, FALSE), 1:2, list(0L))
#[[1]]
#[1] 1
#
#[[2]]
#[1] 0
  • coerce int to double when desired (but not double to int, as in base::ifelse)
str(ifelse(c(T,F),c(1,2),11:12))
# num [1:2] 1 12
str(ifelse(c(T,F),1:2,c(11,12)))
# num [1:2] 1 12
str(ifelse(c(T,F),1:2,c(11,12)))
#Error in fifelse
  • remove hutils, dplyr code from examples, pass --run-dontrun
  • remove console output in examples
  • int64 support NAs

Activity

  1. self-assigned this
    on Aug 3, 2019
  2. added this to the 1.12.4 milestone on Aug 3, 2019
  3. 2005m commented on Aug 3, 2019

    @2005m
    Contributor

    would you agree if fifelse(c(TRUE, FALSE), 1:2, list(0L)) displays an error like this :

    Error in fifelse(c(TRUE, FALSE), 1:2, list(0L)) : 
      'yes' is of type integer but 'no' is of type list. Please make sure that both arguments have the same type.
    

    and that we have the following ?

    DT1 = data.table(a = 0:5, b = list(1, list(2:3), list(4:6), list(6:4), list(3:2), 1))
    DT2 = data.table(a = 0:5, b = list(1, list(2:3), list(4:6), list(6:4), list(3:2), 1))
    DT1 = DT1[ , b1 := fifelse(a > 2, b, 0)]
    DT2 = DT2[ , b1 := fifelse(a > 2, b, list(0))]
    identical(DT1,DT2)
    [1] TRUE
    

    Let me know if you want me to test something else. I don't want to commit anything until you are happy with the behaviour.

  4. jangorecki commented on Aug 3, 2019

    @jangorecki
    MemberAuthor

    So for len1 > 1 or len2 > 1 branches raise an error.
    I would personally avoid this kind of inconsistency, but lets wait for opinion of others. I also think wrapping in a list for values to meant to be a list column elements is not bad.

  5. 2005m commented on Aug 3, 2019

    @2005m
    Contributor

    Yes that is correct. This is consistent with what @MichaelChirico asked me to implement in my pull request. @jangorecki would you avoid en-listing or how would you expect en-listing to work?

  6. shrektan commented on Aug 9, 2019

    @shrektan
    Member

    Thanks for implementing this. dplyr::if_else() has a missing argument I think it's quite helpful, because the number of all the possible logic values in R are 3, in fact: TRUE, FALSE, NA.

    So do you think it's a good idea to add the missing argument in fifelse()?

    Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions