A professional collection of VSCode snippets for R and R Markdown, designed to accelerate your data science workflow. Supports the latest R 4.5.0 features and works with VS Code, Positron, and other modern R IDEs.
Pro Tip: These snippets also work in the new RStudio Codium-based IDE, Positron.
- In VS Code, go to
Code -> Preferences -> User Snippets
- Select
r.json
(for R snippets) ormarkdown.json
(for R Markdown) - Copy and paste the snippets from
snippets.json
in this repository
This collection includes 100+ powerful snippets covering the entire data science workflow:
- Modern tidyverse operations (
|>
pipe operator) - High-performance data.table operations
- Database connections (MySQL, PostgreSQL, SQLite)
- Spatial data handling with sf
- Complete ggplot2 templates with themes and facets
- Publication-quality plot themes
- Interactive visualization with plotly
- Customizable chart parameters
- Comprehensive modeling (linear, GLM, mixed effects)
- ANOVA, t-tests, and non-parametric tests
- Modern machine learning workflows with tidymodels
- Cross-validation and model evaluation
- Random forest, gradient boosting, and neural networks
- Cross-validation templates with tidymodels
- Time series forecasting with Prophet
- Text mining with tidytext
- R Markdown report templates
- Shiny application scaffolding
- Parallel processing setup
- Automated EDA templates
# Type "tidyverse: pipe chain" for:
data |>
filter(condition) |>
mutate(new_var = transformation) |>
group_by(group_var) |>
summarize(summary_stats) |>
arrange(arrangement)
# Type "ggplot: scatter with regression" for:
ggplot(data, aes(x = x, y = y)) +
geom_point(aes(color = group), alpha = 0.7) +
geom_smooth(method = "lm", se = TRUE) +
theme_minimal() +
labs(title = "Scatterplot with Linear Regression", x = "X Label", y = "Y Label")
# Type "cross validation" for a complete modeling workflow
The collection includes snippets for:
- Data Wrangling: filter, select, mutate, arrange, join, pivot, etc.
- Visualization: All ggplot geoms, themes, facets, and customizations
- Statistical Tests: t-tests, ANOVA, chi-square, normality tests
- Modeling: Linear models, GLM, mixed effects, machine learning
- Advanced Analytics: Time series, text mining, spatial data
- Functional Programming: map, walk, reduce, purrr operations
- Reporting: R Markdown templates, Shiny app structures
- Performance: Parallel processing, data.table operations
See snippets.json for the complete list.
Contributions are welcome! Please fork the repository and submit a pull request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-snippet
) - Commit your changes (
git commit -am 'Add some amazing snippet'
) - Push to the branch (
git push origin feature/amazing-snippet
) - Open a Pull Request
- R 4.0+ (optimized for R 4.3+)
- VS Code with R extension or similar IDE
- Recommended packages: tidyverse, data.table, ggplot2, tidymodels
This project is licensed under the Beerware License - see the LICENSE file for details. If you find these snippets useful, consider buying me a beer if we ever meet!
- The R Core Team for their amazing language
- The tidyverse team for revolutionizing data science in R
- The VS Code team for an excellent IDE
- All contributors to this project
Last updated: April 29, 2025