Snippet Files

A Connection Snippet File is an R code snippet with additional metadata which is intended to initialize a connection. This file can be as simple as:

data <- read_csv(readr_example("mtcars.csv"))

Once this file is saved under /etc/rstudio/connections/ as Motor Trend Cars.R, RStudio will make this connection as available under the Connection Pane.

The path is configurable through the connections-path environment variable and multiple connection files can be specified.

In order to parameterize this connection, one can create fields using using the ${Position:Label=Default} syntax:

  • Position: The row position starting at zero.
  • Label: The label assigned to this field.
  • Default: An optional default value.

For example, we can filter out this dataframe to produce the following connection interface:

data <- read_csv(readr_example("mtcars.csv"))
data[data$mpg == ${0:Miles per Gallon=21.4} | data$cyl == ${1:Cylinders=6}, ]

In order to create a ; separated list of values, one can use the syntax ${Position:Label=Default:Key}. Semicolon-separated list are common in database connections and therefore, natively supported in snippet files, for instance:


There are a couple of escape characters supported: $colon$ to escape : and $equal to escape =.

Additional resources are available under RStudio Extensions - Connections.