-
Notifications
You must be signed in to change notification settings - Fork 24
feat: r bindings #973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
gadomski
wants to merge
24
commits into
main
Choose a base branch
from
issues/972-r-wrappers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: r bindings #973
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
63246a5
feat: r bindings
gadomski 22cd757
docs: add readme
gadomski 8d1ea4e
fix: update readme, add ci
gadomski 832bdc9
Merge branch 'main' into issues/972-r-wrappers
gadomski 7acb2e3
fix: registration
gadomski 8d30409
cleanup
gadomski c9b208e
fix: wrappers
gadomski 1e13d71
fix: name
gadomski 20f74e3
fix: redunant directory
gadomski 26af041
fix: remote reads for parquet
gadomski f032cbb
fix: remove files
gadomski 1e1473f
fix: don't put r in workspace
gadomski 8ac0ab3
fix: try to do public for installs
gadomski 5f5cec7
fix: get artifacts
gadomski d931167
fix: add back to workspaces
gadomski e14daa6
fix: exclude R crate
gadomski 4aa36a1
fix: remove workspace exclude
gadomski 2b3d8bf
fix: we need working directory
gadomski 2cf4be6
ci: exclude rcheck
gadomski 6c3aace
fix: build to /tmp
gadomski 39500e5
fix: exclude
gadomski 7361589
fix: rignore more
gadomski cf32bcd
fix: reqwest on ci
gadomski c6aedf9
fix: stuff
gadomski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ^src/rust/target$ | ||
| ^src/rust/.cargo$ | ||
| ^README\.md$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # History files | ||
| .Rhistory | ||
| .Rapp.history | ||
|
|
||
| # Session Data files | ||
| .RData | ||
| .RDataTmp | ||
|
|
||
| # User-specific files | ||
| .Ruserdata | ||
|
|
||
| # Example code in package build process | ||
| *-Ex.R | ||
|
|
||
| # Output files from R CMD build | ||
| /*.tar.gz | ||
|
|
||
| # Output files from R CMD check | ||
| /*.Rcheck/ | ||
|
|
||
| # RStudio files | ||
| .Rproj.user/ | ||
|
|
||
| # produced vignettes | ||
| vignettes/*.html | ||
| vignettes/*.pdf | ||
|
|
||
| # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 | ||
| .httr-oauth | ||
|
|
||
| # knitr and R markdown default cache directories | ||
| *_cache/ | ||
| /cache/ | ||
|
|
||
| # Temporary files created by R markdown | ||
| *.utf8.md | ||
| *.knit.md | ||
|
|
||
| # R Environment Variables | ||
| .Renviron | ||
|
|
||
| # pkgdown site | ||
| docs/ | ||
|
|
||
| # translation temp files | ||
| po/*~ | ||
|
|
||
| # RStudio Connect folder | ||
| rsconnect/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| Package: rustac | ||
| Title: SpatioTemporal Asset Catalog (STAC) Client | ||
| Version: 0.1.0 | ||
| Authors@R: | ||
| person("Pete", "Gadomski", , "pete.gadomski@gmail.com", role = c("aut", "cre")) | ||
| Description: Read and write SpatioTemporal Asset Catalog (STAC) data in JSON, | ||
| NDJSON, and geoparquet formats. Powered by Rust via the 'extendr' framework. | ||
| License: MIT + file LICENSE | ||
| Encoding: UTF-8 | ||
| Roxygen: list(markdown = TRUE) | ||
| RoxygenNote: 7.3.2 | ||
| Imports: | ||
| arrow, | ||
| jsonlite, | ||
| sf | ||
| Suggests: | ||
| geojsonsf, | ||
| testthat (>= 3.0.0) | ||
| Config/testthat/edition: 3 | ||
| SystemRequirements: Cargo (Rust's package manager), rustc >= 1.88 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| Permission is hereby granted, free of charge, to any | ||
| person obtaining a copy of this software and associated | ||
| documentation files (the "Software"), to deal in the | ||
| Software without restriction, including without | ||
| limitation the rights to use, copy, modify, merge, | ||
| publish, distribute, sublicense, and/or sell copies of | ||
| the Software, and to permit persons to whom the Software | ||
| is furnished to do so, subject to the following | ||
| conditions: | ||
|
|
||
| The above copyright notice and this permission notice | ||
| shall be included in all copies or substantial portions | ||
| of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF | ||
| ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
| TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
| SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
| CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
| OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR | ||
| IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| DEALINGS IN THE SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| useDynLib(rustac, .registration = TRUE) | ||
|
|
||
| export(stac_read) | ||
| export(stac_write) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Generated by extendr: Do not edit by hand | ||
|
|
||
| # nolint start | ||
|
|
||
| #' @docType package | ||
| #' @usage NULL | ||
| #' @useDynLib rustac, .registration = TRUE | ||
| NULL | ||
|
|
||
| wrap__stac_read_json <- function(path) { | ||
| .Call("wrap__stac_read_json", path, PACKAGE = "rustac") | ||
| } | ||
|
|
||
| wrap__stac_write_json <- function(json, path) { | ||
| .Call("wrap__stac_write_json", json, path, PACKAGE = "rustac") | ||
| } | ||
|
|
||
| wrap__stac_read_geoparquet <- function(path) { | ||
| .Call("wrap__stac_read_geoparquet", path, PACKAGE = "rustac") | ||
| } | ||
|
|
||
| wrap__stac_write_geoparquet <- function(ipc_bytes, path) { | ||
| .Call("wrap__stac_write_geoparquet", ipc_bytes, path, PACKAGE = "rustac") | ||
| } | ||
|
|
||
| # nolint end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #' Read a STAC value from a file or URL | ||
| #' | ||
| #' Reads STAC data from JSON, NDJSON, or geoparquet formats. The format is | ||
| #' inferred from the file extension. Geoparquet files are returned as sf data | ||
| #' frames via Arrow; all other types are returned as R lists. | ||
| #' | ||
| #' @param path Path to a file or a URL. | ||
| #' @return An sf data frame (for geoparquet/FeatureCollections) or an R list. | ||
| #' @export | ||
| stac_read <- function(path) { | ||
| if (is_geoparquet(path)) { | ||
| ipc_bytes <- wrap__stac_read_geoparquet(path) | ||
| table <- arrow::read_ipc_stream(ipc_bytes, as_data_frame = FALSE) | ||
| df <- as.data.frame(table) | ||
| geom <- sf::st_as_sfc(structure(df$geometry, class = "WKB"), EWKB = TRUE) | ||
| df$geometry <- NULL | ||
| sf::st_sf(df, geometry = geom) | ||
| } else { | ||
| json <- wrap__stac_read_json(path) | ||
| value <- jsonlite::fromJSON(json, simplifyVector = FALSE) | ||
| if (identical(value$type, "FeatureCollection")) { | ||
| sf::read_sf(json) | ||
| } else { | ||
| value | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #' Write a STAC value to a file | ||
| #' | ||
| #' Writes STAC data to JSON, NDJSON, or geoparquet formats. The format is | ||
| #' inferred from the file extension. sf data frames are written via Arrow for | ||
| #' geoparquet output; all other values are serialized with jsonlite. | ||
| #' | ||
| #' @param x An sf data frame or an R list representing a STAC value. | ||
| #' @param path Output file path. | ||
| #' @export | ||
| stac_write <- function(x, path) { | ||
| if (is_geoparquet(path)) { | ||
| table <- arrow::as_arrow_table(sf::st_as_sf(x)) | ||
| buf <- arrow::write_ipc_stream(table, raw()) | ||
| invisible(wrap__stac_write_geoparquet(buf, path)) | ||
| } else { | ||
| if (inherits(x, "sf")) { | ||
| if (!requireNamespace("geojsonsf", quietly = TRUE)) { | ||
| stop("Package 'geojsonsf' is required to write sf objects to non-parquet formats") | ||
| } | ||
| json <- geojsonsf::sf_geojson(x) | ||
| } else { | ||
| json <- jsonlite::toJSON(x, auto_unbox = TRUE, null = "null") | ||
| } | ||
| invisible(wrap__stac_write_json(as.character(json), path)) | ||
| } | ||
| } | ||
|
|
||
| is_geoparquet <- function(path) { | ||
| grepl("\\.(parquet|geoparquet)$", path, ignore.case = TRUE) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .onLoad <- function(libname, pkgname) { | ||
| library.dynam("rustac", pkgname, libname) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # rustac | ||
|
|
||
| R package for reading and writing [SpatioTemporal Asset Catalog (STAC)](https://stacspec.org/) data in JSON, NDJSON, and [stac-geoparquet](https://github.com/stac-utils/stac-geoparquet) formats. | ||
| Powered by Rust via [extendr](https://extendr.github.io/extendr/extendr_api/). | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - **Rust** toolchain (rustc >= 1.88): <https://rustup.rs/> | ||
|
|
||
| ## Install | ||
|
|
||
| Install directly from GitHub using [pak](https://pak.r-lib.org/) (recommended): | ||
|
|
||
| ```r | ||
| # install.packages("pak") | ||
| pak::pak("stac-utils/rustac/crates/r") | ||
| ``` | ||
|
|
||
| Or with `devtools`: | ||
|
|
||
| ```r | ||
| # install.packages("devtools") | ||
| devtools::install_github("stac-utils/rustac", subdir = "crates/r") | ||
| ``` | ||
|
|
||
| ### From source | ||
|
|
||
| From the repository root: | ||
|
|
||
| ```bash | ||
| R CMD build crates/r | ||
| R CMD INSTALL rustac_0.1.0.tar.gz | ||
| ``` | ||
|
|
||
| ### Troubleshooting | ||
|
|
||
| If `arrow` or `sf` fail to install, try [r-universe](https://r-universe.dev/) binaries first: | ||
|
|
||
| ```r | ||
| install.packages( | ||
| c("arrow", "sf"), | ||
| repos = c("https://apache.r-universe.dev", "https://r-spatial.r-universe.dev", "https://cloud.r-project.org") | ||
| ) | ||
| ``` | ||
|
|
||
| Then retry the install. | ||
|
|
||
| ## Development | ||
|
|
||
| For iterative development, use `devtools`: | ||
|
|
||
| ```r | ||
| devtools::load_all("crates/r") | ||
| devtools::test("crates/r") | ||
| ``` | ||
|
|
||
| To run the full R CMD check: | ||
|
|
||
| ```bash | ||
| R CMD build crates/r | ||
| R CMD check rustac_0.1.0.tar.gz | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```r | ||
| library(rustac) | ||
|
|
||
| # Read a STAC item (returns an R list) | ||
| item <- stac_read("spec-examples/v1.1.0/simple-item.json") | ||
| item$id | ||
| #> [1] "20201211_223832_CS2" | ||
|
|
||
| # Read stac-geoparquet (returns an sf data frame) | ||
| sf <- stac_read("data/extended-item.parquet") | ||
| class(sf) | ||
| #> [1] "sf" "data.frame" | ||
|
|
||
| # Write to JSON | ||
| stac_write(item, "output.json") | ||
|
|
||
| # Write to stac-geoparquet | ||
| stac_write(sf, "output.parquet") | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| Package: rustac | ||
| Title: SpatioTemporal Asset Catalog (STAC) Client | ||
| Version: 0.1.0 | ||
| Authors@R: | ||
| person("Pete", "Gadomski", , "pete.gadomski@gmail.com", role = c("aut", "cre")) | ||
| Description: Read and write SpatioTemporal Asset Catalog (STAC) data in JSON, | ||
| NDJSON, and geoparquet formats. Powered by Rust via the 'extendr' framework. | ||
| License: MIT + file LICENSE | ||
| Encoding: UTF-8 | ||
| Roxygen: list(markdown = TRUE) | ||
| RoxygenNote: 7.3.2 | ||
| Imports: arrow, jsonlite, sf | ||
| Suggests: geojsonsf, testthat (>= 3.0.0) | ||
| Config/testthat/edition: 3 | ||
| SystemRequirements: Cargo (Rust's package manager), rustc >= 1.88 | ||
| NeedsCompilation: yes | ||
| Packaged: 2026-02-27 15:17:25 UTC; gadomski | ||
| Author: Pete Gadomski [aut, cre] | ||
| Maintainer: Pete Gadomski <pete.gadomski@gmail.com> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| Permission is hereby granted, free of charge, to any | ||
| person obtaining a copy of this software and associated | ||
| documentation files (the "Software"), to deal in the | ||
| Software without restriction, including without | ||
| limitation the rights to use, copy, modify, merge, | ||
| publish, distribute, sublicense, and/or sell copies of | ||
| the Software, and to permit persons to whom the Software | ||
| is furnished to do so, subject to the following | ||
| conditions: | ||
|
|
||
| The above copyright notice and this permission notice | ||
| shall be included in all copies or substantial portions | ||
| of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF | ||
| ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
| TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
| SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
| CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
| OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR | ||
| IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| DEALINGS IN THE SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| useDynLib(rustac, .registration = TRUE) | ||
|
|
||
| export(stac_read) | ||
| export(stac_write) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Generated by extendr: Do not edit by hand | ||
|
|
||
| # nolint start | ||
|
|
||
| #' @docType package | ||
| #' @usage NULL | ||
| #' @useDynLib rustac, .registration = TRUE | ||
| NULL | ||
|
|
||
| wrap__stac_read_json <- function(path) { | ||
| .Call("wrap__stac_read_json", path) | ||
| } | ||
|
|
||
| wrap__stac_write_json <- function(json, path) { | ||
| .Call("wrap__stac_write_json", json, path) | ||
| } | ||
|
|
||
| wrap__stac_read_geoparquet <- function(path) { | ||
| .Call("wrap__stac_read_geoparquet", path) | ||
| } | ||
|
|
||
| wrap__stac_write_geoparquet <- function(ipc_bytes, path) { | ||
| .Call("wrap__stac_write_geoparquet", ipc_bytes, path) | ||
| } | ||
|
|
||
| # nolint end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.