SlideShare une entreprise Scribd logo
1  sur  11
Télécharger pour lire hors ligne
1RDBL – The open source R package for database access
RDBL
The R database layer package
For information, please contact us:
http://functionalfinances.com
info@functionalfinances.com
2RDBL – The open source R package for database access
Overview
 RDBL is an open source package
 An abstraction layer for R developers to interact with databases
 No prior SQL knowledge required
 data.frame based syntax
 Lazy load – load the data only when absolutely necessary
 Maps tables to db.model analogue to a data.frame
Package description
3RDBL – The open source R package for database access
Main functionalities
 Supports Oracle, MySql, SQLite, PostgreSQL, MS Access
 Loading data from database with column and row filtering
 as.data.frame performs loading data
 merge to create SQL joins
 logical indexing-like syntax for WHERE clauses
 aggregate for GROUP BY queries
 derived columns
What we have done already
4RDBL – The open source R package for database access
Planned functionalities
 INSERT INTO statements
 Additional analytical queries (full range of standard SQL functionalities)
 UPDATE statements
 Optimizing generated SQL queries
What we are working on
5RDBL – The open source R package for database access
Premium services
 RDBL is an open source package available for free
 Missing features you need can be ordered for a fee
 We provide on-site trainings
 We offer 24/7 support if required
What we can do for you
6RDBL – The open source R package for database access
Detailed functionalities
library(RMySQL)
# Create a MySQL connection using DBI
# Database layout:
# Chinook database
db.connection <- dbConnect(MySQL(), dbname = "test")
# Set as the connection used
SetConnection(db.connection)
# Create several database models
artist.db <- db.model("Artist")
album.db <- db.model("Album")
# Load data
artists <- as.data.frame(artist.db)
albums <- as.data.frame(albums)
Creating and loading a db.model
7RDBL – The open source R package for database access
Detailed functionalities
# Create the artist and album models
artist.db <- db.model("Artist")
album.db <- db.model("Album")
names(artist.db)
# [1] "ArtistId" "Name"
names(album.db)
# [1] "AlbumId" "Title" "ArtistId"
# Join tables together
# all.x = TRUE means LEFT JOIN
albums.of.artists.db <-
merge(artist.db,
album.db,
by = "ArtistId", # by.x ="ArtistId", by.y = "ArtistId"
all.x = TRUE)
# Load data
albums.of.artists <- as.data.frame(albums.of.artists.db)
Merging db.models
8RDBL – The open source R package for database access
Detailed functionalities
# Column filtering
aoa.db <-
albums.of.artists.db[, c("Name",
"Title")]
# Row filtering
aoa.db <-
aoa.db[aoa.db$Name == "ACDC" &
aoa.db$Title == "Thunderstruck", ]
# Load data
thunder <- as.data.frame(aoa.db)
Filtering
9RDBL – The open source R package for database access
Detailed functionalities
# rename columns with the same name
rename(genre.db, "Name", "GenreName")
rename(artist.db, "Name", "ArtistName")
# join tables together
# artist x album x track x genre to get the
# mapping between artists and genre
artist.genre.db <-
merge(merge(merge(artist.db, album.db,
by = "ArtistId")[,c("ArtistName",
"AlbumId")],
track.db,
by = "AlbumId")[, c("ArtistName",
"GenreId")],
genre.db,
by = "GenreId")[, c("ArtistName",
"GenreName")]
Merge – complex example
10RDBL – The open source R package for database access
Detailed functionalities
# which group has the most rock songs?
rocks <- artist.genre.db[artist.genre.db$GenreName == "Rock", ]
most.rock.db <-
aggregate(rocks,
list(SongCount = count(rocks$GenreName)),
by = "ArtistName")
most.rock.db <-
most.rock.db[order.db(most.rock.db$SongCount,
decreasing = TRUE)]
rock.band <- as.data.frame(most.rock.db)[1, "ArtistName"]
Aggregation
11RDBL – The open source R package for database access
Detailed functionalities
# which group has the most rock songs?
rocks <- artist.genre.db[artist.genre.db$GenreName == "Rock", ]
most.rock.db <-
aggregate(rocks,
list(SongCount = count(rocks$GenreName)),
by = "ArtistName")
most.rock.db$SongCount2 <-
most.rock.db$SongCount * 2
most.rock.db$SongCount3 <-
most.rock.db$SongCount + most.rock.db$SongCount2
# Load data
most.rock <- as.data.frame(most.rock.db)
Derived columns

