Comments (9)
See #16, comments there welcome. Seems to work, a fresh set of eyes may help.
from nanotime.
bit64
must be loaded and attached, otherwise the as.integer64
generic isn't available. If the generic isn't available, there's nothing to dispatch to the as.integer64.nanotime
method. That said, you can always call the generic directly: bit64::as.integer(nt)
.
from nanotime.
Given the fairly strong dependence of nanotime
on bit64
(at least, that's my impression from the 'Design' section of the help page), would it make sense to load and attach bit64
by default?
from nanotime.
Not sure. Depends
is sort-of frowned upon these days. I would rather keep it as it is now. We do import it though.
Suggestions for making this better or more robust, @joshuaulrich ?
from nanotime.
It's a thorny issue I've discussed with Achim Z before regarding xts and zoo. To paraphrase his comments for this situation:
nanotime
could re-export the generic, but then any packages depending onnanotime
must decide whether to register withbit64::as.integer64
ornanotime::as.integer64
. Or they have to fully export their S3 method so it would be found by either generic.
As Dirk said, using Depends
is discouraged. I think it would be especially so in this case, since it's not clear that users who want nanotime
are also going to want every bit (pun intended) of bit64
on their search path as well.
If you want to convert nanotime
to integer64
, I would ask: why? Once you answer that, we might be able to have a discussion about adding functionality to nanotime
to meet that need.
from nanotime.
I pretty much feel the same way -- but this was eloquently put. One really only wants explicit integer64
for debugging.
So I'd say leave as is ...
from nanotime.
So ... would defining
as.integer64 <- function(...) bit64::as.integer64(...)
as a free (and exported) function greatly upset the higher powers of generic functions? Seems to work:
R> library(nanotime) ## bit64 not loaded
R> as.integer64(nt)
integer64
[1] 1486055787633531000
R>
and then
R> suppressMessages(library(bit64))
R> as.integer64(nt)
[1] "2017-02-02T17:16:27.633531000+00:00"
R> class(as.integer64(nt))
[1] "nanotime" "integer64"
R> bit64::as.integer64(nt)
[1] "2017-02-02T17:16:27.633531000+00:00"
R> nanotime:::as.integer64.nanotime(nt)
integer64
[1] 1486055787633531000
R>
so it looks like worst case I may have to try clean up one class attribute stripping call.
Edit: Tempting but does not quite work, sadly.
from nanotime.
Hm, I may have stumbled on the appropriate fix:
With bit64
edd@max:~/git/nanotime(feature/issue15)$ cat issue15with.R
library(nanotime)
suppressMessages(library(bit64))
nt <- nanotime("2017-02-02T17:16:27.633531000+00:00")
print(nt)
print(as.integer64(nt))
edd@max:~/git/nanotime(feature/issue15)$ r issue15with.R
[1] "2017-02-02T17:16:27.633531000+00:00"
integer64
[1] 1486055787633531000
edd@max:~/git/nanotime(feature/issue15)$
Without bit64
edd@max:~/git/nanotime(feature/issue15)$ cat issue15without.R
library(nanotime)
nt <- nanotime("2017-02-02T17:16:27.633531000+00:00")
print(nt)
print(as.integer64(nt))
edd@max:~/git/nanotime(feature/issue15)$ r issue15without.R
[1] "2017-02-02T17:16:27.633531000+00:00"
integer64
[1] 1486055787633531000
edd@max:~/git/nanotime(feature/issue15)$
That is what we wanted, in both cases. Only change: exporting as.integer64
in NAMESPACE.
Edit: Naa, didn't quite work either.
Edit 2: Did work. Needs a re-export, and hence corresponding documentation.
edd@max:~/git/nanotime(feature/issue15)$ rcc.r
────────────────────────────────────────────────────────────────────────────────
─ using log directory ‘/tmp/file58ea309392af/nanotime.Rcheck’
─ using R version 3.3.2 (2016-10-31)
─ using platform: x86_64-pc-linux-gnu (64-bit)
─ using session charset: UTF-8
✔ checking for file ‘nanotime/DESCRIPTION’
─ checking extension type ... Package
─ this is package ‘nanotime’ version ‘0.1.1’
✔ checking package namespace information
✔ checking package dependencies
✔ checking if this is a source package
✔ checking if there is a namespace
✔ checking for executable files
✔ checking for hidden files and directories
✔ checking for portable file names
✔ checking for sufficient/correct file permissions
✔ checking whether package ‘nanotime’ can be installed
✔ checking installed package size
✔ checking package directory
✔ checking DESCRIPTION meta-information
✔ checking top-level files
✔ checking for left-over files
✔ checking index information
✔ checking package subdirectories
✔ checking R files for non-ASCII characters
✔ checking R files for syntax errors
✔ checking whether the package can be loaded
✔ checking whether the package can be loaded with stated dependencies
✔ checking whether the package can be unloaded cleanly
✔ checking whether the namespace can be loaded with stated dependencies
✔ checking whether the namespace can be unloaded cleanly
✔ checking loading without being on the library search path
✔ checking dependencies in R code
✔ checking S3 generic/method consistency
✔ checking replacement functions
✔ checking foreign function calls
✔ checking R code for possible problems
✔ checking Rd files
✔ checking Rd metadata
✔ checking Rd cross-references
✔ checking for missing documentation entries
✔ checking for code/documentation mismatches
✔ checking Rd \usage sections
✔ checking Rd contents
✔ checking for unstated dependencies in examples
✔ checking examples
✔ checking for unstated dependencies in ‘tests’
✔ checking tests
✔ checking PDF version of manual
── 0 errors ✔ | 0 warnings ✔ | 0 notes ✔
edd@max:~/git/nanotime(feature/issue15)$ r issue15with.R
[1] "2017-02-02T17:16:27.633531000+00:00"
integer64
[1] 1486055787633531000
edd@max:~/git/nanotime(feature/issue15)$ r issue15without.R
[1] "2017-02-02T17:16:27.633531000+00:00"
integer64
[1] 1486055787633531000
edd@max:~/git/nanotime(feature/issue15)$
from nanotime.
To answer Josh's question on why I want to do the conversion, essentially it's serialization. I'm interfacing with a system that wants time in microseconds from the epoch so this seemed like an easy way to fold that in.
In a larger, not-my-immediate-problem, sense I feel like a function that shows up in the docs should just work or provide a better error message.
from nanotime.
Related Issues (20)
- R-devel nags HOT 3
- Filter timestamps between times from specific time zone HOT 2
- Add/subtract methods for nanoduration/difftime durations HOT 1
- Add/subtract methods for nanotime datetimes and difftime durations HOT 1
- Add 'as.nanoduration.Duration()' HOT 5
- Issues with 'nanoival()' checks/tests HOT 7
- 'as.nanotime(NA_character_)' throws an ERROR HOT 5
- 7 out of 1256 tests failed on ppc32 HOT 5
- POSIXct -> nanotime -> POSIXct consistency HOT 13
- nanoduration divided by nanoduration should return double rather than integer64
- as.Date does not handle the case where tz is a vector HOT 5
- Could you implement comparaison on nanoduration and Character HOT 3
- Duration since yesterday's midnight in some timezone HOT 4
- nanotime 0.3.3 release HOT 2
- as.character(nanotime) returns the underlying integer HOT 4
- Export `nanoperiod` C interface for other packages to use
- Incorrect parsing for negative `nanoperiod`
- Support for abs() HOT 13
- Add to awesome-vctrs? HOT 1
- Incorrect subsetting with operator `%in%` HOT 15
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 nanotime.