-
Notifications
You must be signed in to change notification settings - Fork 7
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
R-devel changes set operations leading to a need for an update #132
Comments
A first attempt to reproduce under very current r-devel works. Details follow.
|
The crux seems to be that > setdiff(nanotime(1:10), nanotime(2:9))
[1] 1970-01-01T00:00:00.000000001+00:00 1970-01-01T00:00:00.000000002+00:00
[3] 1970-01-01T00:00:00.000000003+00:00 1970-01-01T00:00:00.000000004+00:00
[5] 1970-01-01T00:00:00.000000005+00:00 1970-01-01T00:00:00.000000006+00:00
[7] 1970-01-01T00:00:00.000000007+00:00 1970-01-01T00:00:00.000000008+00:00
[9] 1970-01-01T00:00:00.000000009+00:00 1970-01-01T00:00:00.000000010+00:00
> is now 'bad'. The hint by @kurthornik to rely on > setequal(nanotime(1:10), nanotime(2:9))
[1] FALSE
> While > setdiff(as.numeric(nanotime(1:10)), as.numeric(nanotime(2:9)))
[1] 1 10
> setdiff(bit64::as.integer64(nanotime(1:10)), bit64::as.integer64(nanotime(2:9)))
integer64
[1] 1 10
> so I guess we need a custom |
Hm, but we have ##' @rdname set_operations
setMethod("intersect",
c("nanotime", "nanotime"),
function(x, y) {
res <- callNextMethod()
oldClass(res) <- "integer64"
new("nanotime", res)
}) |
This works: ##' @rdname set_operations
setMethod("setdiff",
c("nanotime", "nanotime"),
function(x, y) {
#res <- callNextMethod()
#oldClass(res) <- "integer64"
res <- setdiff(as.integer64(x), as.integer64(y))
new("nanotime", res)
}) but it is above my S4 paygrade why root@ec707d7c7bd1:/work# RDscript -e 'library(nanotime); setdiff(nanotime(1:10), nanotime(2:9))'
[1] 1970-01-01T00:00:00.000000001+00:00 1970-01-01T00:00:00.000000010+00:00
root@ec707d7c7bd1:/work# and with that root@ec707d7c7bd1:/work# RDscript tests/tinytest.R
test_data.frame.R............. 16 tests OK 0.2s
test_data.table.R............. 16 tests OK 100ms
test_nanoduration.R........... 252 tests OK 0.2s
test_nanoival.R............... 304 tests OK 0.6s
test_nanoperiod.R............. 336 tests OK 0.2s
test_nanotime.R............... 267 tests OK 0.2s
test_ops.R.................... 58 tests OK 59ms
test_xts.R.................... 0 tests 1ms [Exited at #43: Skip xts tests for now]
test_zoo.R.................... 1 tests OK 8ms
All ok, 1250 results (1.5s)
root@ec707d7c7bd1:/work# |
Dirk, not really. |
Thanks for the follow-up, Kurt. What is very, very confusing to me is that we have three essentially identical dispatchers there for Lines 796 to 825 in 519c4b7
|
Could it be that the dispatches to > library(nanotime)
> u <- as.vector(nanotime(1:10))
> v <- as.vector(nanotime(2:9))
>
> !duplicated(unclass(u)) & (match(u, v, 0L) == 0L) # inner expression
[1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
> u[!duplicated(unclass(u)) & (match(u, v, 0L) == 0L)] # works as subset
[1] 4.940656e-324 4.940656e-323
> as.nanotime(u[!duplicated(unclass(u)) & (match(u, v, 0L) == 0L)]) # reclassed
[1] 1970-01-01T00:00:00+00:00 1970-01-01T00:00:00+00:00
> |
>>>> Dirk Eddelbuettel writes:
Could it be that the dispatches to bit64 and its integer64 "somehow" get lost?
When I run the commands in setdiff by hand all is well too:
> library(nanotime)
> u <- as.vector(nanotime(1:10))
> v <- as.vector(nanotime(2:9))
But that's the old setdiff code, not the one currently in R-devel.
What leaves me puzzled is that interactively I always seem to get
R> setdiff( nanotime(1:10), nanotime(2:9) )
[1] 1970-01-01T00:00:00.000000001+00:00 1970-01-01T00:00:00.000000010+00:00
Btw,
R> base::setdiff( nanotime(1:10), nanotime(2:9) )
integer64
[1] 1 2 3 4 5 6 7 8 9 10
clearly does not work as intended: part of the problem is that
R> class(x)
[1] "nanotime"
attr(,"package")
[1] "nanotime"
R> x <- unique(x)
R> class(x)
[1] "integer64"
so I guess one also needs unique() methods?
…-k
>
> !duplicated(unclass(u)) & (match(u, v, 0L) == 0L) # inner expression
[1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
> u[!duplicated(unclass(u)) & (match(u, v, 0L) == 0L)] # works as subset
[1] 4.940656e-324 4.940656e-323
> as.nanotime(u[!duplicated(unclass(u)) & (match(u, v, 0L) == 0L)]) # reclassed
[1] 1970-01-01T00:00:00+00:00 1970-01-01T00:00:00+00:00
>
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.*Message ID: <eddelbuettel/
***@***.***>
|
My bad for being asleep in an emacs buffer with R-release... The missing |
Well well well: Unstaged changes (2)
modified R/nanoival.R
@@ -814,6 +814,14 @@ setMethod("union",
new("nanotime", res)
})
+setMethod("unique",
+ "nanotime",
+ function(x) {
+ res <- callNextMethod()
+ oldClass(res) <- "integer64"
+ new("nanotime", res)
+ })
+
##' @rdname set_operations
setMethod("setdiff",
c("nanotime", "nanotime"), leads to root@ec707d7c7bd1:/work# RDscript -e 'library(nanotime); setdiff(nanotime(1:10), nanotime(2:9))'
[1] 1970-01-01T00:00:00.000000001+00:00 1970-01-01T00:00:00.000000010+00:00
root@ec707d7c7bd1:/work# which is what we want. No side-effects as far as I can tell from a quick look: root@ec707d7c7bd1:/work# RDscript tests/tinytest.R
test_data.frame.R............. 16 tests OK 0.1s
test_data.table.R............. 16 tests OK 98ms
test_nanoduration.R........... 252 tests OK 0.2s
test_nanoival.R............... 304 tests OK 0.6s
test_nanoperiod.R............. 336 tests OK 0.2s
test_nanotime.R............... 267 tests OK 0.2s
test_ops.R.................... 58 tests OK 58ms
test_xts.R.................... 0 tests 1ms [Exited at #43: Skip xts tests for now]
test_zoo.R.................... 1 tests OK 9ms
All ok, 1250 results (1.5s)
root@ec707d7c7bd1:/work# |
Sadly with this (new method for ----- FAILED[data]: test_nanoival.R<1105--1105>
call| expect_identical(setdiff(nanotime(1:10), nanotime(2:9)), c(nanotime(1),
call| --> nanotime(10)))
diff| Numeric: lengths (2, 10) differ
Error: 1 out of 1250 tests failed
Execution halted Uggh. |
The following tests ok under r-release and r-devel, but it is of 'not pure' as we should S4 dispatch 🙄 ##' @rdname set_operations
setMethod("setdiff",
c("nanotime", "nanotime"),
function(x, y) {
##res <- callNextMethod()
res <- setdiff(as.integer64(x), as.integer64(y))
oldClass(res) <- "integer64"
new("nanotime", res)
}) |
@eddelbuettel, when you define the |
I had not yet let me add that -- good catch. Which promptly gets me into trouble:
... because I had the function commented out. My bad. This leads to
Under r-release:
PS Scratch that. That was a side effect from temp. directory issues. |
So with a little break for the morning run I am now at a state where r-release and r-devel pass checks. But it is kinda ugly: R code##' @rdname set_operations
setMethod("setdiff",
c("nanotime", "nanotime"),
function(x, y) {
res <- if (getRversion() >= "4.5.0") setdiff(as.integer64(x), as.integer64(y)) else callNextMethod()
oldClass(res) <- "integer64"
new("nanotime", res)
}) and if (getRversion() > "4.5.0") {
##' @rdname nanotime
setMethod("unique",
"nanotime",
function(x) {
res <- callNextMethod()
oldClass(res) <- "integer64"
new("nanotime", res)
})
} NAMESPACEif (getRversion() > "4.5.0") exportMethods(unique) I cannot get it to work without the ugly-ish dispatch to setdiff() for integer64. @kurthornik Any sage advice? |
Given the time limit we have to address this, and the nod in email by @lsilvest, I plan to upload this in a day or two to get us out of the deadline. We can probably revisit later as needed, this is all conditional on R 4.5.0 or later anyway. |
Addressed in release 0.3.10 now on CRAN. |
Great. thanks! |
Fresh in via email from Vienna:
I am building rocker/r-devel weekly, the last one is currently dated Sep 8 ie was rebuilt last night.
@lsilvest can you take a look? I will try to repro here as well.
The text was updated successfully, but these errors were encountered: