My question is pretty much the same as this one. In short, I'm using dplyr (along with RMySQL) to import a MySQL table with a datetime column, and I want to convert it to date in R. In the question linked above, no answer was posted, only a comment by Hadley. The OP apparently found a solution based on the comment made. I understood from Hadley's comment that I could solve the issue by properly importing the column as date into R. Then there would be no need to use as.Date. However, I couldn't find how to do that with dplyr and RMySQL.
I don't know how to post a fully reproducible example, because it's a MySQL database connection, but I'll post my code:
If I try:
pedidos <- my_db %>%
tbl("pedidos") %>%
mutate(test = as.Date(DateSent))
And then I run:
pedidos
R returns:
FUNCTION AS.DATE does not exist
Like the OP in the other question, I can workaround the issue using collect(), but then it defeats the purpose of not copying the data into memory. Here´s some info about data type in MySQL DateSent is datetime
and R sessionInfo():
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=Portuguese_Brazil.1252
[2] LC_CTYPE=Portuguese_Brazil.1252
[3] LC_MONETARY=Portuguese_Brazil.1252
[4] LC_NUMERIC=C
[5] LC_TIME=Portuguese_Brazil.1252
attached base packages:
[1] stats graphics grDevices utils datasets
[6] methods base
other attached packages:
[1] RMySQL_0.10.11 DBI_0.5-1 dplyr_0.5.0
[4] digest_0.6.12
loaded via a namespace (and not attached):
[1] lazyeval_0.2.0 magrittr_1.5 R6_2.2.0
[4] assertthat_0.1 rsconnect_0.5 tools_3.3.1
[7] tibble_1.2 Rcpp_0.12.8