New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shift.time: no applicable method for 'shift.time #268

Closed
pverspeelt opened this Issue Sep 24, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@pverspeelt
Contributor

pverspeelt commented Sep 24, 2018

Description

shift.time is an exported function of xts, but if you try to use it, it will result in an error.

Error in UseMethod("shift.time") :
no applicable method for 'shift.time' applied to an object of class "c('xts', 'zoo')"

Expected behavior

shift.time.xts is the underlying function called when you have an xts object and you want to shift the time by n seconds.

Reason

I found that the reason why this doesn't work is that shift.time.xts is not exported as an s3 method in the namespace. Adding S3method(shift.time, xts) to the namespace will resolve this issue.

Minimal, reproducible example

Following code will result in the error

df1 <- data.frame(dates = Sys.time() + 1:10, 
                  values = 1:10)

df1_xts <- xts(df1$values, order.by = df1$dates)
shift.time(df1_xts, n = 60)

using the following code, the shift works
xts:::shift.time.xts(df1_xts, n = 60)

Session Info

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=Dutch_Netherlands.1252  LC_CTYPE=Dutch_Netherlands.1252    LC_MONETARY=Dutch_Netherlands.1252
[4] LC_NUMERIC=C                       LC_TIME=Dutch_Netherlands.1252    

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

other attached packages:
[1] xts_0.11-1 zoo_1.8-4 

loaded via a namespace (and not attached):
[1] compiler_3.5.0  tools_3.5.0     yaml_2.2.0      grid_3.5.0      lattice_0.20-35
@joshuaulrich

This comment has been minimized.

Owner

joshuaulrich commented Sep 30, 2018

Thanks for the report! I agree this is a bug, and agree with your proposed solution. Would you like to create a PR to add S3method(shift.time, xts) to NAMESPACE?

@joshuaulrich joshuaulrich added the bug label Sep 30, 2018

@pverspeelt pverspeelt closed this Sep 30, 2018

@pverspeelt

This comment has been minimized.

Contributor

pverspeelt commented Sep 30, 2018

Accidentally pushed close button when trying to link it to the PR :-(

@joshuaulrich joshuaulrich reopened this Oct 6, 2018

@joshuaulrich joshuaulrich self-assigned this Oct 6, 2018

@joshuaulrich joshuaulrich added this to the 0.11-2 milestone Oct 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment