Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

as.Date.IDate won't change the class if xts package loaded #1500

Closed
jangorecki opened this issue Jan 15, 2016 · 5 comments
Closed

as.Date.IDate won't change the class if xts package loaded #1500

jangorecki opened this issue Jan 15, 2016 · 5 comments
Assignees

Comments

@jangorecki
Copy link
Member

To convert your IDate into Date you currently need to go through as.integer.

library(data.table)
id = as.IDate("2016-01-15")
class(id)
#[1] "IDate" "Date" 
class(as.Date(id))
#[1] "IDate" "Date" 
class(as.Date(as.integer(id)))
#[1] "Date" 

when resolved update this SO.

@franknarf1
Copy link
Contributor

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-47

and 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.

@jangorecki
Copy link
Member Author

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.

@jangorecki
Copy link
Member Author

@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"

@jangorecki jangorecki changed the title as.Date.IDate won't change the class as.Date.IDate won't change the class if xts package loaded Jan 15, 2016
@franknarf1
Copy link
Contributor

Yes, I also see what you're seeing.

@jangorecki
Copy link
Member Author

isolated as xts issue and reported to xts repo: joshuaulrich/xts#137
isolated as zoo issue 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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants