if_else is strict on type and all TRUE or FALSE replacement must be the same type. So when replacing to NA, you need to choose between NA_integer_, NA_real_ or other. NA is NA_logical_ by default. This strict rule applies also to recode, coalesce.
Maybe this will change in the future with {vctrs}
If you apply by column, you can control with anyof this function
case_when can handle the different NA types
See following examples
library(tidyverse)
#> Warning: le package 'tibble' a été compilé avec la version R 3.5.2
#> Warning: le package 'purrr' a été compilé avec la version R 3.5.2
#> Warning: le package 'stringr' a été compilé avec la version R 3.5.2
#> Warning: le package 'forcats' a été compilé avec la version R 3.5.2
df <- data.frame(Month = 1:5,
Year = c(2000, rep(NA, 4)),
Year2 = c(2000, rep(NaN, 4)))
df
#> Month Year Year2
#> 1 1 2000 2000
#> 2 2 NA NaN
#> 3 3 NA NaN
#> 4 4 NA NaN
#> 5 5 NA NaN
# column by column specifying NA type
df %>%
mutate(Year2 = coalesce(Year2, NA_real_))
#> Month Year Year2
#> 1 1 2000 2000
#> 2 2 NA NA
#> 3 3 NA NA
#> 4 4 NA NA
#> 5 5 NA NA
# all at once
df %>%
mutate_all( ~ case_when(!is.nan(.x) ~ .x))
#> Month Year Year2
#> 1 1 2000 2000
#> 2 2 NA NA
#> 3 3 NA NA
#> 4 4 NA NA
#> 5 5 NA NA
Created on 2019-03-07 by the reprex package (v0.2.1)
Also, I believe a feature request can be sent to dplyr so that fill can apply also on NaN, moreover because
is.na(NaN)
#> [1] TRUE