I am looking for a way to work with connected databases using R so I don't have to upload databases to my memory. I have been working using pool
or DBI
packages to connect to the database and dplyr
for data manipulation, but I have found some problems I haven't been able to solve:
Loading the Data:
library(pool)
library(dplyr)
library(RMariaDB)
my_db <- dbPool(
MariaDB(),
donate = "aaa",
host = "localhost",
username = "root"
)
- 1st Problem: Unable to use slice function
my_db %>% tbl("bbb") %>%
slice(2:10)
#Error: slice() is not supported on database backends
For this problem I have came up with this work around:
my_db %>% tbl("bbb") %>%
mutate(Rowindx = row_number()) %>%
filter(Rowindx >= 2 && Rowindx <= 10)
This has work for me, but I wanna know if there is a better solution to this problem
- 2nd Problem: Unable to change the class or type of a column using transmute()
I have a column class character and I want to change it to factor. I have tried the following code, that does work with no connected databases.
my_db %>% tbl("bbb") %>%
transmute (colname = factor(colname))
#Error: FUNCTION aaa.factor does not exist [1305]
For this problem I haven't came up with any solution, any idea about how to solve it will be appreciated.