55
66<!-- badges: start -->
77
8- [ ![ R-CMD-check] ( https://github.com/torfason/gitpins/workflows/R-CMD-check/badge.svg )] ( https://github.com/torfason/gitpins/actions )
98[ ![ R-CMD-check] ( https://github.com/torfason/gitpins/actions/workflows/R-CMD-check.yaml/badge.svg )] ( https://github.com/torfason/gitpins/actions/workflows/R-CMD-check.yaml )
109<!-- badges: end -->
1110
@@ -14,7 +13,7 @@ are versioned using a local git repository, and if getting a document
1413from the web is not successful, a previous local download is made
1514available.
1615
17- ## The problem
16+ ## The Problem
1817
1918You want to quickly and easily process an online resource using R
2019functions, some of which only accept local files. Thus you would like
@@ -28,13 +27,23 @@ the following properties for your workflow:
2827- Not ruin your local copy if the online version should change in a
2928 “bad” way
3029
31- ## The solution
30+ ## The Solution
3231
3332The ` gitpins ` package downloads a URL to a local file in the ` gitpins `
34- folder inside your project (the currently fixed path is determined by
35- ` here("gitpins") ` ), and then returns the full file name name of the
36- local file, which can be passed as an argument to any function that
37- expects to read such a file.
33+ folder (defaults to ` here::here("gitpins") ` , but can be configured using
34+ ` gp_options() ` ), and then returns the full file name name of the local
35+ file, which can be passed as an argument to any function that expects to
36+ read such a file.
37+
38+ ## Installation
39+
40+ Install ` gitpins ` using ` pak ` :
41+
42+ ``` r
43+ pak :: pak(" torfason/gitpins" )
44+ ```
45+
46+ ## Usage
3847
3948``` r
4049# Downloads on first try
@@ -90,7 +99,11 @@ pin("https://vincentarelbundock.github.io/Rdatasets/csv/openintro/country_iso.cs
9099The refresh interval is configured with the ` refresh_hours ` parameter.
91100Use ` refresh_hours=0 ` to force a download on every call, and
92101` refresh_hours=Inf ` to always use the local copy (after the first
93- download).
102+ download). A helper function, ` gp_dropper() ` is provided for the case
103+ where a new version of the resource “drops” at the same time every day.
104+ The function allows you to set a lower interval in a given time window
105+ after the expected drop time, to maximize the probability that an
106+ updated version gets downloaded quickly.
94107
95108``` r
96109# Force a reload by specifying zero refresh time
@@ -106,6 +119,13 @@ pin("https://vincentarelbundock.github.io/Rdatasets/csv/openintro/country_iso.cs
106119 gsub(pattern = " .*/(gitpins/.*)" , replacement = " /home/user/project/\\ 1" )
107120# > pin() found recent version, using it ...
108121# > [1] "/home/user/project/gitpins/5ad1e570044be11330713642c682b9db.data"
122+
123+ # Set a lower interval for a given time window after a resource update "drops"
124+ pin(" https://vincentarelbundock.github.io/Rdatasets/csv/openintro/country_iso.csv" ,
125+ refresh_hours = gp_dropper(drop_hour = 12 , drop_tz = " US/Eastern" )) | >
126+ gsub(pattern = " .*/(gitpins/.*)" , replacement = " /home/user/project/\\ 1" )
127+ # > pin() found recent version, using it ...
128+ # > [1] "/home/user/project/gitpins/5ad1e570044be11330713642c682b9db.data"
109129```
110130
111131The ` gitpins ` directory is actually a local ` git ` repository, and each
@@ -120,62 +140,58 @@ but beyond that, the user is expected to use `git` directly for more
120140complex retrieval operations.
121141
122142``` r
123- list_pins()
143+ withr :: with_options(list (width = 130 ), {
144+ gp_list()
145+ gp_list(history = TRUE )
146+ })
124147# > Loading required namespace: tibble
125- # > # A tibble: 2 × 2
126- # > timestamp url
127- # > <chr> <chr>
128- # > 1 2024-03-28 16:33:23.74682 https://vincentarelbundock.github.io/Rdatasets/csv/openintro/country_iso.csv
129- # > 2 2024-03-28 16:33:23.58968 https://vincentarelbundock.github.io/Rdatasets/csv/datasets/sunspot.month.csv
130- list_pins(history = TRUE )
131148# > # A tibble: 3 × 2
132- # > timestamp url
133- # > <chr> <chr>
134- # > 1 2024 -03-28 16:33:23.74682 https://vincentarelbundock.github.io/Rdatasets/csv/openintro/country_iso.csv
135- # > 2 2024 -03-28 16:33 :23.58968 https://vincentarelbundock.github.io/Rdatasets/csv/datasets/sunspot.month.csv
136- # > 3 2024 -03-28 16:33 :23.27699 https://vincentarelbundock.github.io/Rdatasets/csv/openintro/country_iso.csv
149+ # > timestamp url
150+ # > <chr> <chr>
151+ # > 1 2025 -03-21 18:28:24.10695 https://vincentarelbundock.github.io/Rdatasets/csv/…
152+ # > 2 2025 -03-21 18:28 :23.92979 https://vincentarelbundock.github.io/Rdatasets/csv/…
153+ # > 3 2025 -03-21 18:28 :23.60490 https://vincentarelbundock.github.io/Rdatasets/csv/…
137154```
138155
139- ## Installation
156+ ## Function Name Conflicts
140157
141- Install ` gitpins ` with either of the following commands:
158+ For use with with another package that also defines a ` pin() ` function
159+ (such as the ` pins ` package), the ` conflicted ` package comes highly
160+ recommended, but the ` exclude ` option of the ` library() ` function is
161+ also a valid approach. In either case, the ` gp_pin() ` function is
162+ provided as an alias for ` pin() ` so you don’t need to specify the full
163+ package name on each call:
142164
143- ``` r
144- pak :: pak(" torfason/gitpins" )
145- # or alternatively
146- remotes :: install_github(" torfason/gitpins" )
147- ```
148-
149- You can then load and use the package like this:
165+ ### Using ` conflicted `
150166
151167``` r
168+ library(conflicted )
169+ conflicts_prefer(pins :: pin())
170+ library(pins )
152171library(gitpins )
153- pin (URL )
172+ gp_pin (URL )
154173```
155174
156- To use this concurrently with another package that also defines a
157- ` pin() ` function, exclude this function and use the alias ` gitpin() `
158- instead:
175+ ### Using ` exclude `
159176
160177``` r
178+ library(pins )
161179library(gitpins , exclude = " pin" )
162- gitpin (URL )
180+ gp_pin (URL )
163181```
164182
165- Note that ` gitpins ` uses the native pipe operator (` |> ` ) and so depends
166- on ` R (>= 4.1.0) ` . If this is an issue for you, holler and I can
167- probably be convinced of changing it to make it compatible with older
168- versions.
169-
170- ## Related packages and feedback
183+ ## Related Packages, System Requirements, and Feedback
171184
172185This package was inspired by the ` pins ` package, and in particular the
173186` pins::pin() ` function. However, that function stores the actual local
174187file in a system location rather than inside the project, so using it
175- did not prove reliable reliable. Furthermore, it did not have the
176- desired versioning properties, and finally, it is now defined as a
177- legacy function and is not part of the new api for that package. As a
178- result, ` gitpins ` was born.
188+ did not prove reliable. Furthermore, it did not have the desired
189+ versioning properties, and finally, it is now defined as a legacy
190+ function and is not part of the new api for that package. As a result,
191+ ` gitpins ` was born.
192+
193+ Note that ` gitpins ` uses the native pipe operator (` |> ` ) and so depends
194+ on ` R (>= 4.1.0) ` .
179195
180196For feature requests, bugs, or other feedback, feel free to file an
181197issue.
0 commit comments