Skip to content

Commit

Permalink
RMD check passing
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejohnson51 committed Oct 3, 2024
1 parent c566cc5 commit 532a76b
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 17 deletions.
4 changes: 4 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ Depends:
R (>= 4.2)
Imports:
arrow,
DBI,
RSQLite,
dplyr,
glue,
jsonlite,
nhdplusTools,
sf
Suggests:
testthat
License: GPL (>= 3)
Encoding: UTF-8
LazyData: true
Expand Down
3 changes: 3 additions & 0 deletions R/find_origin.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ findOrigin <- function(
nldi_feature = NULL,
xy = NULL
) {

hf_id <- hydroseq <- poi_id <- toid <- topo <- vpuid <- NULL
# Capture arguments
.args <- c(as.list(environment()))

Expand Down Expand Up @@ -98,6 +100,7 @@ findOriginQuery.hf_id <- function(id, network, ...) {
#' @method findOriginQuery comid
#' @keywords internal
findOriginQuery.comid <- function(comid, network, ...) {
hf_id <- NULL
arrow::open_dataset(network) |>
dplyr::filter(hf_id == !!comid)
}
Expand Down
7 changes: 5 additions & 2 deletions R/find_origin_gpkg.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' Find Origin From ID
#' @param network a URI to a network-formatted Arrow dataset
#' @param gpkg a local geopackages file path
#' @inheritParams get_subset
#' @return data.frame
#' @export
Expand All @@ -13,6 +13,8 @@ findOriginGPKG <- function(
nldi_feature = NULL,
xy = NULL
) {

hf_id <- hydroseq <- poi_id <- toid <- topo <- vpuid <- NULL
# Capture arguments
.args <- c(as.list(environment()))

Expand Down Expand Up @@ -56,7 +58,7 @@ findOriginGPKG <- function(


#' S3 method for dispatching on query type
#' @return Arrow Table/Deferred connection
#' @return SQLite connection
#' @keywords internal
findOriginQueryGPKG <- function(id, gpkg, ...) {
if (!inherits(gpkg, "character")) {
Expand Down Expand Up @@ -89,6 +91,7 @@ findOriginQueryGPKG.hf_id <- function(id, gpkg, ...) {
#' @method findOriginQuery comid
#' @keywords internal
findOriginQueryGPKG.comid <- function(comid, gpkg, ...) {
hf_id <- NULL
as_sqlite(gpkg, "network") |>
dplyr::filter(hf_id == !!comid)
}
Expand Down
17 changes: 13 additions & 4 deletions R/get_subset.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
na.omit = function(x){ x[!is.na(x)] }

#' Extract Data from Arrow Stores
#' @inheritParams get_subset
#' @param hook a local or s3 hydrofabric directory
#' @param vpu an optional VPU to quicken search
#' @param ids all identifiers to extract
#' @param lyrs hydrofabric layers to subset
#' @param outfile a path to write resulting geopackage
#' @return list or file path
#' @export

extract_arrow_data = function(hook, vpu, ids, lyrs, outfile = NULL){

vpuid <- poi_id <- NULL
hydrofabric = list()

for(i in 1:length(lyrs)){
Expand Down Expand Up @@ -58,13 +62,17 @@ extract_arrow_data = function(hook, vpu, ids, lyrs, outfile = NULL){


#' Extract Data from Arrow Stores
#' @inheritParams get_subset
#' @param hook a local or s3 hydrofabric directory
#' @param gpkg a local gpkg file
#' @param vpu an optional VPU to quicken search
#' @param ids all identifiers to extract
#' @param lyrs hydrofabric layers to subset
#' @param outfile a path to write resulting geopackage
#' @return list or file path
#' @export

extract_gpkg_data = function(gpkg, vpu, ids, lyrs, outfile = NULL){

vpuid <- poi_id <- NULL
hydrofabric = list()

for(i in 1:length(lyrs)){
Expand Down Expand Up @@ -114,7 +122,6 @@ extract_gpkg_data = function(gpkg, vpu, ids, lyrs, outfile = NULL){
}



#' @title Build a hydrofabric subset
#' @param id hydrofabric id. datatype: string / vector of strings e.g., 'wb-10026' or c('wb-10026', 'wb-10355')
#' @param comid NHDPlusV2 COMID. datatype: int / vector of int e.g., 61297116 or c(61297116 , 6129261)
Expand All @@ -125,6 +132,7 @@ extract_gpkg_data = function(gpkg, vpu, ids, lyrs, outfile = NULL){
#' @param type hydrofabric type
#' @param hf_version hydrofabric version
#' @param source hydrofabric source (local root directory or s3 link)
#' @param gpkg a local gpkg file
#' @param outfile If gpkg file path is provided, data will be written to a file.
#' @param lyrs layers to extract
#' @param domain hydrofabric domain
Expand Down Expand Up @@ -163,6 +171,7 @@ get_subset = function(id = NULL,
}
}

hf_id <- vpuid <- NULL
hook <- glue("{source}/v{hf_version}/{type}/{domain}")

if(!is.null(gpkg)){
Expand Down
8 changes: 6 additions & 2 deletions man/extract_arrow_data.Rd

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

10 changes: 7 additions & 3 deletions man/extract_gpkg_data.Rd

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

4 changes: 2 additions & 2 deletions man/findOriginGPKG.Rd

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

2 changes: 1 addition & 1 deletion man/findOriginQueryGPKG.Rd

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

4 changes: 3 additions & 1 deletion man/get_subset.Rd

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

7 changes: 5 additions & 2 deletions tests/testthat/test-origin.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#x network <- '/Users/mjohnson/hydrofabric/v2.2/reference/conus_network'
network <- 's3://lynker-spatial/hydrofabric/v2.2/reference/conus_network'

test = arrow %>%
filter(hl_uri == "gages-06752260") %>%
collect()


test_that("Test ID", {
ido = findOrigin(network, id = test$id)
expect_equal(ido$id, 2899997)
Expand Down Expand Up @@ -46,8 +51,6 @@ test_that("Test XY", {
#x network <- '/Users/mjohnson/hydrofabric/v2.2/reference/conus_network'
gpkg <- conus_gpkg

read_sf(ne)

test = as_sqlite(gpkg, "network") %>%
filter(hl_uri == "gages-06752260") %>%
collect()
Expand Down

0 comments on commit 532a76b

Please sign in to comment.