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

complete.cases does not work with nanotime #4744

Closed
vermosen opened this issue Oct 9, 2020 · 4 comments · Fixed by #4752
Closed

complete.cases does not work with nanotime #4744

vermosen opened this issue Oct 9, 2020 · 4 comments · Fixed by #4752
Milestone

Comments

@vermosen
Copy link

vermosen commented Oct 9, 2020

Hi,

I have a problem with the following example:

library(nanotime)
library(data.table)

DT <- data.table(time=as.nanotime(seq(1, 3)))
DT[, shift.val := shift(time, 1, fill=NA)]

is.na(DT[1, shift.val])       # TRUE
DT[complete.cases(DT)]        # still shows up here

here is my current configuration:

> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 8 (Core)

Matrix products: default
BLAS:   /opt/r40-gcc84/lib64/R/lib/libRblas.so
LAPACK: /opt/r40-gcc84/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] data.table_1.13.0 nanotime_0.3.2

loaded via a namespace (and not attached):
[1] zoo_1.8-8       bit_4.0.4       compiler_4.0.0  RcppCCTZ_0.2.9
[5] Rcpp_1.0.5      bit64_4.0.5     grid_4.0.0      lattice_0.20-41

@vermosen
Copy link
Author

vermosen commented Oct 9, 2020

Actually, this doesn't seems to relate to data.table. The same problem do occur with regular data.frame objects. There is a seemingly related remark in ?complete.cases ...

@MichaelChirico
Copy link
Member

MichaelChirico commented Oct 12, 2020

What is as.nanotime? I think nanotime(.) is intended

@MichaelChirico
Copy link
Member

Thanks for the report, I can reproduce and I can confirm the note you saw in complete.cases is indeed the source of the issue:

A current limitation of this function is that it uses low level functions to determine lengths and missingness, ignoring the class.

The issue is that nanotime is stored (from R's perspective) as double, so complete.cases is looking for NA_real_ but the missing value for nanotime is different.

Luckily for you, there is a data.table method for na.omit that is bit64-aware, so this should work:

na.omit(DT)

Unluckily for you, it doesn't (yet) 😄

However, a fix is ready in #4752

ben-schwen added a commit to ben-schwen/data.table that referenced this issue Oct 15, 2020
@jangorecki
Copy link
Member

I think we can close this one. It is base R issue which s already documented in base R.

@mattdowle mattdowle added this to the 1.14.1 milestone Aug 19, 2021
@jangorecki jangorecki modified the milestones: 1.14.9, 1.15.0 Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants