You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A subsetting error will be thrown if there are duplicate entries in the INDEX argument to period.apply(). This is possible if users create custom end points without using the endpoints() function.
x<- .xts(1:10, 1:10)
ep<- c(2, 4, 6, 8, 10)
period.apply(x, c(0, ep, nrow(x)), mean)
# Error in `[.xts`(x, (INDEX[y] + 1):INDEX[y + 1]) : # subscript out of bounds
Possibly worse, you get incorrect results if INDEX is not sorted.
The simplest solution is probably to call xts::isOrdered(INDEX) before looping over it. This solves both problems because isOrdered() returns FALSE if x has duplicate entries. If isOrdered() returns FALSE, we should throw a warning and then call sort and unique on INDEX before proceeding.
We could also prevent any performance hit during internal calls to period.apply() (e.g. apply.daily) by checking for a specific argument passed via ... (e.g. _internal = TRUE). Using a non-syntactic name would prevent accidental matching with arguments intended for FUN.
The text was updated successfully, but these errors were encountered:
period.apply() expects INDEX to be sorted and unique. Check for those
characteristics. If they're not present, then sort INDEX and ensure it
is unique.
See #171.
period.apply() expects INDEX to start with zero and end with the
number of observations in 'x'. Check those values are present, and
add them if they are not.
See #171.
A subsetting error will be thrown if there are duplicate entries in the
INDEX
argument toperiod.apply()
. This is possible if users create custom end points without using theendpoints()
function.Possibly worse, you get incorrect results if
INDEX
is not sorted.The simplest solution is probably to call
xts::isOrdered(INDEX)
before looping over it. This solves both problems becauseisOrdered()
returnsFALSE
ifx
has duplicate entries. IfisOrdered()
returnsFALSE
, we should throw a warning and then callsort
andunique
onINDEX
before proceeding.We could also prevent any performance hit during internal calls to
period.apply()
(e.g.apply.daily
) by checking for a specific argument passed via...
(e.g._internal = TRUE
). Using a non-syntactic name would prevent accidental matching with arguments intended forFUN
.The text was updated successfully, but these errors were encountered: