rstudio / pins-r

Pin, discover, and share resources
https://pins.rstudio.com
Other
312 stars 63 forks source link

Add `tags` to metadata #677

Closed juliasilge closed 1 year ago

juliasilge commented 1 year ago

Closes #570

This PR adds a tags field to pin metadata. It is used like this:

library(pins)
b <- board_rsconnect()
#> Connecting to RSC 2022.09.0 at <https://colorado.rstudio.com/rsc>
b %>% pin_write(
  1:10, 
  "julia.silge/great-numbers", 
  tags = c("i-love-integers", "numbers-are-fun")
)
#> Guessing `type = 'rds'`
#> Writing to pin 'julia.silge/great-numbers'

Created on 2022-11-16 with reprex v2.0.2

You can see how this is stored on Connect here (click "Raw metadata" to see the tags stored in YAML).

This adds a new argument in pin_write() between description and metadata, which could cause problems for any folks who have used metadata by position only. It does not fail silently, though:

library(pins)
b <- board_temp()
b %>% pin_write(1:10, "great-numbers", "json", "My beautiful numbers", "Some numbers for you to enjoy", list(a = "a"))
#> Error in `check_tags()` at pins-r/R/pin-read-write.R:88:2:
#> ! `tags` must be a character vector

#> Backtrace:
#>     ▆
#>  1. ├─b %>% ...
#>  2. └─pins::pin_write(...)
#>  3.   └─pins:::check_tags(tags) at pins-r/R/pin-read-write.R:88:2
#>  4.     └─rlang::abort("`tags` must be a character vector") at pins-r/R/pin-read-write.R:256:4

Created on 2022-11-16 with reprex v2.0.2

I think the number of folks who have used metadata like this (by position) must be very small, though, because there are so many arguments before it. Is this a breaking change? Probably?

For future extensions, on Connect we could try to store these tags as Connect tags. Publishers cannot create tags, so the plan would be to check if the tag exists and then add it to the pin.

juliasilge commented 1 year ago

This change is backwards compatible for reading pins that were stored without tags:

library(pins)
b <- board_rsconnect()
#> Connecting to RSC 2022.09.0 at <https://colorado.rstudio.com/rsc>
b %>% pin_meta("julia.silge/wow-another-mtcars-model")
#> List of 11
#>  $ file       : chr "wow-another-mtcars-model.rds"
#>  $ file_size  : 'fs_bytes' int 5.07K
#>  $ pin_hash   : chr "ebc45bb5da89fbcc"
#>  $ type       : chr "rds"
#>  $ title      : chr "wow-another-mtcars-model: a pinned list"
#>  $ description: chr "An OLS linear regression model"
#>  $ created    : POSIXct[1:1], format: "2022-10-07 14:45:38"
#>  $ api_version: num 1
#>  $ user       : list()
#>  $ name       : chr "julia.silge/wow-another-mtcars-model"
#>  $ local      :List of 4
#>   ..$ dir       : 'fs_path' chr "~/Library/Caches/pins/rsc-e62371cfd77db754024f9c5ed3556a73/3ff71b31-f257-480a-a87b-fc6dc9a7e4dc/63410"
#>   ..$ url       : chr "https://colorado.rstudio.com/rsc/content/3ff71b31-f257-480a-a87b-fc6dc9a7e4dc/_rev63410/"
#>   ..$ version   : chr "63410"
#>   ..$ content_id: chr "3ff71b31-f257-480a-a87b-fc6dc9a7e4dc"

Created on 2022-11-16 with reprex v2.0.2

juliasilge commented 1 year ago

@machow do you mind taking a look, with an eye to a) whether this change would be a problem for pins for Python as it exists today and b) whether you think this approach would work for Python (later, when adding it may be appropriate)?

juliasilge commented 1 year ago

I think you are right @machow that we should just put this at the end. I still kept it before the dots ... which means it could possibly still be a breaking change for folks who have used all existing args by position only (not by name) and then passed something through the dots; I think this must be very rare since there are so many arguments ahead of the dots.

github-actions[bot] commented 1 year ago

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.