Contenu connexe

Dernier

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 

Dernier (20)

Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

RDBL - The open source R package for database interaction

  • 1. 1RDBL – The open source R package for database access RDBL The R database layer package For information, please contact us: http://functionalfinances.com info@functionalfinances.com
  • 2. 2RDBL – The open source R package for database access Overview  RDBL is an open source package  An abstraction layer for R developers to interact with databases  No prior SQL knowledge required  data.frame based syntax  Lazy load – load the data only when absolutely necessary  Maps tables to db.model analogue to a data.frame Package description
  • 3. 3RDBL – The open source R package for database access Main functionalities  Supports Oracle, MySql, SQLite, PostgreSQL, MS Access  Loading data from database with column and row filtering  as.data.frame performs loading data  merge to create SQL joins  logical indexing-like syntax for WHERE clauses  aggregate for GROUP BY queries  derived columns What we have done already
  • 4. 4RDBL – The open source R package for database access Planned functionalities  INSERT INTO statements  Additional analytical queries (full range of standard SQL functionalities)  UPDATE statements  Optimizing generated SQL queries What we are working on
  • 5. 5RDBL – The open source R package for database access Premium services  RDBL is an open source package available for free  Missing features you need can be ordered for a fee  We provide on-site trainings  We offer 24/7 support if required What we can do for you
  • 6. 6RDBL – The open source R package for database access Detailed functionalities library(RMySQL) # Create a MySQL connection using DBI # Database layout: # Chinook database db.connection <- dbConnect(MySQL(), dbname = "test") # Set as the connection used SetConnection(db.connection) # Create several database models artist.db <- db.model("Artist") album.db <- db.model("Album") # Load data artists <- as.data.frame(artist.db) albums <- as.data.frame(albums) Creating and loading a db.model
  • 7. 7RDBL – The open source R package for database access Detailed functionalities # Create the artist and album models artist.db <- db.model("Artist") album.db <- db.model("Album") names(artist.db) # [1] "ArtistId" "Name" names(album.db) # [1] "AlbumId" "Title" "ArtistId" # Join tables together # all.x = TRUE means LEFT JOIN albums.of.artists.db <- merge(artist.db, album.db, by = "ArtistId", # by.x ="ArtistId", by.y = "ArtistId" all.x = TRUE) # Load data albums.of.artists <- as.data.frame(albums.of.artists.db) Merging db.models
  • 8. 8RDBL – The open source R package for database access Detailed functionalities # Column filtering aoa.db <- albums.of.artists.db[, c("Name", "Title")] # Row filtering aoa.db <- aoa.db[aoa.db$Name == "ACDC" & aoa.db$Title == "Thunderstruck", ] # Load data thunder <- as.data.frame(aoa.db) Filtering
  • 9. 9RDBL – The open source R package for database access Detailed functionalities # rename columns with the same name rename(genre.db, "Name", "GenreName") rename(artist.db, "Name", "ArtistName") # join tables together # artist x album x track x genre to get the # mapping between artists and genre artist.genre.db <- merge(merge(merge(artist.db, album.db, by = "ArtistId")[,c("ArtistName", "AlbumId")], track.db, by = "AlbumId")[, c("ArtistName", "GenreId")], genre.db, by = "GenreId")[, c("ArtistName", "GenreName")] Merge – complex example
  • 10. 10RDBL – The open source R package for database access Detailed functionalities # which group has the most rock songs? rocks <- artist.genre.db[artist.genre.db$GenreName == "Rock", ] most.rock.db <- aggregate(rocks, list(SongCount = count(rocks$GenreName)), by = "ArtistName") most.rock.db <- most.rock.db[order.db(most.rock.db$SongCount, decreasing = TRUE)] rock.band <- as.data.frame(most.rock.db)[1, "ArtistName"] Aggregation
  • 11. 11RDBL – The open source R package for database access Detailed functionalities # which group has the most rock songs? rocks <- artist.genre.db[artist.genre.db$GenreName == "Rock", ] most.rock.db <- aggregate(rocks, list(SongCount = count(rocks$GenreName)), by = "ArtistName") most.rock.db$SongCount2 <- most.rock.db$SongCount * 2 most.rock.db$SongCount3 <- most.rock.db$SongCount + most.rock.db$SongCount2 # Load data most.rock <- as.data.frame(most.rock.db) Derived columns