Skip to content

Commit

Permalink
use pkgdown and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
njtierney committed Apr 19, 2024
1 parent 52603dd commit 4ce62ed
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
^_targets\.Rmd$
^_targets\.yaml$
^CODE_OF_CONDUCT\.md$
^_pkgdown\.yml$
^docs$
^pkgdown$
48 changes: 48 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
folder: docs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ _targets.R
_targets.Rmd
_targets_r
_targets.yaml
docs
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ Suggests:
terra,
testthat (>= 3.0.0)
Config/testthat/edition: 3
URL: https://github.com/njtierney/geotargets
URL: https://github.com/njtierney/geotargets, https://njtierney.github.io/geotargets/
BugReports: https://github.com/njtierney/geotargets/issues
35 changes: 34 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ install.packages("geotargets", repos = c("https://njtierney.r-universe.dev", "ht

# Examples

Below we show two examples of target factories:
Below we show three examples of target factories:

- `tar_terra_rast()`
- `tar_terra_vect()`
- `tar_terra_sprc()`

You would use these in place of `tar_target()` in your targets pipeline, when you are doing work with terra raster or terra vector data.

Expand Down Expand Up @@ -117,6 +118,38 @@ tar_dir({ # tar_dir() runs code from a temporary directory.
})
```


## `tar_terra_sprc()`: targets with terra raster collections

```{r}
#| label: tar-terra-sprc
#| eval: false
targets::tar_dir({ # tar_dir() runs code from a temporary directory.
library(geotargets)
targets::tar_script({
elev_scale <- function(z = 1, projection = "EPSG:4326") {
terra::project(
terra::rast(system.file("ex", "elev.tif", package = "terra")) * z,
projection
)
}
list(
tar_terra_sprc(
raster_elevs,
# two rasters, one unaltered, one scaled by factor of 2 and
# reprojected to interrupted good homolosine
command = terra::sprc(list(
elev_scale(1),
elev_scale(2, "+proj=igh")
))
)
)
})
targets::tar_make()
x <- targets::tar_read(raster_elevs)
})
```

## Code of Conduct

Please note that the geotargets project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ coverage](https://codecov.io/gh/njtierney/geotargets/branch/master/graph/badge.s
as rasters and vectors (e.g., shapefiles).

A relatively common gotcha moment when using popular libraries like
`terra` with targets is running into errors with read and write. Due to
`terra` with targets is running into erros with read and write. Due to
the limitations that come with the underlying C++ implementation in the
`terra` library, there are specific ways to write and read these
objects. See `?terra` for details. `geotargets` helps handle these write
Expand Down Expand Up @@ -55,10 +55,11 @@ breaking ways.

# Examples

Below we show two examples of target factories:
Below we show three examples of target factories:

- `tar_terra_rast()`
- `tar_terra_vect()`
- `tar_terra_sprc()`

You would use these in place of `tar_target()` in your targets pipeline,
when you are doing work with terra raster or terra vector data.
Expand Down Expand Up @@ -116,6 +117,35 @@ tar_dir({ # tar_dir() runs code from a temporary directory.
})
```

## `tar_terra_sprc()`: targets with terra raster collections

``` r
targets::tar_dir({ # tar_dir() runs code from a temporary directory.
library(geotargets)
targets::tar_script({
elev_scale <- function(z = 1, projection = "EPSG:4326") {
terra::project(
terra::rast(system.file("ex", "elev.tif", package = "terra")) * z,
projection
)
}
list(
tar_terra_sprc(
raster_elevs,
# two rasters, one unaltered, one scaled by factor of 2 and
# reprojected to interrupted good homolosine
command = terra::sprc(list(
elev_scale(1),
elev_scale(2, "+proj=igh")
))
)
)
})
targets::tar_make()
x <- targets::tar_read(raster_elevs)
})
```

## Code of Conduct

Please note that the geotargets project is released with a [Contributor
Expand Down
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
url: https://njtierney.github.io/geotargets/
template:
bootstrap: 5

1 change: 1 addition & 0 deletions man/geotargets-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4ce62ed

Please sign in to comment.