After writing Inf (as numeric) into excel, I read it back again and get Inf as Char. For NaN, it becomes NA. For NA, it remains NA as numeric, which is supposed to be.
I used both readxl and writexl. I tried to install tibble and failed.
library(readxl)
library(writexl)
x <- c(1,NA)
y <- c(2,NaN)
z <- c(3,Inf)
d0 <- data.frame(x,y,z)
write_xlsx(d0, 'Test.xlsx')
d1 <- read_xlsx('Test.xlsx')
str(d0$x)
str(d0$y)
str(d0$z)
str(d1$x)
str(d1$y)
str(d1$z)
Here are results: Notice NaN becomes NA; Inf (numeric) becomes Inf (character)
> str(d0$x)
num [1:2] 1 NA
> str(d0$y)
num [1:2] 2 NaN
> str(d0$z)
num [1:2] 3 Inf
> str(d1$x)
num [1:2] 1 NA
> str(d1$y)
num [1:2] 2 NA
> str(d1$z)
chr [1:2] "3" "Inf"
I am looking for explanations and remedies during write and read phases. I am not looking for solutions after reading in such as setting as.numeric(d1$z). I am verifying dataset output by third party using the same R code.
Thanks for your help!