Repository navigation
as.Date.IDate won't change the class if xts package loaded #1500
Description
Activity
I see different output:
> library(data.table) > id = as.IDate("2016-01-15") > class(id) [1] "IDate" "Date" > #[1] "IDate" "Date" > class(as.Date(id)) [1] "Date" > #[1] "IDate" "Date" > class(as.Date(as.integer(id))) Error in as.Date.numeric(as.integer(id)) : 'origin' must be supplied > sessionInfo() R version 3.2.3 (2015-12-10) Platform: i386-w64-mingw32/i386 (32-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] data.table_1.9.7 loaded via a namespace (and not attached): [1] chron_2.3-47and the same with 64-bit (
Platform: x86_64-w64-mingw32/x64 (64-bit)).I didn't update to the latest, latest 1.9.7, but if you have done, then at least this might be helpful in pinpointing where/when it broke.
Just tested latest data.table and I can confirm it is working as expected:
library(data.table) id = as.IDate("2016-01-15") class(id) #[1] "IDate" "Date" class(as.Date(id)) #[1] "Date" class(as.Date(as.integer(id))) #Error in as.Date.numeric(as.integer(id)) : 'origin' must be supplied sessionInfo() #R version 3.2.3 (2015-12-10) #Platform: x86_64-pc-linux-gnu (64-bit) #Running under: Ubuntu 14.04.3 LTS # #locale: # [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C LC_TIME=en_GB.UTF-8 #LC_COLLATE=en_GB.UTF-8 LC_MONETARY=en_GB.UTF-8 # [6] LC_MESSAGES=en_GB.UTF-8 LC_PAPER=en_GB.UTF-8 LC_NAME=C #LC_ADDRESS=C LC_TELEPHONE=C #[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C # #attached base packages: #[1] stats graphics grDevices utils datasets methods base # #other attached packages: #[1] data.table_1.9.7 # #loaded via a namespace (and not attached): #[1] tools_3.2.3 chron_2.3-47
I also tested with R 3.2.2 and data.table 1.9.6 and works fine.
I have no idea why I had different results, any of the branch installed into lib should not result into that. Anyway not reproducible any more.@franknarf1 reproduce issue with the following
library(data.table) library(xts) dt = data.table(date = as.IDate("2016-01-15")) dt[, date := as.Date(date)] class(dt$date) #[1] "IDate" "Date"
while that works as expected:
library(data.table) dt = data.table(date = as.IDate("2016-01-15")) dt[, date := as.Date(date)] class(dt$date) #[1] "Date"
- changed the title
[-]as.Date.IDate won't change the class[/-][+]as.Date.IDate won't change the class if xts package loaded[/+]on Jan 15, 2016 Yes, I also see what you're seeing.
isolated asxtsissue and reported to xts repo: joshuaulrich/xts#137
isolated aszooissue and reported over email to Achim Zeileis:library(data.table) x = as.IDate("2016-01-15") class(as.Date(x)) #[1] "Date" library(zoo) class(as.Date(x)) #[1] "IDate" "Date" class(data.table:::as.Date.IDate(x)) #[1] "Date"
To convert your IDate into Date you currently need to go through
as.integer.when resolved update this SO.