-
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
Support for abs() #97
Comments
Can you work out minimally completely verifiable example not involving other packages? A minimal one would, indeed, that we not support > min(x)
[1] 2011-12-05T08:30:00+00:00
> abs(x)
Error in abs(x) : non-numeric argument to mathematical function
> sin(x)
Error in sin(x) : non-numeric argument to mathematical function
> There are as shown many other ops we do not support. Yet > d <- data.table(ii = as.integer64(1:3), nn = as.nanotime(Sys.time()) + 0:2)
> d
ii nn
1: 1 2021-12-17T14:09:09.119302000+00:00
2: 2 2021-12-17T14:09:09.119302001+00:00
3: 3 2021-12-17T14:09:09.119302002+00:00
> print(d, class=TRUE)
ii nn
<i64> <nanotime>
1: 1 2021-12-17T14:09:09.119302000+00:00
2: 2 2021-12-17T14:09:09.119302001+00:00
3: 3 2021-12-17T14:09:09.119302002+00:00
> We can add |
library(nanotime)
x <- nanotime('2011-12-05 08:30:00.000', format ="%Y-%m-%d %H:%M:%E9S", tz ="GMT")
abs(x) results in Not sure it makes sense to support |
Yep. I edited my initial answer. |
I don't know but maybe @DavisVaughan (not sure how to mention someone not part of this thread?) can answer. |
Again. maybe Lines 515 to 528 in 69c7612
We represent time as numeric offsets from an epoch. Negative values are permitted, they signal earlier times: > xx <- as.nanotime(0) + c(-1,1) * 1e9
> xx
[1] 1969-12-31T23:59:59+00:00 1970-01-01T00:00:01+00:00
> Permitting > pp <- as.POSIXct(0, origin="1970-01-01", tz="UTC") + c(-1,1)*60
> pp
[1] "1969-12-31 23:59:00 UTC" "1970-01-01 00:01:00 UTC"
> abs(pp)
Error in Math.POSIXt(pp) : 'abs' not defined for "POSIXt" objects
> which is the same behaviour we have for > xx <- as.nanotime(0) + c(-1,1) * 1e9
> xx
[1] 1969-12-31T23:59:59+00:00 1970-01-01T00:00:01+00:00
> abs(xx)
Error in abs(xx) : non-numeric argument to mathematical function
> format(xx)
[1] "1969-12-31T23:59:59+00:00" "1970-01-01T00:00:01+00:00"
> show(xx)
[1] 1969-12-31T23:59:59+00:00 1970-01-01T00:00:01+00:00
> print(xx)
[1] 1969-12-31T23:59:59+00:00 1970-01-01T00:00:01+00:00
> |
I think that all makes sense. I will close this, at least it serves as a discussion point for the pillar issue. |
I can understand your frustration, and I appreciate that you understand that we cannot willy-nilly add an interface here. If |
Works now in the dev version of pillar with r-lib/pillar#380. |
That is welcome news! I didn't have time to dig through older version to confirm but I think we previously had the ability to use sich |
I suppose this is really a question of whether or not nanotime should "contain"/inherit from integer64, or if it should just be a slot. Since # this is FALSE
is.numeric(Sys.Date())
#> [1] FALSE
# because...
is.numeric.Date
#> function (x)
#> FALSE
#> <bytecode: 0x7fec1a030a80>
#> <environment: namespace:base>
# so i would have expected FALSE here
bit64::is.integer64(nanotime::nanotime(Sys.Date()))
#> [1] TRUE This returns Line 2 in 02f191d
So you end up being able to dispatch on nanotime objects when you write integer64 S3 methods, which is what went wrong in pillar. foo <- function(x) {
UseMethod("foo")
}
foo.default <- function(x) {
"default"
}
foo.integer64 <- function(x) {
"s3-method"
}
data <- bit64::as.integer64(1)
# With inheritance
setClass("s4_part1", contains = "integer64")
x <- new("s4_part1", data)
foo(x)
#> [1] "s3-method"
# Without inheritance
s4_part2 <- setClass("s4_part2", slots = c(data = "integer64"))
x <- s4_part2(data = data)
foo(x)
#> [1] "default" |
Thanks for digging where it went wrong for We have in the past made use of the fact that we inherit from |
checking in very late; glad to see it got sorted out (far better than I could have suggested), and happy new year to all! |
This is apparently causing a problem for displaying a nanotime column in a tibble.
r-lib/pillar#378
The text was updated successfully, but these errors were encountered: