Warning
Beta version. Report issues on GitHub.
Note
Positron IDE Only - Requires Positron. Will not work in VS Code.
SQL syntax highlighting and intelligent autocomplete for DuckDB in R files.
Write DuckDB SQL with full IDE support right inside R strings. Take full advantage of expressive SQL expressions within your R scripts!
- 🎨 SQL Syntax Highlighting - Context-aware highlighting in R strings
- 🧠 Smart Autocomplete - 900+ DuckDB functions + live schema from R session
- 🔌 R Connection Picker - Select specific connection objects (supports
:memory:) - 🔄 Auto-Refresh - Detects schema changes automatically
- 🌈 Visual Distinction - Themed background colors for SQL strings
- ✨ SQL Auto-Format - Format SQL with glue interpolation support
✈️ Air Formatter Support - Works with multi-line SQL
Download Release (Recommended)
- Download
.vsixfrom Releases - Positron: Extensions → ... → Install from VSIX
Or Build from Source
git clone https://github.com/belian-earth/duckdb-r-editor.git
cd duckdb-r-editor
npm installWith Make (Linux/Mac/WSL - recommended):
make # Build and package
make quick # Quick build (skip linting)
make help # See all commandsWithout Make (universal):
npm run compile # Compile TypeScript
npm run lint # Run linter
npm run vsce:package # Create .vsix fileThe .vsix file will be created in the project root. Install it via Positron: Extensions → ... → Install from VSIX
Note: Windows users can install Make via Chocolatey (choco install make) or use WSL
library(DBI)
library(duckdb)
con <- dbConnect(duckdb(), "mydata.duckdb")
# Or in-memory: dbConnect(duckdb(), ":memory:")- Command Palette (
Cmd/Ctrl + Shift + P) - "DuckDB R Editor: Connect to DuckDB Database"
- Select your R connection (e.g., "con")
- Write SQL with autocomplete!
Autocomplete works in:
dbGetQuery(con, "SELECT * FROM ...")
dbExecute(con, "CREATE TABLE ...")
sql("SELECT ...") # dbplyr
glue_sql("...", .con = con) # glue
read_sql_duckdb("SELECT ...") # duckplyr
db_exec("SET threads TO 2") # duckplyrTip
Completions appear as you type. Use Ctrl+Space (Cmd+Space on Mac) to manually trigger suggestions at any position inside a SQL string.
Optional settings (.vscode/settings.json):
{
"duckdb-r-editor.enableAutoComplete": true,
"duckdb-r-editor.enableSQLHighlighting": true,
"duckdb-r-editor.enableSQLBackgroundColor": true,
"duckdb-r-editor.autoRefreshSchema": true,
"duckdb-r-editor.sqlFormattingStyle": "standard",
"duckdb-r-editor.sqlKeywordCase": "upper"
}Available Settings:
enableAutoComplete- Enable autocomplete (default: true)enableSQLHighlighting- SQL keyword/function highlighting in R strings (default: true)enableSQLBackgroundColor- Background color for SQL strings (default: true)autoRefreshSchema- Auto-detect schema changes (default: true)sqlFormattingStyle- Format style:standard,tabularLeft,tabularRight(default: standard)sqlKeywordCase- Keyword case:preserve,upper,lower(default: preserve)
Access via Command Palette (Cmd/Ctrl + Shift + P):
- Connect to DuckDB Database - Select R connection for schema
- Disconnect from Database - Clear connection
- Refresh DuckDB Schema - Manually update schema
- Format SQL in R String - Format SQL at cursor (preserves glue interpolations)
- Debug SQL Detection at Cursor - Diagnose autocomplete issues at cursor position (logs to Output panel)
Load DuckDB extensions in your R session — the extension picks up new functions automatically via auto-refresh:
dbExecute(con, "INSTALL spatial; LOAD spatial;")
# -> Functions automatically available for autocompleteSchema and functions refresh automatically when:
- Creating/dropping tables:
CREATE TABLE,DROP TABLE - Modifying data:
INSERT,UPDATE,DELETE - Loading extensions:
INSTALL,LOAD
Notifications show what changed:
✓ 2 new tables added to 'con' (Total: 5 tables)
✓ 45 new functions loaded in 'con' (Total: 945 functions)
* Disable in settings: "autoRefreshSchema": false
Writing SQL in R strings without IDE support means:
- Guessing table/column names
- No syntax validation until runtime
- Constant context switching to check schema
This extension provides:
- ✅ Real-time autocomplete from your active R session
- ✅ Syntax highlighting and validation
- ✅ Seamless workflow - stay in your code
- DuckDB - Analytical database
- Positron - Data science IDE
- Air formatter - R code formatting
- R packages:
DBI,duckdb,dbplyr,duckplyr,glue
Contributions welcome! See DEVELOPMENT.md for build instructions and development workflow.
To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes and test thoroughly
- Ensure code passes linting:
make buildornpm run lint - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Open an issue on GitHub for bug reports or feature requests.
