bcgov / bcgov/bcdata

Filter using string partial matching

Open
#227 7 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
R
Stars
87
Forks
14
PR merge metrics
No merged PRs in 30d

Description

**Problem:** I'd like to filter a query but I only know part of the string I am looking for...

``` r
bcdata::bcdc_query_geodata("bc-parks-ecological-reserves-and-protected-areas") %>%
filter(stringr::str_detect(PROTECTED_LANDS_NAME, "SUGARBOWL.*PARK*"))

#> Error in stri_detect_regex(string, pattern, negate = negate, opts_regex = opts(pattern)): object 'PROTECTED_LANDS_NAME' not found
```

**Potential solution:**
I could download/collect only the column that I want to filter by, detect the sting that I am looking for and then use that string to filter my query.

```
my_var <- bcdc_query_geodata("bc-parks-ecological-reserves-and-protected-areas") %>%
collect() %>%
st_drop_geometry() %>%
select(PROTECTED_LANDS_NAME) %>%
filter(stringr::str_detect(PROTECTED_LANDS_NAME, "SUGARBOWL.*PARK")) %>%
pull()

bcdc_query_geodata("bc-parks-ecological-reserves-and-protected-areas") %>%
filter(PROTECTED_LANDS_NAME == my_var)
```

**Problem with this solution:** I need to download the geometries of the data set to get the column that I am interested in, which is essentially just downloading the entire dataset, so there is no processing speed advantage.

**My question:**
Is there a way to drop the geometry before collecting the data? I suspect that this would be very fast and efficient for filtering large datasets using string detection.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.