4

Is there some magic to using dplyr to access a database when it has a date field?

A dplyr tbl_df converts mysql datetime fields to chr. That wouldn't be so bad if I could as.Date() them back. But if I do that before collect()'ing the table, I get an error that as.Date() is an invalid sql function. I can sort-of workaround this by calling collect(), but then I'm copying all of the data out of the database, which is what I was trying to avoid. In addition, once I've collect()'ed, its a data.frame, so if I want to join it with another tbl I have to set copy=TRUE and copy that one into memory as well.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Bob
  • 1,274
  • 1
  • 13
  • 26
  • dplyr doesn't do any conversion, it relies on the underlying database connector. If you provide a reproducible example, it would be possible to see which one you're using – hadley Dec 25 '14 at 19:10
  • RMySql - thanks Hadley, you answered it. – Bob Dec 26 '14 at 04:14
  • Hi, what did you do? I'm having a similar problem, but didn't understand what was the solution. – Manoel Galdino May 03 '17 at 13:34
  • This is till out here unanswered... @hadley if you want to convert your comment to an answer I'll accept it. – Bob Jun 08 '17 at 20:38
  • 1
    Possible duplicate of [importing date correctly from MySQL into R](https://stackoverflow.com/questions/43762009/importing-date-correctly-from-mysql-into-r) – 千木郷 Feb 26 '19 at 18:34

0 Answers0