From e48bd856754caa3835e2fe81123965e49ea57162 Mon Sep 17 00:00:00 2001
From: juliasilge Instead, we can also write a special function for reading, to
reconstruct the factor including its levels: Reading from the downloaded pin is straightforward;
A function to store factors
ten_letters <- factor(sample(letters, size = 10), levels = letters)
board %>% pin_write_factor_json(ten_letters, "letters-as-json")
-#> Creating new version '20231019T173317Z-1b599'
+#> Creating new version '20231103T164213Z-b9c79'
#> Writing to pin 'letters-as-json'
A function to read factors
@@ -170,7 +170,7 @@
A function to read factors
+#> [1] "r" "z" "t" "e" "d" "p" "y" "h" "l" "k"
@@ -181,7 +181,7 @@
A function to read factors}
board %>% pin_read_factor_json("letters-as-json")
-#> [1] w g b a o d f j c k
+#> [1] r z t e d p y h l k
#> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
Upload a single filearrow::write_feather(mtcars, path, compression = "uncompressed")
pin_upload(board, paths = path, name = pin_name)
-#> Creating new version '20231019T173321Z-be312'
pin_download()
returns a local path that can be piped to
arrow::read_feather()
:Function to manage uploadingpin_write():
pin_upload_arrow(board, x = mtcars, name = "mtcars-arrow2")
-#> Creating new version '20231019T173322Z-be312'
As before, you can pipe the result of pin_download()
to
your reader function:
diff --git a/dev/articles/pins-update.html b/dev/articles/pins-update.html index a3acf325..3a8c3aa5 100644 --- a/dev/articles/pins-update.html +++ b/dev/articles/pins-update.html @@ -148,7 +148,7 @@Examples pin_write(board, head(mtcars), "mtcars") #> Guessing `type = 'rds'` -#> Creating new version '20231019T173326Z-8df40' +#> Creating new version '20231103T164221Z-0a03e' #> Writing to pin 'mtcars' pin_read(board, "mtcars") #> mpg cyl disp hp drat wt qsec vs am gear carb @@ -187,7 +187,7 @@
Pinning filespin(path, "alphabet", board = "vignette") pin_get("alphabet", board = "vignette") -#> [1] "/tmp/Rtmph7Nfdk/file213a55420818/alphabet/file213a11b73ef1"
pins 1.0.0 clearly separates the two cases of pin an object and
pinning a file, so here instead of pin_write()
and
pin_read()
you need to pin_upload()
and
@@ -195,9 +195,9 @@
# Modern API
board %>% pin_upload(path, "alphabet")
-#> Creating new version '20231019T173328Z-ee580'
+#> Creating new version '20231103T164223Z-ee580'
board %>% pin_download("alphabet")
-#> [1] "~/.local/share/pins/alphabet/20231019T173328Z-ee580/file213a11b73ef1"
+#> [1] "~/.local/share/pins/alphabet/20231103T164223Z-ee580/file217b6a957e27"
This now needs to be made explicit with the new
board_url()
, and since this returns a path, not a file, you
need to use pin_download()
:
The first argument is the object to save (usually a data frame, but it can be any R object), and the second argument gives the “name” of the @@ -219,21 +219,21 @@
This shows you the metadata that’s generated by default. This includes:
While we’ll do our best to keep the automatically generated metadata
consistent over time, I’d recommend manually capturing anything you
really care about in metadata
.
You can list all the available versions with
pin_versions()
:
You can delete a specific older version with
pin_version_delete()
or sets of older versions with
pin_versions_prune()
.
board2 %>% pin_read("x")
-#> [1] 1 2 3 4 5
+#> [1] 3 4 5 6 7
But you can request an older version by supplying the
version
argument:
@@ -362,12 +362,12 @@Reading and writing filesNow I can upload those to the board:
+#> Creating new version '20231103T164229Z-e9d42'board %>% pin_upload(paths, "example") -#> Creating new version '20231019T173335Z-e9d42'
pin_download()
returns a vector of paths:
board %>% pin_download("example")
-#> [1] "/tmp/RtmpgNKgRg/pins-21867f5c2dab/example/20231019T173335Z-e9d42/mtcars.csv"
-#> [2] "/tmp/RtmpgNKgRg/pins-21867f5c2dab/example/20231019T173335Z-e9d42/alphabet.txt"
It’s now your job to handle them. You should treat these paths as internal implementation details — never modify them and never save them for use outside of pins.
@@ -382,7 +382,7 @@
board %>% pin_download("mtcars")
-#> [1] "/tmp/RtmpgNKgRg/pins-21867f5c2dab/mtcars/20231019T173332Z-66c17/mtcars.rds"
board %>% pin_write(mtcars, type = "json")
#> Using `name = 'mtcars'`
-#> Creating new version '20231019T173346Z-c2702'
+#> Creating new version '20231103T164240Z-c2702'
#> Writing to pin 'mtcars'
Let’s make a new version of this data by adding a column:
lper100km
, consumption in liters per 100 km. This could
@@ -161,7 +161,7 @@
Let’s check our board to ensure we have one pin named
"mtcars"
, with two versions:
Because a board_url()
is consumed over the web, it
doesn’t have access to a file system the way, for example, a
board_folder()
has; we can work around this by creating a
@@ -199,8 +199,8 @@
mtcars:
-- mtcars/20231019T173346Z-c2702/
-- mtcars/20231019T173348Z-8416c/
+- mtcars/20231103T164240Z-c2702/
+- mtcars/20231103T164242Z-8416c/
At this point, we would publish the folder containing the board as a
part of a web site. Let’s pretend that we have served the folder from
our fake website, https://not.real.website.co/pins/
.
We can read the most-recent version of the "mtcars"
pin:
diff --git a/dev/authors.html b/dev/authors.html index ea7f27c6..8fe2d6d1 100644 --- a/dev/authors.html +++ b/dev/authors.html @@ -96,13 +96,14 @@Citation
Silge J, Wickham H, Luraschi J (2023). pins: Pin, Discover and Share Resources. -https://pins.rstudio.com/, https://github.com/rstudio/pins-r. +R package version 1.2.2.9000, https://github.com/rstudio/pins-r, https://pins.rstudio.com/.
@Manual{, title = {pins: Pin, Discover and Share Resources}, author = {Julia Silge and Hadley Wickham and Javier Luraschi}, year = {2023}, - note = {https://pins.rstudio.com/, https://github.com/rstudio/pins-r}, + note = {R package version 1.2.2.9000, https://github.com/rstudio/pins-r}, + url = {https://pins.rstudio.com/}, }