arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

Using MariaDB With R

hashtag
Introduction to R

R is a language and environment for statistical computing and graphics. R provides a wide variety of statistical (linear and nonlinear modeling, classical statistical tests, time-series analysis, classification, clustering, …), graphical techniques, machine learning packages and is highly extensible.

One of R’s strengths is the ease with which well-designed publication-quality plots can be produced, including mathematical symbols and formulae where needed. Great care has been taken over the defaults for the minor design choices in graphics, but the user retains full control.

hashtag
The R Environment

R is an integrated suite of software facilities for data manipulation, calculation, and graphical display.

It includes:

• an effective data handling and storage facility,

• a suite of operators for calculations on arrays, in particular matrices,

• a large, coherent, integrated collection of intermediate tools for data analysis,

• graphical facilities for data analysis and display either on-screen or on hardcopy, and

• a well-developed, simple and effective programming language which includes conditionals, loops, user-defined recursive functions and input and output facilities.

hashtag
Using R with MariaDB

hashtag
R Installation

Some basic notions / tips on how to use R along with MariaDB are the following:

A. The recommended R distribution is “Base R”:

B. The recommended R GUIs are RStudio Desktop, or RStudio Server:

Alternative GUIs would be:

  • RCode (PGM Solutions): .

“R” and “MariaDB Server” can be installed either in the same server, or in different servers, as an ODBC communication protocol will be used for the exchange of data between the two environments.

hashtag
Data Transfer between R and MariaDB

hashtag
Package: "odbc"

For the transfer of data between MariaDB Server and R Environment, it is recommended R's "odbc" Package:

  • “odbc" is a new R package available on CRAN (Since 2017-02-05), and maintained by RStudio, which is designed to comply with the DBI specification.

  • Tutorials on how to use R's "odbc" package can be found here:

    • Setting up ODBC Drivers:

The "odbc" package requires to have previously installed the MariaDB or MySQL ODBC connector:

For installing the "odbc" package from CRAN, execute in R:

hashtag
Package: "RMariaDB"

“RMariaDB” R library, is a modern 'MariaDB' client based on 'Rcpp'.

For installing RMariaDB package through CRAN, execute the following R statement:

And for connecting to MariaDB:

hashtag
Other Packages: "readr", "RODBC"

There are other alternatives for data transfer between R and MariaDB:

  • “readr” R package, for writing / reading CSV files. To be used in MariaDB along with “LOAD DATA INFILE”.

  • "RODBC" R package: Robust and well-tested (Since 2000-05-24) package which enables data transfer between R and MariaDB by means of an ODBC connector:

    • It is slightly slower than RStudio's new "odbc" package (See benchmarks):

hashtag
R Programming Resources

hashtag
A) Programming

Recommended resources for learning how to program in R are the following:

hashtag
B) Statistics

A recommended book for understanding the underlying statistics in the R packages is:

hashtag
C) Cheatsheets: Concept Summary

  • Rstudio Cheatsheets are a recommended and valuable resource:

  • Along with the following Base R reference card:

hashtag
D) Search Engine & R Package Spotlight

  • Search Engines:

hashtag
E) Statistical / Unsupervised Machine Learning, Deep Learning and Artificial Intelligence

H2O.AI

The R Programming language has support for the H2O.ai library (), which enables to create in-memory multi-cluster GPU powered machine learning models.

For installing H2O.ai through CRAN, execute:

The following R Statements can be used for importing a MariaDB table to H2O.ai using the R Front End:

  • import_sql_table: "This function imports a SQL table to H2OFrame in memory".

  • import_sql_select: "This function imports the SQL table that is the result of the specified SQL query to H2OFrame in memory".

NOTE: Be sure to start the h2o.jar in the terminal with your downloaded JDBC driver in the classpath:

KERAS

offers an interface to , a high-level neural networks 'API'.

'Keras' was developed with a focus on enabling fast experimentation, supports both convolution based networks and recurrent networks (as well as combinations of the two), and runs seamlessly on both 'CPU' and 'GPU' devices.

R LIBRARIES: CARET

A book which introduces core Machine Learning concepts:

hashtag
F) Text Mining

Documentation on how to perform Text Mining in R can be found in the book "Text Mining With R":

hashtag
G) Shiny Web Apps & RMarkdown Documents

SHINY WEB APPS

R Package makes it incredibly easy to build interactive web applications with R.

Automatic "reactive" binding between inputs and outputs and extensive prebuilt widgets make it possible to build beautiful, responsive, and powerful applications with minimal effort.

For deploy Shiny Web Applications using Open Source Alternatives, you can either use:

