Code
::pkg_install("pins") pak
Tony D
March 15, 2025
A guide to using the pins
package in R for data transfer and version control between local and online storage.
This document provides a comprehensive guide to using the pins
package in R for efficient data transfer and version control. It demonstrates how to set up and use both local and online boards (with OneDrive as an example) to store and retrieve data and other files. The guide covers essential pins
functions for uploading, downloading, listing, and managing different versions of your data, making it a valuable resource for creating reproducible and collaborative data science workflows.
The pins
package is used for uploading and downloading data/models to online drives.
upload two data to mtcars with version control
RStudio’s {pins} package: what it is, how it works, and what it can do for you! || RStudio https://www.youtube.com/watch?v=3Yk6U_XqxNo
Javier Luraschi | Datasets in Reproducible Research with ‘pins’ | RStudio (2020) https://www.youtube.com/watch?v=xwItECnphRU
pins doc: https://pins.rstudio.com/
Ep 5: Keeping data up-to-date with 6 pins workflows | Posit Team: https://www.youtube.com/watch?v=t8A-ysXinpE
---
title: "使用R pin数据传输"
subtitle: "For data transfer between local and cloud"
author: "Tony D"
date: "2025-03-15"
categories:
- Tool
- R
execute:
warning: false
error: false
eval: false
---
A guide to using the `pins` package in R for data transfer and version control between local and online storage.
This document provides a comprehensive guide to using the `pins` package in R for efficient data transfer and version control. It demonstrates how to set up and use both local and online boards (with OneDrive as an example) to store and retrieve data and other files. The guide covers essential `pins` functions for uploading, downloading, listing, and managing different versions of your data, making it a valuable resource for creating reproducible and collaborative data science workflows.
The `pins` package is used for uploading and downloading data/models to online drives.

```{r}
#| eval: false
pak::pkg_install("pins")
```
```{r}
library(pins)
library(tidyverse)
```
# local board
## use local location as a board
```{r}
board=board_folder(getwd())
```
```{r}
board %>% pin_list()
```
## upload to local board
```{r}
board %>% pin_write(head(mtcars), "mtcars")
```
## download from local board
```{r}
a=board %>% pin_read("mtcars")
a
```
## upload file to board
```{r}
board %>% pin_upload('thumbnail.jpg','new.thumbnail.jpg')
```
## list file in the board
```{r}
board %>% pin_list()
```
## download file from board
```{r}
board %>% pin_download('new.thumbnail.jpg')
```
# online one drive board
## one drive as as a board
```{r}
od <- Microsoft365R::get_personal_onedrive()
board365 <- board_ms365(od, "myboard")
```
## upload to one drive board
```{r}
board365 %>% pin_write(tail(mtcars), "mtcars")
```
## download from one drive board
```{r}
board365 %>% pin_read("mtcars")
```
## list file in the board
```{r}
board %>% pin_list()
```
# using version
upload two data to mtcars with version control
```{r}
board %>% pin_write(tail(mtcars), "mtcars_version",versioned = TRUE)
board %>% pin_write(head(mtcars), "mtcars_version",versioned = TRUE)
```
## there will be two version
```{r}
board %>% pin_versions("mtcars_version")
```
## download version file from board
```{r}
# board %>% pin_read("mtcars_version",version = '20230704T095208Z-8df40')
board %>% pin_read("mtcars_version",version = .Last.value$version[[1]])
```
# Reference
RStudio's {pins} package: what it is, how it works, and what it can do for you! \|\| RStudio https://www.youtube.com/watch?v=3Yk6U_XqxNo
Javier Luraschi \| Datasets in Reproducible Research with 'pins' \| RStudio (2020) https://www.youtube.com/watch?v=xwItECnphRU
pins doc:
https://pins.rstudio.com/
Ep 5: Keeping data up-to-date with 6 pins workflows | Posit Team:
https://www.youtube.com/watch?v=t8A-ysXinpE