kevinushey/RcppRoll

not working with by > 1

pasturm opened this issue · 5 comments

With the by argument set to > 1 the left out points are returned as random/uninitialized values.
Example:
roll_mean(rep(1,20), n = 3, by = 3)
[1] 1.000000e+00 1.071419e+200 9.385277e+223 1.000000e+00 4.311955e-80 1.840099e-80 1.000000e+00 7.724200e-37 2.647809e-32
[10] 1.000000e+00 1.426530e-71 3.791529e+179 1.000000e+00 3.315553e-33 5.391965e+241 1.000000e+00 7.096584e-110 9.486060e-322

A workaround is:
foo = roll_mean(rep(1,20), n = 3, by = 3)
foo = foo[seq(1, length(foo), by = 3)]
but it would be nice if this was done inside the roll_ functions.

This should be fixed with the latest version on GitHub (sorry, not on CRAN yet). Can you try installing with:

devtools::install_github('kevinushey/RcppRoll')

and let me know if you still see the issue?

Whoops, I lied -- there is definitely something amiss here as it only occasionally produces the correct result! I'll dig in deeper; thanks for reporting.

Is this fixed now?

No. I still get

RcppRoll::roll_mean(rep(1,10), n = 3, by = 3)
[1]  1.000000e+00 1.234163e-315 2.598143e-315  1.000000e+00 9.686561e-316 9.686768e-316  1.000000e+00 9.685727e-316

or even

[1]  1.000000e+00  3.331680e-28 2.584442e+185  1.000000e+00  4.003587e+88 8.422677e-316  1.000000e+00 3.395193e-313

whereas I would expect

zoo::rollapply(rep(1,10), 3, mean, by = 3)
[1] 1 1 1
> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=German_Switzerland.1252  LC_CTYPE=German_Switzerland.1252    LC_MONETARY=German_Switzerland.1252
[4] LC_NUMERIC=C                        LC_TIME=German_Switzerland.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RcppRoll_0.2.3

loaded via a namespace (and not attached):
[1] compiler_3.5.0 tools_3.5.0   

This appears to be resolved in the development version of RcppRoll:

devtools::install_github("kevinushey/RcppRoll")

I really should make a CRAN submission one of these days ...

> devtools::install_github("kevinushey/RcppRoll")
Using GitHub PAT from envvar GITHUB_PAT
Downloading GitHub repo kevinushey/RcppRoll@master
from URL https://api.github.com/repos/kevinushey/RcppRoll/zipball/master
Installing RcppRoll
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ  \
  --no-save --no-restore --quiet CMD INSTALL  \
  '/private/var/folders/tm/5dt8p5s50x58br1k6wpqnwx00000gn/T/RtmpqqNMUm/devtoolsc1956019a270/kevinushey-RcppRoll-90c0ed5'  \
  --library='/Users/kevin/Library/R/3.5/library' --with-keep.source  \
  --install-tests

* installing *source* package ‘RcppRoll’ ...
** libs
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Users/kevin/Library/R/3.5/library/Rcpp/include" -I/usr/local/include   -fPIC  -g -O3 -Wall -pedantic -mtune=native -Wno-unused-local-typedef -I/usr/local/opt/openssl/include -c RcppExports.cpp -o RcppExports.o
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Users/kevin/Library/R/3.5/library/Rcpp/include" -I/usr/local/include   -fPIC  -g -O3 -Wall -pedantic -mtune=native -Wno-unused-local-typedef -I/usr/local/opt/openssl/include -c RcppRoll.cpp -o RcppRoll.o
clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/opt/openssl/lib -o RcppRoll.so RcppExports.o RcppRoll.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Users/kevin/Library/R/3.5/library/RcppRoll/libs
** R
** tests
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (RcppRoll)
> RcppRoll::roll_mean(rep(1,10), n = 3, by = 3)
[1] 1 1 1