-
Notifications
You must be signed in to change notification settings - Fork 979
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
implicit re-casting of logical to Date fails #5344
Labels
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
using data.table 1.14.0 built under R version 3.6.3 in RStudio Version 1.1.463 session using R version 3.6.0
slightly modified and greatly expanded from https://stackoverflow.com/a/54081089/4228193
using
alldata <- data.table(1)[,
:=(c("va", "vb", "vc", "vd"),NA)][,V1:=NULL][.0]
or
alldata <- data.table(1)[,
:=(c("va", "vb", "vc", "vd"),NA)][,V1:=NULL][!is.na(va)]
creates an empty data.table with 4 named columns, which I intend to iteratively append to with the results of an fread (stored in
filedata
). You can dummy up a value for filedata withfiledata <- data.table(1)[,
:=(va="bob", vb="barbara ann", vc=4, vd=as.Date("1965-09-23"), V1=NULL)]
alldata[,lapply(.SD,class)] # 0-row data seeded with NA in each column
filedata[,lapply(.SD,class)] # lines of real data that you are trying to merge
rbindlist(list(alldata,filedata))
Basically, a logical column can't be auto-recast to a Date data type. Nor is IDate class data allowed to be appended to the vd column of filedata (code and results not shown here).
the Date class itself appears to accept NA as a value, but this NA appears to be slightly different from a logical NA
filedata <- data.table(1)[,
:=(va="bob", vb="barbara ann", vc=4, vd=as.Date(NA))][,V1:=NULL]
filedata
filedata[,lapply(.SD, class)]
rbindlist(list(alldata,filedata))
filedata <- data.table(1)[,
:=(va="bob", vb="barbara ann", vc=4, vd=as.logical(NA))][,V1:=NULL]
filedata[,lapply(.SD, class)]
rbindlist(list(alldata,filedata)) # note the lack of <> brackets around NA
...but it seems you can convert from a logical to a Date with explicit casting outside of data.table...
as.integer(as.logical(NA))
as.character(as.logical(NA))
as.Date(as.logical(NA))
class(as.Date(as.logical(NA)))
The text was updated successfully, but these errors were encountered: