Installation

To install package from CRAN-like repository:

repos <- c("https://mokymai.github.io/download/", getOption("repos"))
install.packages("snippets", repos = repos)

To install from GitHub:

# install.packages("remotes")
remotes::install_github("GegznaV/snippets")

Quickstart

Install Snippets from “snippets”

# Replace current files with snippets with those in package "snippets"
# (backup copies are created by default)
snippets::install_snippets_from_package("snippets")

More Examples

# Get the name of the directory where RStudio snippets are stored
get_path_rstudio_snippets_dir()
# Open the directory with RStudio snippets
open_rstudio_snippets_dir()
# Replace your R and Markdown snippets with those in package "snippets"
install_snippets_from_package("snippets", type = c("r", "markdown"), backup = TRUE)
list_snippet_file_backups()
# View and edit file with snippets of certain type: r
open_rstudio_snippets_file(type = "r")
# View and edit file with snippets of certain type: markdown
open_rstudio_snippets_file(type = "markdown")

Create and Clean-up Back-ups

# Create several back up files
backup_rstudio_snippets(type = "r")
Sys.sleep(1)
backup_rstudio_snippets(type = "r")
Sys.sleep(1)
backup_rstudio_snippets(type = "r")
# Remove duplicated back-up files
remove_snippet_backup_duplicates()

Additional resources

More on using and writing RStudio snippets

  1. Code Snippets (on RStudio website). All information is relevant to RStudio users.
  2. R tip: Save time with RStudio code snippets (Case study on YouTube).
  3. Snippets (on Cloud9 SDK website). Advanced topics on writing snippets. Most sections (but not all) are relevant to RStudio users.

Similar projects

  1. Package snippr.

More snippets

  1. Snippets by @dgrtwo.
  2. Snippets by @gadenbuie.