# Install pins
install.packages("pins")
# Load pins
library(pins)
Pin R Object to Posit Connect
In R, pins
is an open source package that allows you to publish and share R objects (data, models, etc.) across projects and with your colleagues. The process of pinning an R object is similar to using a push-pin to pin a piece of paper to a cork board:
Piece of paper: your R object
Cork board: where you want to pin your object
Push-Pin: the
pins
package
In this example, we’ll pin an R dataset to Posit Connect.
Install and load the pins
package
Set up Posit Connect as your board
To use Posit Connect as a board, you first need to authenticate. If you’re using the RStudio IDE, you can do this via Tools –> Global Options –> Publishing –> Connect
. Otherwise, you can manually set the Connect server
address and supply an API key
. Once Posit Connect has been authenticated, we can connect to it via the board_connect()
function and save the connection as my_board
. The output from this function in your environment should reflect your Connect server.
<- pins::board_connect()
my_board
# Connecting to Posit Connect [version number] at [Connect URL]
Pin R object to Posit Connect
For this example, our object with be the mtcars dataset:
# Assign mtcars datest to the "r_object" variable
<- mtcars r_object
And now we can pin the r_object to our Posit Connect server. We’ll name our pin “mtcars_dataset” and publish it as a csv file.
# Pin to Posit Connect
::pin_write(x = r_object,
pinsboard = my_board,
name = "mtcars_dataset",
type = "csv")
# Writing to pin 'ryan/mtcars_dataset'
And here is the pin on the Posit Connect:
Read Pin from Posit Connect
Now that our R object has been pinned, we can easily read the pin into another R project, or share the pin with a colleague. In the image above, Posit Connect shows you how to read the pin using R:
# Read the pin
::pin_read(board = my_board,
pinsname = "ryan/mtcars_dataset")