This is a read-only copy of the MariaDB Knowledgebase generated on 2024-11-14. For the latest, interactive version please visit https://mariadb.com/kb/.

RMariaDB: MariaDB Driver for R

Description

RMariaDB is a database interface and MariaDB driver for R. This version is aimed at full compliance with R's DBI specification.

The link to the package on CRAN (R Package Repository) can be accessed from: CRAN RMariaDB

The package can be installed in R with the following statement:

install.packages("RMariaDB")

And loaded in the R environment executing:

library(RMariaDB)

Basic notions on R Programming can be found in article: R Statistical Programming Using MariaDB as the Background Database

RMariaDB Package Function Examples

library(RMariaDB)
library(DBI)
# Connect to my-db as defined in ~/.my.cnf
con <- dbConnect(RMariaDB::MariaDB(), group = "my-db")

dbListTables(con)
dbWriteTable(con, "mtcars", mtcars)
dbListTables(con)

dbListFields(con, "mtcars")
dbReadTable(con, "mtcars")

# You can fetch all results:
res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4")
dbFetch(res)
dbClearResult(res)

# Or a chunk at a time
res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4")
while(!dbHasCompleted(res)){
  chunk <- dbFetch(res, n = 5)
  print(nrow(chunk))
}
# Clear the result
dbClearResult(res)

# Disconnect from the database
dbDisconnect(con)
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.