Skip to content
Back to skills

R Data Database

ASecurity

R database packages for SQL and NoSQL. Use for DBI connections, SQL queries, dbplyr, SQLite, PostgreSQL, MySQL, MongoDB, Redis.

  • 5 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added June 4, 2026
datagosqldatabase

Works with

  • cli

Security analysis

A100/100

Pro scans all 8 files and shows the line behind each finding

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill r-data-database --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of R Data Database?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for R Data Database
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-r-data-database/badge)](https://www.skillsdirectory.com/skills/leolin990405-r-data-database)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: r-data-database
description: R database packages for SQL and NoSQL. Use for DBI connections, SQL queries, dbplyr, SQLite, PostgreSQL, MySQL, MongoDB, Redis.
---

# R Database Connections

SQL and NoSQL database access from R.

## DBI (Common Interface)

```r
library(DBI)

# Connect
con <- dbConnect(RSQLite::SQLite(), "database.db")
con <- dbConnect(RPostgres::Postgres(),
  host = "localhost", dbname = "mydb",
  user = "user", password = "pass"
)

# Query
result <- dbGetQuery(con, "SELECT * FROM table WHERE x > 10")

# Execute (no return)
dbExecute(con, "INSERT INTO table VALUES (1, 'a')")
dbExecute(con, "UPDATE table SET x = 10 WHERE id = 1")

# Parameterized queries (safe)
dbGetQuery(con, "SELECT * FROM table WHERE id = ?", params = list(123))

# Tables
dbListTables(con)
dbExistsTable(con, "mytable")
dbWriteTable(con, "newtable", df)
dbReadTable(con, "mytable")
dbRemoveTable(con, "mytable")

# Disconnect
dbDisconnect(con)
```

## dbplyr (dplyr for databases)

```r
library(dplyr)
library(dbplyr)

con <- dbConnect(RSQLite::SQLite(), "database.db")

# Lazy table reference
tbl_db <- tbl(con, "mytable")

# dplyr operations (translated to SQL)
result <- tbl_db %>%
  filter(x > 10) %>%
  select(a, b, c) %>%
  group_by(category) %>%
  summarise(mean = mean(value)) %>%
  collect()  # Execute and bring to R

# View SQL
tbl_db %>% filter(x > 10) %>% show_query()

# Copy local data to database
copy_to(con, df, "temp_table", temporary = TRUE)
```

## SQLite

```r
library(RSQLite)
con <- dbConnect(SQLite(), "mydb.sqlite")

# In-memory database
con <- dbConnect(SQLite(), ":memory:")

dbWriteTable(con, "mtcars", mtcars)
dbGetQuery(con, "SELECT * FROM mtcars WHERE mpg > 20")
dbDisconnect(con)
```

## PostgreSQL

```r
library(RPostgres)
con <- dbConnect(Postgres(),
  host = "localhost",
  port = 5432,
  dbname = "mydb",
  user = "user",
  password = "password"
)

# With connection string
con <- dbConnect(Postgres(),
  "postgresql://user:pass@host:5432/dbname"
)
```

## MySQL/MariaDB

```r
library(RMariaDB)
con <- dbConnect(MariaDB(),
  host = "localhost",
  dbname = "mydb",
  user = "user",
  password = "password"
)
```

## ODBC (Universal)

```r
library(odbc)

# List drivers
odbcListDrivers()

# Connect
con <- dbConnect(odbc(),
  Driver = "SQL Server",
  Server = "server_name",
  Database = "db_name",
  UID = "user",
  PWD = "password"
)

# DSN connection
con <- dbConnect(odbc(), dsn = "my_dsn")
```

## MongoDB

```r
library(mongolite)

# Connect
mongo <- mongo(
  collection = "mycollection",
  db = "mydb",
  url = "mongodb://localhost:27017"
)

# Query
data <- mongo$find('{"x": {"$gt": 10}}')
data <- mongo$find(limit = 100)

# Insert
mongo$insert(df)

# Update
mongo$update('{"id": 1}', '{"$set": {"x": 100}}')

# Aggregate
mongo$aggregate('[
  {"$match": {"x": {"$gt": 10}}},
  {"$group": {"_id": "$category", "count": {"$sum": 1}}}
]')
```

## Redis

```r
library(redux)

r <- redux::hiredis()

# Key-value
r$SET("key", "value")
r$GET("key")

# Hash
r$HSET("hash", "field", "value")
r$HGET("hash", "field")

# List
r$LPUSH("list", "item")
r$LRANGE("list", 0, -1)
```

## Connection Pooling

```r
library(pool)

pool <- dbPool(
  drv = RPostgres::Postgres(),
  dbname = "mydb",
  host = "localhost",
  user = "user",
  password = "password",
  minSize = 1,
  maxSize = 5
)

# Use pool like connection
dbGetQuery(pool, "SELECT * FROM table")

# Close pool
poolClose(pool)
```

Files in this skill

  • DBI/SKILL.md2.6 KB
  • RPostgres/SKILL.md1.2 KB
  • RSQLite/SKILL.md1.1 KB
  • SKILL.md3.3 KB
  • dbplyr/SKILL.md1.3 KB
  • elastic/SKILL.md3.2 KB
  • mongolite/SKILL.md2.9 KB
  • odbc/SKILL.md1.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.