skiPatrol provides a native R interface to the
Snowflake ML platform. This vignette covers installation, connecting to
Snowflake, running queries, and using the DBI integration.
Install the development version from GitHub:
skiPatrol requires a Python environment with
snowflake-ml-python. The package includes a helper to set
this up:
Or create the environment manually:
If you have a ~/.snowflake/connections.toml file (the
Snowflake standard), skiPatrol reads it automatically:
In Workspace Notebooks, sfr_connect() automatically
detects the active session – no credentials needed:
# List tables
sfr_list_tables(conn)
# Check if a table exists
sfr_table_exists(conn, "MY_TABLE")
# Read a table into R
df <- sfr_read_table(conn, "MY_TABLE")
# Write a data.frame to Snowflake
sfr_write_table(conn, "NEW_TABLE", mtcars, overwrite = TRUE)
# Describe a table's columns
sfr_list_fields(conn, "MY_TABLE")For full DBI compliance (dbGetQuery,
dbWriteTable, dbListTables, etc.) and
dbplyr integration, use the companion skiLift
package. You can bridge from an sfr_connection to a DBI
connection with sfr_dbi_connection():
# Obtain an skiLift DBI connection (requires skiLift to be installed)
dbi_con <- sfr_dbi_connection(conn)
library(DBI)
DBI::dbGetQuery(dbi_con, "SELECT 1 AS x")
DBI::dbListTables(dbi_con)
DBI::dbExistsTable(dbi_con, "MY_TABLE")
DBI::dbReadTable(dbi_con, "MY_TABLE")
DBI::dbWriteTable(dbi_con, "NEW_TABLE", mtcars, overwrite = TRUE)This also enables dbplyr for dplyr-style data
manipulation:
library(dplyr)
library(dbplyr)
tbl(dbi_con, "MY_TABLE") |>
filter(status == "active") |>
group_by(category) |>
summarise(n = n(), avg_value = mean(value, na.rm = TRUE)) |>
collect()Alternatively, you can connect directly with skiLift without
skiPatrol:
vignette("model-registry") for logging and deploying R
models to Snowflake.vignette("feature-store") for managing features and
generating training data.