I use RMySQL and a MySQL database to store my datasets. Sometimes data gets revised or I store results back to the database as well. Long story short, there is quite some interaction between R and the database in my use case.
Most of the time I use convenience functions like dbWriteTable
and dbReadTable
to write and read my data. Unfortunately these are just completely ignoring R data types and the MySQL field types. I mean I would expect that MySQL date fields end up in a Date
or POSIX
class. The other way around I´d think that these R classes are stored as a somewhat corresponding MySQL field type. That means a date should not be character – I do not expect to distinguish between float and doubles here...
I also tried to use dbGetQuery
– same result there. Is there something I have completely missed when reading the manual or is it simply not possible (yet) in these packages? What would by a nice work around?
EDIT: @mdsummer I tried to find something more in the documentation, but found only these disappointing lines: `MySQL tables are read into R as data.frames, but without coercing character or logical data into factors. Similarly while exporting data.frames, factors are exported as character vectors.
Integer columns are usually imported as R integer vectors, except for cases such as BIGINT or UNSIGNED INTEGER which are coerced to R's double precision vectors to avoid truncation (currently R's integers are signed 32-bit quantities).
Time variables are imported/exported as character data, so you need to convert these to your favorite date/time representation.
mytable <- getDbTable(con,"mytable")
:). returns character classes instead of Date or POSIXlt. It's more a general question, I am not so sure a) if is missed something on the manual like mdsummer suggested, b) or if i should start coding (in that case I ask: where to start). – PitcherRMySQL::dbReadTable
still returns warnings when converting data types such as "Unsigned INTEGER in col 5 imported as numeric." Since you posted your answer below, did you find a nice way to describe type conversion from MySQL to a R data frame? I have tried to look atDBI::dbReadTable
the conversion of column names is documented but not the conversion of types. – ZorazorahRPostgreSQL
package. I just learned thatRMySQL
has two well known new maintainers: blog.rstudio.org/2015/01/09/rmysql-0-1-0 . Maybe something new is coming up with their releases ... – Pitcher