Skip to content
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

Date column coerced from "date" -> "dttm" when xts converts back to tibble. #7

Closed
DavisVaughan opened this issue Jan 21, 2017 · 2 comments
Assignees
Labels

Comments

@DavisVaughan
Copy link
Collaborator

When using a tq_mutate() and a function like periodReturn, the date column is coerced from a date to a dttm (POSIXct) class. Minor quirk, but hopefully is fixable.

From our email:
"The date class change is what happens during the conversion process from tibble to xts and then back to tibble. When xts goes back to tibble the date is POSIXct by default."

Reproducible example created using jennybc's reprex package:

library(tidyquant)
apple <- tq_get("AAPL")
apple %>% tq_transform(Ad, transform_fun = periodReturn, period = "monthly", col_rename = "monthly_ret")
#> # A tibble: 121 × 2
#>          date  monthly_ret
#>        <dttm>        <dbl>
#> 1  2007-01-31  0.023031022
#> 2  2007-02-28 -0.013064288
#> 3  2007-03-30  0.098097108
#> 4  2007-04-30  0.074157832
#> 5  2007-05-31  0.214328672
#> 6  2007-06-29  0.007013839
#> 7  2007-07-31  0.079645970
#> 8  2007-08-31  0.051001827
#> 9  2007-09-28  0.108246690
#> 10 2007-10-31  0.237701136
#> # ... with 111 more rows
@mdancho84 mdancho84 added the bug label Jan 21, 2017
@mdancho84 mdancho84 self-assigned this Jan 21, 2017
mdancho84 added a commit that referenced this issue Jan 24, 2017
@mdancho84
Copy link
Collaborator

Fix implemented. Switched ymd() function to as_date(), which seems to do the trick. Please test it, and let me know if it works as planned.

@DavisVaughan
Copy link
Collaborator Author

Great! That seems to have worked. Nice, easy fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants