Comments (4)
Connecting the two packages also connects their dependencies which is something less desirable for the majority of users.
Maybe something like this belongs in a smaller utility package (just how in dang I have some xts / data.table mappers) ?
Apart from that, why not use what nanotime
has? Aren't you just redoing this:
R> library(nanotime)
R> nt <- as.nanotime(Sys.time())
R> nt
[1] 2020-10-09T12:08:00.333868+00:00
R> as.Date(nt)
[1] "2020-10-09"
R>
from anytime.
Indeed I did not remember as.Date.nanotime
, I was fearing a doh moment but it seems this way is quite faster.
suppressMessages(expr = {
library(nanotime)
library(bit64)
library(microbenchmark)
})
N <- 1e7
x <- nanotime(Sys.time() + 864000 * runif(n = N, -1, 1))
microbenchmark::microbenchmark(
y <- as.Date(x),
y1 <- as.Date(as.integer64(x)/1e9/86400, origin = "1970-01-01"),
times = 10L
) -> res
res
# Unit: milliseconds
# expr min lq mean median uq max neval
# y <- as.Date(x) 416.4999 484.2233 494.6725 496.2450 517.1470 572.8053 10
# y1 <- as.Date(as.integer64(x)/1e+09/86400, origin = "1970-01-01") 187.1953 197.8244 224.7171 203.0242 262.8207 271.0411 10
identical(as.integer(y), as.integer(y1))
# [1] TRUE
sessionInfo()
# R version 4.0.2 (2020-06-22)
# Platform: x86_64-redhat-linux-gnu (64-bit)
# Running under: Fedora 32 (Workstation Edition)
#
# Matrix products: default
# BLAS/LAPACK: /usr/lib64/libopenblas-r0.3.10.so
[line_length_linter] [I] Lines should not be more than 80 characters.
# locale:
# [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8 LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8 LC_PAPER=en_GB.UTF-8 LC_NAME=C
# [9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
#
# attached base packages:
# [1] stats graphics grDevices utils methods base
#
# other attached packages:
# [1] microbenchmark_1.4-7 bit64_4.0.5 bit_4.0.4 nanotime_0.3.2 nvimcom_0.9-102 colorout_1.2-2
#
# loaded via a namespace (and not attached):
# [1] zoo_1.8-8 compiler_4.0.2 tools_4.0.2 RcppCCTZ_0.2.9 Rcpp_1.0.5 grid_4.0.2 lattice_0.20-41 CoprManager_0.3.5
You seem to be doing smart things in
##' @rdname nanotime
as.POSIXct.nanotime <- function(x, tz="", ...) {
## if (verbose) warning("Lossy conversion dropping precision")
if ((tz == "" || is.null(tz)) && length(attr(x, "tzone")) > 0) {
tz <- attr(x, "tzone")
}
pt <- as.POSIXct(as.double(S3Part(x, strictS3=TRUE)/1e9), tz=tz, origin="1970-01-01")
pt
}
But that's not used (as far as I understand in as.Date (you might have forgotten to pass ...
))
##' @rdname nanotime
as.Date.nanotime <- function(x, ...) {
as.Date(as.POSIXct(x))
}
from anytime.
If the user passes nothing ...
is an empty default. We have to have it in the signature...
If you don't mind, I am closing this. That your (to be frank a little more hackish int math) function is very well for you and you can and should use it if that is important to you. This was for starters at the wrong repo and there still is nothing deficient in anytime
. Always eager to hear real issues (as e.g. in your earlier "bulk test" bug report) but this does not seem to be one.
from anytime.
Ok thanks, it's wrong package indeed.
I take from this there is no point changing as.Date in nanotime because you think the above "feels" hackish ? Or did I miss something and it is actually wrong ?
Regards
from anytime.
Related Issues (20)
- Cannot use both tz and useR=TRUE arguments
- Strange issue - anydate does not recognize format or ... ? HOT 3
- UK v US formats HOT 2
- Process only unique values for speed, please :) HOT 27
- Time is silently scrubbed when using certain string date time formats HOT 3
- Add argument for default MM/DD to add to just YYYY inputs HOT 1
- timedatectl problem on HPC? HOT 2
- Failed to activate service 'org.freedesktop.timedate1' on Google Cloud VM HOT 9
- month year specification HOT 7
- Returning NA value HOT 3
- Feature requests: more flexibly find date substring in a non-date string; and process additional incomplete date substrings HOT 11
- European vs US date formats HOT 3
- Feature request: function to return which format was recognized. HOT 3
- Anytime errors with length 1 NA HOT 6
- Chinese date format suggestion HOT 3
- just yyyy-mm-dd hh:mm:ss but not AEST suffix HOT 5
- anytime() sometimes returns the wrong date HOT 2
- Inconsistent handling of vectors with unknown values HOT 1
- single digit dates with unambiguous month and year HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anytime.