问题
I noticed that calling c.Date() to initialize an empty date vector raises a Warning. I am on R version 3.4.0.
The warning message is :
Warning message: In structure(c(unlist(lapply(list(...), unclass))), class = "Date") : Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes. Consider 'structure(list(), *)' instead.
Do anyone has an explantion? How to initialize an empty DATE vector without having this warning?
A reproducible code :
vect = c.Date()
d = as.Date("31/12/2018", format = "%d/%m/%Y")
for(i in 1:10){
vect = c(vect, d)
d = d+1
}
print(vect)
Result is
[1] "2016-03-31" "2016-04-01" "2016-04-02" "2016-04-03" [5] "2016-04-04" "2016-04-05" "2016-04-06" "2016-04-07" [9] "2016-04-08" "2016-04-09"
If I don't use c.Date() but c() instead.
vect = c()
d = as.Date("31/12/2018", format = "%d/%m/%Y")
for(i in 1:10){
vect = c(vect, d)
d = d+1
}
print(vect)
[1] 17896 17897 17898 17899 17900 17901 17902 17903 17904 17905
which is undesirable.
回答1:
r2evans answerd my question.
Sys.Date()[0]
does the trick.
I post here to mark it as resolved for future readers.
来源:https://stackoverflow.com/questions/51751959/r-c-date-raises-warning-calling-structurenull-is-deprecated