R c.Date() raises warning Calling 'structure(NULL, *)' is deprecated

元气小坏坏 提交于 2020-01-16 08:57:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!