case_when: Type literal integers as integer rather than real by default

I have just been learning how to use case_when() to replace chains of ifelse() statements. This is a very convenient function. (Thanks, Hadley, or whoever wrote this function.) I have learned that when I have NA as the right hand side of a formula, I have to "type" the NA as NA_real_ or NA_integer_ or whatever is appropriate, since plain NA is interpreted as logical and breaks things because of class inconsistency.
But I am now working with several large data sets containing (mostly) integer columns as the data are imported to R. Now, when I run case_when using these datasets, I have to explicitly cast all of the RHS values as integer as (it seems) that the RHS of the formula creates them as double, and the class inconsistency abends everything with a class conflict.
(The documentation says: " A vector of length 1 or n , matching the length of the logical input or output vectors, with the type (and attributes) of the first RHS." But my experience says that if I cast the first RHS as.integer, I have to cast all the other RHS as integer, too, or the function breaks because of class inconsistency.)

So, is there a way that I can call case_when() to output integer values by default, and in particular, when my first formula RHS is a literal integer?

Thanks for any help with this.

Addendum: After a bit of noodling around, I discovered that in R one can type a literal integer as integer rather than real simply by adding 'L' after the literal. E.g., 1 is real, 1L is integer. This is a lot easier than remembering always to type as.integer(1). If I have 1L as the first RHS, it seems to accept integer values in following conditions -- but not always. I still haven't figured out when I have to explicitly cast a value from an integer column as integer. It seems sometimes I do and sometimes I don't. Larry

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.