Skip to content

Commit 73dda2e

Browse files
committed
Update README and documentation
1 parent c7efa63 commit 73dda2e

9 files changed

Lines changed: 140 additions & 90 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: gitpins
22
Type: Package
33
Title: Pin urls to local file and version with git
4-
Version: 0.1.3.9002
4+
Version: 0.1.3.9003
55
Author: Magnus Thor Torfason
66
Maintainer: Magnus Thor Torfason <m@zulutime.net>
77
Description: Pin URLs to local file and version the pins with git.

NEWS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
Version 0.3.9003
3+
================
4+
5+
- Custom location for the `gitpin` directory using `gp_options()`
6+
7+
- Target specific "drop" times for the online resources that are being fetched,
8+
by using the `gp_dropper()`
9+
10+
- More consistent function names, `gp_pin()`, `gp_list()`, `gp_options()`,
11+
and `gp_dropper()`
12+
13+
14+
Version 0.3.0
15+
=============
16+
17+
- Initial release.

R/gp_options.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11

22

3-
#' @title Create a gp_options Object
3+
#' @title Create a `gp_options` Object
44
#' @description Constructs a `gp_options` object with configurable parameters.
55
#' The parameters can be set from the defaults, from R options, or directly
66
#' when the options object is created.
77
#' @param ... Reserved. All arguments must be named.
88
#' @param pin_directory A character string specifying the directory to use
9-
#' for the pin repo
9+
#' for the pin directory (the local git repository where downloaded resources
10+
#' are stored and versioned).
1011
#' @return A list representing the `gp_options` object.
1112
#' @export
1213
gp_options <- function(...,
@@ -27,12 +28,12 @@ gp_options <- function(...,
2728
}
2829

2930

30-
#' @title Verify that x is a valid gp_options object
31+
#' @title Verify that x is a valid `gp_options` object
3132
#' @description Verifies that `x` is a `gp_options` object (of class
3233
#' `gitpins_gp_options`) and that all elements of the object are
3334
#' valid for such an object. Use `gp_options()` to create `gp_options`
3435
#' objects.
35-
#' @param x An object to verify
36+
#' @param x An object to verify.
3637
#' @return Unchanged input if valid, otherwise an error is thrown.
3738
#' @keywords internal
3839
assert_gp_options <- function(x) {

README.Rmd

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ stopifnot(!file.exists(here::here("gitpins")))
2121
# gitpins
2222

2323
<!-- badges: start -->
24-
[![R-CMD-check](https://github.com/torfason/gitpins/workflows/R-CMD-check/badge.svg)](https://github.com/torfason/gitpins/actions)
2524
[![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)
2625
<!-- badges: end -->
2726

2827
`r desc::desc_get("Description")`
2928

30-
## The problem
29+
## The Problem
3130

3231
You want to quickly and easily process an online resource using R functions,
3332
some of which only accept local files. Thus you would like the following
@@ -40,14 +39,24 @@ properties for your workflow:
4039
* Have the local copy be easily accessible in a predictable location
4140
* Not ruin your local copy if the online version should change in a "bad" way
4241

43-
## The solution
42+
## The Solution
4443

4544
The `gitpins` package downloads a URL to a local file in the `gitpins` folder
46-
inside your project (the currently fixed path is determined by
47-
`here("gitpins")`), and then returns the full file name name of the local file,
45+
(defaults to `here::here("gitpins")`, but can be configured using
46+
`gp_options()`), and then returns the full file name name of the local file,
4847
which can be passed as an argument to any function that expects to read such a
4948
file.
5049

50+
## Installation
51+
52+
Install `gitpins` using `pak`:
53+
54+
```r
55+
pak::pak("torfason/gitpins")
56+
```
57+
58+
## Usage
59+
5160
```{r}
5261
# Downloads on first try
5362
pin("https://vincentarelbundock.github.io/Rdatasets/csv/openintro/country_iso.csv") |>
@@ -81,7 +90,11 @@ pin("https://vincentarelbundock.github.io/Rdatasets/csv/openintro/country_iso.cs
8190

8291
The refresh interval is configured with the `refresh_hours` parameter. Use
8392
`refresh_hours=0` to force a download on every call, and `refresh_hours=Inf` to
84-
always use the local copy (after the first download).
93+
always use the local copy (after the first download). A helper function,
94+
`gp_dropper()` is provided for the case where a new version of the resource
95+
"drops" at the same time every day. The function allows you to set a lower
96+
interval in a given time window after the expected drop time, to maximize the
97+
probability that an updated version gets downloaded quickly.
8598

8699
```{r}
87100
# Force a reload by specifying zero refresh time
@@ -93,6 +106,11 @@ pin("https://vincentarelbundock.github.io/Rdatasets/csv/openintro/country_iso.cs
93106
pin("https://vincentarelbundock.github.io/Rdatasets/csv/openintro/country_iso.csv",
94107
refresh_hours = Inf) |>
95108
gsub(pattern=".*/(gitpins/.*)", replacement="/home/user/project/\\1")
109+
110+
# Set a lower interval for a given time window after a resource update "drops"
111+
pin("https://vincentarelbundock.github.io/Rdatasets/csv/openintro/country_iso.csv",
112+
refresh_hours = gp_dropper(drop_hour = 12, drop_tz = "US/Eastern")) |>
113+
gsub(pattern=".*/(gitpins/.*)", replacement="/home/user/project/\\1")
96114
```
97115

98116
The `gitpins` directory is actually a local `git` repository, and each new
@@ -106,56 +124,51 @@ function is provided to list available pins (with or without history), but
106124
beyond that, the user is expected to use `git` directly for more complex
107125
retrieval operations.
108126

109-
```{r, include=FALSE}
110-
old_width <- options(width=130)
111-
```
112-
113127
```{r}
114-
list_pins()
115-
list_pins(history = TRUE)
128+
withr::with_options(list(width = 130), {
129+
gp_list()
130+
gp_list(history = TRUE)
131+
})
116132
```
117133

118-
```{r, include=FALSE}
119-
options(old_width)
120-
```
121134

122-
## Installation
135+
## Function Name Conflicts
123136

124-
Install `gitpins` with either of the following commands:
137+
For use with with another package that also defines a `pin()` function (such as
138+
the `pins` package), the `conflicted` package comes highly recommended, but the
139+
`exclude` option of the `library()` function is also a valid approach. In either
140+
case, the `gp_pin()` function is provided as an alias for `pin()` so you don't
141+
need to specify the full package name on each call:
125142

126-
``` r
127-
pak::pak("torfason/gitpins")
128-
# or alternatively
129-
remotes::install_github("torfason/gitpins")
130-
```
131-
132-
You can then load and use the package like this:
143+
### Using `conflicted`
133144

134145
```r
146+
library(conflicted)
147+
conflicts_prefer(pins::pin())
148+
library(pins)
135149
library(gitpins)
136-
pin(URL)
150+
gp_pin(URL)
137151
```
138152

139-
To use this concurrently with another package that also defines a `pin()`
140-
function, exclude this function and use the alias `gitpin()` instead:
153+
### Using `exclude`
141154

142155
```r
156+
library(pins)
143157
library(gitpins, exclude="pin")
144-
gitpin(URL)
158+
gp_pin(URL)
145159
```
146160

147-
Note that `gitpins` uses the native pipe operator (`|>`) and so depends on `R
148-
(>= 4.1.0)`. If this is an issue for you, holler and I can probably be convinced
149-
of changing it to make it compatible with older versions.
150-
151-
## Related packages and feedback
161+
## Related Packages, System Requirements, and Feedback
152162

153163
This package was inspired by the `pins` package, and in particular the
154164
`pins::pin()` function. However, that function stores the actual local file in a
155165
system location rather than inside the project, so using it did not prove
156-
reliable reliable. Furthermore, it did not have the desired versioning
157-
properties, and finally, it is now defined as a legacy function and is not part
158-
of the new api for that package. As a result, `gitpins` was born.
166+
reliable. Furthermore, it did not have the desired versioning properties, and
167+
finally, it is now defined as a legacy function and is not part of the new api
168+
for that package. As a result, `gitpins` was born.
169+
170+
Note that `gitpins` uses the native pipe operator (`|>`) and so depends on `R
171+
(>= 4.1.0)`.
159172

160173
For feature requests, bugs, or other feedback, feel free to file an issue.
161174

README.md

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
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
1413
from the web is not successful, a previous local download is made
1514
available.
1615

17-
## The problem
16+
## The Problem
1817

1918
You want to quickly and easily process an online resource using R
2019
functions, 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

3332
The `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
9099
The refresh interval is configured with the `refresh_hours` parameter.
91100
Use `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

111131
The `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
120140
complex 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)
152171
library(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)
161179
library(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

172185
This package was inspired by the `pins` package, and in particular the
173186
`pins::pin()` function. However, that function stores the actual local
174187
file 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

180196
For feature requests, bugs, or other feedback, feel free to file an
181197
issue.

build/build_and_release_process.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
if (file.exists(gpdir)) {
66
file.rename(gpdir, paste0(gpdir,"_",gitpins:::fstamp(Sys.time())))
77
}
8-
devtools::build()
98
devtools::document()
9+
devtools::build()
1010
devtools::build_readme()
11+
devtools::build_site()
1112
devtools::test()
1213
message("Build OK")
1314
}

0 commit comments

Comments
 (0)