pins for R

repository·main·Indexed 43 days ago

https://github.com/rstudio/pins-r

An R package for publishing and sharing data, models, and other R objects across projects and colleagues. It uses 'boards' as an abstraction for storage backends, including local folders, Posit Connect, Amazon S3, Google Cloud Storage, Azure blob storage, and Databricks Volumes.

Tokens
740
Snippets
5
Records
5
Agent score
6%

What's inside pins

  1. How pins and boards work together

    main

    The pins package allows you to publish data, models, and other R objects to shared locations called boards.

    A board is an abstraction representing a storage backend (e.g., a local folder, Posit Connect, Amazon S3, Google Cloud Storage, etc.). Once a board is initialized, you use it to write (pin) or read objects.

    Key workflow:

    1. Create a board: Initialize a board object using functions like board_folder() or board_connect().
    2. Pin an object: Use pin_write() to save an object to the board with a specific name.
    3. Read an object: Use pin_read() to retrieve the object from the board using its name.
    library(pins)
    
    # 1. Create a board
    board <- board_temp()
    
    # 2. Pin an object
    board |> pin_write(head(mtcars), "mtcars")
    
    # 3. Read the object
    board |> pin_read("mtcars")
  2. Install the pins package

    main

    You can install the stable version of pins from CRAN or the development version from GitHub.

    To install from CRAN:

    install.packages("pins")

    To install the development version using pak:

    # install.packages("pak")
    pak::pak("rstudio/pins-r")
    install.packages("pins")
  3. Pin an object with pin_write()

    main

    Use pin_write() to save an object to a board. It requires the board object, the object itself, and a name for the pin.

    By default, pins may choose a file format like parquet. You can explicitly specify the storage format using the type argument (e.g., "rds", "arrow", "csv", or "json").

    board |> pin_write(head(mtcars), "mtcars")
    
    # Specifying a type
    board |> pin_write(tidy_sales_data, "sales-summary", type = "rds")
  4. Initialize different types of pin boards

    main

    Pins supports various storage backends through different board initialization functions:

    • Local/Temporary:
      • board_temp(): Creates a temporary board that is automatically deleted when the R session ends. Useful for testing.
      • board_folder(): Stores pins in a specified directory (e.g., a networked drive or Dropbox).
    • Cloud & Enterprise:
      • board_connect(): Connects to Posit Connect.
      • board_databricks(): Uses Databricks Volumes.
      • board_s3(): Uses Amazon S3.
      • board_azure(): Uses Azure blob storage.
      • board_gcs(): Uses Google Cloud Storage.

    Refer to vignette("pins") for detailed documentation on cloud boards.

    board <- board_temp()
    board <- board_folder("path/to/folder")
    board <- board_connect()
    board <- board_s3(bucket = "my-bucket")