bcgov / bcdata

An R package for searching & retrieving data from the B.C. Data Catalogue
https://bcgov.github.io/bcdata
Apache License 2.0
81 stars 12 forks source link

sticky column is reversed #279

Closed boshek closed 2 years ago

boshek commented 3 years ago

bcdc_describe_feature had the sticky column values reversed. For example:

library(bcdata)
#> 
#> Attaching package: 'bcdata'
#> The following object is masked from 'package:stats':
#> 
#>     filter
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

## All the columns that are "not" sticky
bcdc_describe_feature("bc-airports") %>%
  filter(!sticky)
#> Warning: It is advised to use the permanent id ('76b1b7a3-2112-4444-857a-afccf7b20da8') rather than the name of the record ('bc-airports') to guard against future name changes.
#> # A tibble: 9 x 5
#>   col_name                      sticky remote_col_type local_col_type column_comments
#>   <chr>                         <lgl>  <chr>           <chr>          <chr>          
#> 1 id                            FALSE  xsd:string      character      <NA>           
#> 2 CUSTODIAN_ORG_DESCRIPTION     FALSE  xsd:string      character      CUSTODIAN_ORG_~
#> 3 BUSINESS_CATEGORY_CLASS       FALSE  xsd:string      character      BUSINESS_CATEG~
#> 4 BUSINESS_CATEGORY_DESCRIPTION FALSE  xsd:string      character      BUSINESS_CATEG~
#> 5 OCCUPANT_TYPE_DESCRIPTION     FALSE  xsd:string      character      OCCUPANT_TYPE_~
#> 6 SOURCE_DATA_ID                FALSE  xsd:string      character      SOURCE_DATA_ID~
#> 7 SUPPLIED_SOURCE_ID_IND        FALSE  xsd:string      character      SUPPLIED_SOURC~
#> 8 AIRPORT_NAME                  FALSE  xsd:string      character      AIRPORT_NAME i~
#> 9 SEQUENCE_ID                   FALSE  xsd:decimal     numeric        SEQUENCE_ID co~

fw <- bcdc_query_geodata("bc-airports")

## we don't drop any columns that are supposedly "not-sticky"
fw %>%
  select(AIRPORT_NAME)
#> Querying 'bc-airports' record
#> * Using collect() on this object will return 455 features and 9 fields
#> * At most six rows of the record are printed here
#> --------------------------------------------------------------------------------
#> Simple feature collection with 6 features and 9 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 833323.9 ymin: 381604.1 xmax: 1198292 ymax: 1054950
#> Projected CRS: NAD83 / BC Albers
#> # A tibble: 6 x 10
#>   id       CUSTODIAN_ORG_DES~ BUSINESS_CATEGO~ BUSINESS_CATEGO~ OCCUPANT_TYPE_D~
#>   <chr>    <chr>              <chr>            <chr>            <chr>           
#> 1 WHSE_IM~ "Ministry of Fore~ airTransportati~ Air Transportat~ BC Airports     
#> 2 WHSE_IM~ "Ministry of Fore~ airTransportati~ Air Transportat~ BC Airports     
#> 3 WHSE_IM~ "Ministry of Fore~ airTransportati~ Air Transportat~ BC Airports     
#> 4 WHSE_IM~ "Ministry of Fore~ airTransportati~ Air Transportat~ BC Airports     
#> 5 WHSE_IM~ "Ministry of Fore~ airTransportati~ Air Transportat~ BC Airports     
#> 6 WHSE_IM~ "Ministry of Fore~ airTransportati~ Air Transportat~ BC Airports     
#> # ... with 5 more variables: SOURCE_DATA_ID <chr>,
#> #   SUPPLIED_SOURCE_ID_IND <chr>, AIRPORT_NAME <chr>, SEQUENCE_ID <int>,
#> #   geometry <POINT [m]>

## All cols that are supposed to be sticky
bcdc_describe_feature("bc-airports") %>%
  filter(sticky)
#> # A tibble: 33 x 5
#>    col_name         sticky remote_col_type local_col_type column_comments       
#>    <chr>            <lgl>  <chr>           <chr>          <chr>                 
#>  1 DESCRIPTION      TRUE   xsd:string      character      "DESCRIPTION describe~
#>  2 PHYSICAL_ADDRESS TRUE   xsd:string      character      "PHYSICAL_ADDRESS con~
#>  3 ALIAS_ADDRESS    TRUE   xsd:string      character      "ALIAS_ADDRESS contai~
#>  4 STREET_ADDRESS   TRUE   xsd:string      character      "STREET_ADDRESS is a ~
#>  5 POSTAL_CODE      TRUE   xsd:string      character      "POSTAL_CODE is the C~
#>  6 LOCALITY         TRUE   xsd:string      character      "LOCALITY is the name~
#>  7 CONTACT_PHONE    TRUE   xsd:string      character      "CONTACT PHONE contai~
#>  8 CONTACT_EMAIL    TRUE   xsd:string      character      "CONTACT_EMAIL contai~
#>  9 CONTACT_FAX      TRUE   xsd:string      character      "CONTACT FAX contains~
#> 10 WEBSITE_URL      TRUE   xsd:string      character      "WEBSITE_URL contains~
#> # ... with 23 more rows

## all cols dropped except that one selected and non-sticky ones!
fw %>%
  select(DESCRIPTION)
#> Querying 'bc-airports' record
#> * Using collect() on this object will return 455 features and 10 fields
#> * At most six rows of the record are printed here
#> --------------------------------------------------------------------------------
#> Simple feature collection with 6 features and 10 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 833323.9 ymin: 381604.1 xmax: 1198292 ymax: 1054950
#> Projected CRS: NAD83 / BC Albers
#> # A tibble: 6 x 11
#>   id       CUSTODIAN_ORG_DES~ BUSINESS_CATEGO~ BUSINESS_CATEGO~ OCCUPANT_TYPE_D~
#>   <chr>    <chr>              <chr>            <chr>            <chr>           
#> 1 WHSE_IM~ "Ministry of Fore~ airTransportati~ Air Transportat~ BC Airports     
#> 2 WHSE_IM~ "Ministry of Fore~ airTransportati~ Air Transportat~ BC Airports     
#> 3 WHSE_IM~ "Ministry of Fore~ airTransportati~ Air Transportat~ BC Airports     
#> 4 WHSE_IM~ "Ministry of Fore~ airTransportati~ Air Transportat~ BC Airports     
#> 5 WHSE_IM~ "Ministry of Fore~ airTransportati~ Air Transportat~ BC Airports     
#> 6 WHSE_IM~ "Ministry of Fore~ airTransportati~ Air Transportat~ BC Airports     
#> # ... with 6 more variables: SOURCE_DATA_ID <chr>,
#> #   SUPPLIED_SOURCE_ID_IND <chr>, AIRPORT_NAME <chr>, DESCRIPTION <chr>,
#> #   SEQUENCE_ID <int>, geometry <POINT [m]>

The issue is here: https://github.com/bcgov/bcdata/blob/f1ef671e04e9072561c490e75bca3cec3e323bbc/R/describe-feature.R#L118