Confusing dplyr::if_else error "`false` must be a `Date` object, not a `Date` object"

Hi, manipulating a dataframe imported by haven::read_sas, the call of dplyr::il_else led to the confusing following error message : error false must be a Date object, not a Date object

Both columns I used in the true/false arguments of if_else were of the class Date :

[1] "Date"
[1] "Date"

but the type of the columns was different :

[1] "integer"
[1] "double"

leading to the confusing error message.

Maybe the blame is on haven::read_sas which should not create Date format with integer type, anyway it will be great if the dplyr::if_else error message said rather in this case : "error false must be of integer format, not a double format. It would have save me some time.


Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.


If you've never heard of a reprex before, you might want to start by reading the help page. The reprex dos and don'ts are also useful.

There's also a nice FAQ on how to do a minimal reprex for beginners, below:

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "")

For pointers specific to the community site, check out the reprex FAQ.

I'm sorry I don't think I can. I must have a ill-defined dataframe and I get an error trying to dpasta it

"Error in strrep(" ", char_length - nchar(char_vec)) :
invalid 'times' value"

Even trying the factor trick

da %>%

  • dplyr::mutate_if(is.factor, as.character) %>%
  • datapasta::tribble_paste()
    Error in strrep(" ", char_length - nchar(char_vec)) :
    invalid 'times' value

You should report unexpected behavior in the GitHub issue tracker for dplyr.

Reprex isolating the error:


int_date <- Sys.Date()
num_date <- Sys.Date()
storage.mode(int_date) <- "integer"

if_else(TRUE, int_date, num_date)
# Error: `false` must be a `Date` object, not a `Date` object
# Call `rlang::last_error()` to see a backtrace

If you need to know how to report bugs for any package, you can run this command:

# dplyr is the example, but any package name will do
packageDescription("dplyr", fields = c("BugReports", "Maintainer"))
# BugReports:
# Maintainer: Hadley Wickham <>
# -- File: C:/Users/nwerth/Documents/R/win-library/3.6/dplyr/Meta/package.rds 
# -- Fields read: BugReports, Maintainer

If there's a BugReports field, it tells you where to go. Otherwise, send an email to the person named in Maintainer.

1 Like

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