When using dbWriteTable()
in the RMySQL
package, logical values are written as 0
regardless of value. I would expect that TRUE
values would return a 1
:
# Setup
# con is a valid MySQLConnection object
> df <- data.frame(string = 'Testing Logical Values',
t_lgl = TRUE,
f_lgl = FALSE,
stringsAsFactors = FALSE)
> df
string t_lgl f_lgl
1 Testing Logical Values TRUE FALSE
> class(df[,2])
[1] "logical"
# Test
# This schema has no tables until dbWriteTable() is called
> dbWriteTable(con,'test_table',df)
[1] TRUE
# Result
> dbReadTable(con,'test_table')
string t_lgl f_lgl
1 Testing Logical Values 0 0
> class(dbReadTable(con,'test_table')[,2])
[1] "integer"
Shouldn't the t_lgl
value return 1
since it was TRUE
and passed to dbWriteTable()
as a logical?
The RMySQL
package is being phased out in favour of RMariaDB
.
Using RMariaDB
I am able to successfully write logical
values to a MySQL database like this:
con <- dbConnect(RMariaDB::MariaDB(), group = "my-db")
dbWriteTable(con, "test", data.frame(a=T, b=F), overwrite = T)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With