Code
install.packages("pins")For data transfer between local and cloud
Tony Duan
July 4, 2023
Package Pins for Upload and download data/model to online drive.

use local location as a board
or you can use one drive as as a board
upload two data to mtcars with version control
there will be two version
download version file from board
list file in the board
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/
---
title: "R Package: [Pins]"
subtitle: "For data transfer between local and cloud"
author: "Tony Duan"
date: "2023-07-04"
categories: [packages]
execute:
eval: false
warning: false
error: false
format:
html:
toc: true
code-fold: show
code-tools: true
number-sections: true
code-block-bg: true
code-block-border-left: "#31BAE9"
---
Package Pins for Upload and download data/model to online drive.

```{r}
#| eval: false
install.packages("pins")
```
```{r}
library(pins)
library(tidyverse)
```
## define a board
use local location as a board
```{r}
board=board_folder(getwd())
```
or you can use one drive as as a board
```{r}
od <- Microsoft365R::get_personal_onedrive()
board365 <- board_ms365(od, "myboard")
```
## upload to local board
```{r}
board %>% pin_write(head(mtcars), "mtcars")
```
## download from local board
```{r}
board %>% pin_read("mtcars")
```
## upload to one drive board
```{r}
board365 %>% pin_write(tail(mtcars), "mtcars")
```
## download from one drive board
```{r}
board365 %>% pin_read("mtcars")
```
## 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]])
```
list file in the board
```{r}
board %>% pin_list()
```
## upload file/download file to board
```{r}
board %>% pin_upload('thumbnail.jpg','new.thumbnail.jpg')
```
```{r}
board %>% pin_download('new.thumbnail.jpg')
```
## 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