RMARKDOWN DOCUMENTS

hashtag
H) Advanced R Resources

Some of the most advanced R resources for fully understanding the internals and nuances of the R Programming Language are the following:

This page is: Copyright © 2025 MariaDB. All rights reserved.

"odbc" R Package: DB RStudio odbc Usagearrow-up-right

For bug report to the RODBC package maintainer, use the following R statement: bug.report(package = "RODBC")

  • A vignette on how to use the RODBC package can be found here: RODBC CRAN Vignettearrow-up-right

  • Advanced R Second Edition (CRC R Series; Hadley Wickham)arrow-up-right
  • Mastering Spark with R (O'Reilly; Javier Luraschi, Kevin Kuo, Edgar Ruiz)arrow-up-right

  • R Packages (Hadley Wickham; O’Reilly)arrow-up-right

  • Information on new R packages is regularly published in the following websites:
    • R-bloggersarrow-up-right

    • Towards Data Sciencearrow-up-right

    • MRAN: Package Spotlightarrow-up-right

    Practical Machine Learning with H2O (O'Reilly Media; Darren Cook)arrow-up-right
  • Machine Learning with R and H2O (Mark Landry): Booklet Online Versionarrow-up-right

  • Deep Learning with H2O: Vignettearrow-up-right

  • CRANarrow-up-right
    RStudioarrow-up-right
    RCodearrow-up-right
    CRAN odbcarrow-up-right
    DB RStudio Driversarrow-up-right
    MariaDB ODBC Connectorarrow-up-right
    MySQL ODBC Connectorarrow-up-right
    CRAN RODBCarrow-up-right
    RStudio odbcarrow-up-right
    R Cookbook Second Edition (O’Reilly Media; Paul Teetor; James (JD) Long)arrow-up-right
    R Graphics Cookbook Second Edition (O’Reilly Media; Winston Chang)arrow-up-right
    R for Data Science (O’Reilly Media; Garrett Grolemund, Hadley Wickham)arrow-up-right
    Practical Statistics for Data Scientists (O’Reilly Media; Peter Bruce, Andrew Bruce)arrow-up-right
    RStudio Cheatsheets: Webpagearrow-up-right
    R Reference Card v2arrow-up-right
    RSeek: For searching any R related information (Based on Google).arrow-up-right
    RPackages: Search and stats for CRAN packages.arrow-up-right
    h2oarrow-up-right
    H2O.ai: Webpagearrow-up-right
    H2O.ai Algorithms: Cheatsheetarrow-up-right
    h2o R Package Functions: Cheatsheetarrow-up-right
    R package kerasarrow-up-right
    Python's 'Keras'arrow-up-right
    R interface to Keras: Webpagearrow-up-right
    Deep Learning With R (François Chollet with J. J. Allaire, Manning)arrow-up-right
    Keras Rstudio Cheatsheetarrow-up-right
    Introduction to Machine Learning with R (O'Reilly; Scott Burger)arrow-up-right
    Text Mining With R: A Tidy Approach (O’Reilly Media; Julia Silge and David Robinson): Book Online Versionarrow-up-right
    Shinyarrow-up-right
    Shiny Written Tutorialsarrow-up-right
    Shiny R Package Cheatsheetarrow-up-right
    RInno: CRAN Webpage (Windows)arrow-up-right
    ShinyProxy: Webpagearrow-up-right
    Shiny Server (Open Source Edition): Webpagearrow-up-right
    R Markdown: The Definitive Guide (Book).arrow-up-right
    R Markdown Cheatsheet.arrow-up-right
    Chapman & Hall/CRC The R Series: Subject-specific Booksarrow-up-right
    install.packages("odbc")
    install.packages("RMariaDB")
    library(RMariaDB)
    
    con <- dbConnect(
      drv = RMariaDB::MariaDB(), 
      username = NULL,
      password = NULL, 
      host = NULL, 
      port = 3306
    )
    install.packages("h2o")
    connection_url <- "jdbc:mariadb://172.16.2.178:3306/ingestSQL?&useSSL=false"
    username <- "root"
    password <- "abc123"
    
    # Whole Table:
    table <- "citibike20k"
    my_citibike_data <- h2o.import_sql_table(connection_url, table, username, password)
    
    # SELECT Query:
    select_query <-  "SELECT  bikeid  FROM citibike20k"
    my_citibike_data <- h2o.import_sql_select(connection_url, select_query, username, password)
    java -cp <path_to_h2o_jar>:<path_to_jdbc_driver_jar> water.H2OApp
    spinner