Comments (6)
integer64 is weird because it's actually a REALSXP
(R's internal double vector). So anything that doesn't know about integer64 treats it as a double, but the result will be a weird number because the raw bits of a 64-bit integer and the raw bits of a 64-bit double don't share any equivalence as base-10 numbers.
The result of mean(bit64::as.integer64(1:10))
is correct because the sum of integers 1:10 is 55 (also an integer), but integer division by 10 discards any remainder, so you get 5.
from ttr.
I think the easiest way to do this would be to add Suggests: bit64
to the DESCRIPTION and special case that class inside the functions.
Here's a helper function to test for integer64
objects and that bit64
is installed.
is.integer64 <- function(x)
{
if (inherits(x, "integer64")) {
if (requireNamespace("bit64", quietly = TRUE)) {
return(TRUE)
} else {
stop("install the 'bit64' package to use this function on integer64 objects")
}
} else {
return(FALSE)
}
}
Then something like this for runSum()
:
if (is.integer64(x)) {
top <- bit64::as.integer64(rep(0, n))
csum <- cumsum(x)
result <- csum - c(top, head(csum, -n))
is.na(result) <- seq_len(n - 1 + NAs)
}
from ttr.
i vaguely remember reading somewhere that supporting the bit64 types just involved adding headers and linking , but no code changes, so wasnt sure. what was actually involved. thats the only reason i left that open.
for me, i ran into this because another package has loaded some data as int64 and it took me a while to track that down as the source of my issue. i fixed it by forcing the data to be loaded as a float. im not sure its worth adding the support unless someone else actually needs it. even an "int64 not currently supported." message would be pretty low priority, but i'd take that on if you want.
from ttr.
I don't see any packages that currently link to bit64
, so there isn't a package with an example of how to handle integer64
objects in C using the bit64 C API.
data.table supports integer64, and they just check inherits(x, "integer64")
and then cast to int64_t
and then work with the cast object.
from ttr.
just looked at some internals. its a weird beast. im not sure there is value in supporting this in xts. im now more in the camp of an error message, at best
> mean(bit64::as.integer64(1:10))
#integer64
#[1] 5
> mean(1L:10L)
#[1] 5.5
thinking further, most TTR and runXX functions, other than runSum
, would probably return a double anyway, so. im im even more suspect in adding any complexity here.
from ttr.
Findings:
- integer64 doesnt seem to support matrix. since xts is based on matrix, xts cant really be used with integer64
bit64::is.integer64(matrix(bit64::as.integer64(1:9)))
- The following function will solve a lot of scenarios quite simply, since it would get dispatched to by
try.xts
as.xts.integer64 <- function(x, order.by, dateFormat = "POSIXct", frequency = NULL, ...) {stop("integer64 not supported")}
- this would not handle explicit
xts
creation with integer64 input.
This leaves me here:
- It probably makes sense to do something in
xts
instead ofTTR
- How far down the rabbit hole we should go with this?
- what about a data.frame as input that has integer64 columns (which was my actual real world issue)
- What about functions like
diff.xts
that dont usetry.xts
?xts::diff.xts(bit64::as.integer64(1:9))
- might be simplest to just check if
bit64
has been loaded and just issue a blanket warning whenxts
gets loaded
from ttr.
Related Issues (20)
- "Series contains non-leading NAs" on stoch() HOT 8
- support TR calculations without Average HOT 2
- ERROR: package or namespace load failed for 'TTR' in dyn.load(file, DLLpath = DLLpath, ...): HOT 1
- Standardize leading NA checks in C code
- ALMA optimization HOT 2
- runSum produces leading NA when cumulative = TRUE HOT 2
- how can i buy and finish a operation in R? HOT 1
- Issue on nSig for TRIX HOT 2
- cumulative runSD returns all NA HOT 3
- runMean(..., cumulative = TRUE) doesn't account for leading NA in denominator
- Use R_forceSymbols(dll, TRUE) for native routines
- Add argument to EMA to prevent setting first n-1 obs to NA
- malloc(): invalid size (unsorted) HOT 8
- CTI doesn't pad non-xtsible inputs with NA
- The Symbol for Nano Labs Ltd (NASDAQ), NA, conflicts with NA in R HOT 6
- Change Readme to reflect that Fortran is no longer used HOT 1
- indicators show different values on windows of different sizes HOT 4
- rolling trimmed mean HOT 7
- Add Fibonacci Retracements and Extensions
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 ttr.