Skip to content

Commit

Permalink
Merge pull request #229 from bcgov/fix-examples-checks
Browse files Browse the repository at this point in the history
Guard against check failures in examples
  • Loading branch information
ateucher authored Oct 22, 2020
2 parents b06b2c5 + e4bf5d1 commit d780f10
Show file tree
Hide file tree
Showing 26 changed files with 411 additions and 163 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cmd-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
matrix:
config:
- { os: windows-latest, r: 'release', args: "'--no-manual'"}
- { os: macOS-latest, r: 'release', args: "'--test-dontrun'"}
- { os: macOS-latest, r: 'release', args: "'--as-cran'"}
- { os: ubuntu-latest, r: '3.5', args: "'--no-manual'"}
- { os: ubuntu-latest, r: 'oldrel', args: "'--no-manual'"}
- { os: ubuntu-latest, r: 'release', args: "'--no-manual'"}
- { os: ubuntu-latest, r: 'devel', args: "c('--no-manual', '--test-dontrun')"}
- { os: ubuntu-latest, r: 'release', args: "c('--no-manual', '--as-cran')"}
- { os: ubuntu-latest, r: 'devel', args: "c('--no-manual', '--as-cran')"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
### MAINTENANCE
* Updated internal SQL translation to use `DBI` S4 generics (`DBI::dbQuoteIdentifier()` is now used instead of
`dbplyr::sql_escape_ident()` and `DBI::dbQuoteString()` instead of `dbplyr::sql_escape_string()`), to comply
with upcoming `dbplyr` 2.0 release (#225, #225; https://github.com/tidyverse/dbplyr/issues/385)
with upcoming `dbplyr` 2.0 release (#225, #225; https://github.com/tidyverse/dbplyr/issues/385)
* Wrapped all examples that call web resources in `try()` to avoid spurious check failures (#229).

# bcdata 0.2.0

Expand Down
57 changes: 39 additions & 18 deletions R/bcdc-web-services.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,45 @@
#'
#' \donttest{
#' # Returns a bcdc_promise, which can be further refined using filter/select:
#' bcdc_query_geodata("bc-airports", crs = 3857)
#' try(
#' bcdc_query_geodata("bc-airports", crs = 3857)
#' )
#'
#' # To obtain the actual data as an sf object, collect() must be called:
#' bcdc_query_geodata("bc-airports", crs = 3857) %>%
#' filter(PHYSICAL_ADDRESS == 'Victoria, BC') %>%
#' collect()
#'
#' bcdc_query_geodata("groundwater-wells") %>%
#' filter(OBSERVATION_WELL_NUMBER == 108) %>%
#' select(WELL_TAG_NUMBER, INTENDED_WATER_USE) %>%
#' collect()
#' try(
#' bcdc_query_geodata("bc-airports", crs = 3857) %>%
#' filter(PHYSICAL_ADDRESS == 'Victoria, BC') %>%
#' collect()
#' )
#'
#' try(
#' bcdc_query_geodata("groundwater-wells") %>%
#' filter(OBSERVATION_WELL_NUMBER == "108") %>%
#' select(WELL_TAG_NUMBER, INTENDED_WATER_USE) %>%
#' collect()
#' )
#'
#' ## A moderately large layer
#' bcdc_query_geodata("bc-environmental-monitoring-locations")
#' bcdc_query_geodata("bc-environmental-monitoring-locations") %>%
#' filter(PERMIT_RELATIONSHIP == "DISCHARGE")
#' try(
#' bcdc_query_geodata("bc-environmental-monitoring-locations")
#' )
#'
#' try(
#' bcdc_query_geodata("bc-environmental-monitoring-locations") %>%
#' filter(PERMIT_RELATIONSHIP == "DISCHARGE")
#' )
#'
#'
#' ## A very large layer
#' bcdc_query_geodata("terrestrial-protected-areas-representation-by-biogeoclimatic-unit")
#' try(
#' bcdc_query_geodata("terrestrial-protected-areas-representation-by-biogeoclimatic-unit")
#' )
#'
#' ## Using a BCGW name
#' bcdc_query_geodata("WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW")
#' try(
#' bcdc_query_geodata("WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW")
#' )
#' }
#'
#' @export
bcdc_query_geodata <- function(record, crs = 3005) {
if (!has_internet()) stop("No access to internet", call. = FALSE) # nocov
Expand Down Expand Up @@ -149,11 +163,18 @@ bcdc_query_geodata.bcdc_record <- function(record, crs = 3005) {
#'
#' @examples
#' \donttest{
#' bcdc_preview("regional-districts-legally-defined-administrative-areas-of-bc")
#' bcdc_preview("points-of-well-diversion-applications")
#' try(
#' bcdc_preview("regional-districts-legally-defined-administrative-areas-of-bc")
#' )
#'
#' try(
#' bcdc_preview("points-of-well-diversion-applications")
#' )
#'
#' # Using BCGW name
#' bcdc_preview("WHSE_LEGAL_ADMIN_BOUNDARIES.ABMS_REGIONAL_DISTRICTS_SP")
#' try(
#' bcdc_preview("WHSE_LEGAL_ADMIN_BOUNDARIES.ABMS_REGIONAL_DISTRICTS_SP")
#' )
#' }
#' @export
bcdc_preview <- function(record) { # nocov start
Expand Down
18 changes: 13 additions & 5 deletions R/bcdc_browse.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,24 @@
#' @examples
#' \donttest{
#' ## Take me to the B.C. Data Catalogue home page
#' bcdc_browse()
#' try(
#' bcdc_browse()
#' )
#'
#' ## Take me to the B.C. airports catalogue record
#' bcdc_browse("bc-airports")
#' try(
#' bcdc_browse("bc-airports")
#' )
#'
#'#' ## Take me to the B.C. airports catalogue record
#' bcdc_browse("76b1b7a3-2112-4444-857a-afccf7b20da8")
#' ## Take me to the B.C. airports catalogue record
#' try(
#' bcdc_browse("76b1b7a3-2112-4444-857a-afccf7b20da8")
#' )
#'
#' ## Take me to the catalogue search results for 'fish'
#' bcdc_browse("fish")
#' try(
#' bcdc_browse("fish")
#' )
#'
#' }
bcdc_browse <- function(query = NULL, browser = getOption("browser"),
Expand Down
23 changes: 17 additions & 6 deletions R/bcdc_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,31 @@
#' it is advisable to lower the chunk limit. Chunks must be less than 10000.
#'
#' @examples
#' \donttest{
#' ## Save initial conditions
#' original_options <- options()
#' try(
#' original_options <- options()
#' )
#'
#' ## See initial options
#' bcdc_options()
#' try(
#' bcdc_options()
#' )
#'
#' options(bcdata.max_geom_pred_size = 1E6)
#' try(
#' options(bcdata.max_geom_pred_size = 1E6)
#' )
#'
#' ## See updated options
#' bcdc_options()
#' try(
#' bcdc_options()
#' )
#'
#' ## Reset initial conditions
#' options(original_options)
#'
#' try(
#' options(original_options)
#' )
#' }
#' @export

bcdc_options <- function() {
Expand Down
47 changes: 38 additions & 9 deletions R/bcdc_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#'
#' @examples
#' \donttest{
#' bcdc_search_facets("type")
#' try(
#' bcdc_search_facets("type")
#' )
#' }
bcdc_search_facets <- function(facet = c("license_id", "download_audience",
"type", "res_format", "sector",
Expand Down Expand Up @@ -56,6 +58,12 @@ bcdc_search_facets <- function(facet = c("license_id", "download_audience",
#'
#' @return A character vector of the names of B.C. Data Catalogue records
#' @export
#' @examples
#' \donttest{
#' try(
#' bcdc_list()
#' )
#' }
bcdc_list <- function() {
if(!has_internet()) stop("No access to internet", call. = FALSE) # nocov

Expand Down Expand Up @@ -100,8 +108,13 @@ bcdc_list <- function() {
#'
#' @examples
#' \donttest{
#' bcdc_search("forest")
#' bcdc_search("regional district", type = "Geographic", res_format = "fgdb")
#' try(
#' bcdc_search("forest")
#' )
#'
#' try(
#' bcdc_search("regional district", type = "Geographic", res_format = "fgdb")
#' )
#' }
bcdc_search <- function(..., license_id = NULL,
download_audience = "Public",
Expand Down Expand Up @@ -178,10 +191,21 @@ bcdc_search <- function(..., license_id = NULL,
#'
#' @examples
#' \donttest{
#' bcdc_get_record("https://catalogue.data.gov.bc.ca/dataset/bc-airports")
#' bcdc_get_record("bc-airports")
#' bcdc_get_record("https://catalogue.data.gov.bc.ca/dataset/76b1b7a3-2112-4444-857a-afccf7b20da8")
#' bcdc_get_record("76b1b7a3-2112-4444-857a-afccf7b20da8")
#' try(
#' bcdc_get_record("https://catalogue.data.gov.bc.ca/dataset/bc-airports")
#' )
#'
#' try(
#' bcdc_get_record("bc-airports")
#' )
#'
#' try(
#' bcdc_get_record("https://catalogue.data.gov.bc.ca/dataset/76b1b7a3-2112-4444-857a-afccf7b20da8")
#' )
#'
#' try(
#' bcdc_get_record("76b1b7a3-2112-4444-857a-afccf7b20da8")
#' )
#' }
bcdc_get_record <- function(id) {

Expand Down Expand Up @@ -249,8 +273,13 @@ as.bcdc_recordlist <- function(x) {
#'
#' @examples
#' \donttest{
#' airports <- bcdc_get_record("bc-airports")
#' bcdc_tidy_resources(airports)
#' try(
#' airports <- bcdc_get_record("bc-airports")
#' )
#'
#' try(
#' bcdc_tidy_resources(airports)
#' )
#' }
#'
#' @export
Expand Down
6 changes: 4 additions & 2 deletions R/cql-geom-predicates.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ CQL <- function(...) {
#'
#' @examples
#' \donttest{
#' airports <- bcdc_query_geodata("bc-airports") %>% collect()
#' bcdc_cql_string(airports, "DWITHIN")
#' try({
#' airports <- bcdc_query_geodata("bc-airports") %>% collect()
#' bcdc_cql_string(airports, "DWITHIN")
#' })
#' }
#'
#' @noRd
Expand Down
9 changes: 7 additions & 2 deletions R/describe-feature.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
#'
#' @examples
#' \donttest{
#' bcdc_describe_feature("bc-airports")
#' bcdc_describe_feature("WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW")
#' try(
#' bcdc_describe_feature("bc-airports")
#' )
#'
#' try(
#' bcdc_describe_feature("WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW")
#' )
#' }
#'
#' @export
Expand Down
57 changes: 40 additions & 17 deletions R/get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,68 @@
#' @examples
#' \donttest{
#' # Using the record and resource ID:
#' bcdc_get_data(record = '76b1b7a3-2112-4444-857a-afccf7b20da8',
#' resource = '4d0377d9-e8a1-429b-824f-0ce8f363512c')
#' bcdc_get_data('1d21922b-ec4f-42e5-8f6b-bf320a286157')
#' try(
#' bcdc_get_data(record = '76b1b7a3-2112-4444-857a-afccf7b20da8',
#' resource = '4d0377d9-e8a1-429b-824f-0ce8f363512c')
#' )
#'
#' try(
#' bcdc_get_data('1d21922b-ec4f-42e5-8f6b-bf320a286157')
#' )
#'
#' # Using a `bcdc_record` object obtained from `bcdc_get_record`:
#' record <- bcdc_get_record('1d21922b-ec4f-42e5-8f6b-bf320a286157')
#' bcdc_get_data(record)
#' try(
#' record <- bcdc_get_record('1d21922b-ec4f-42e5-8f6b-bf320a286157')
#' )
#'
#' try(
#' bcdc_get_data(record)
#' )
#'
#' # Using a BCGW name
#' bcdc_get_data("WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW")
#' try(
#' bcdc_get_data("WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW")
#' )
#'
#' # Using sf's sql querying ability
#' bcdc_get_data(
#' record = '30aeb5c1-4285-46c8-b60b-15b1a6f4258b',
#' resource = '3d72cf36-ab53-4a2a-9988-a883d7488384',
#' layer = 'BC_Boundary_Terrestrial_Line',
#' query = "SELECT SHAPE_Length, geom FROM BC_Boundary_Terrestrial_Line WHERE SHAPE_Length < 100"
#' try(
#' bcdc_get_data(
#' record = '30aeb5c1-4285-46c8-b60b-15b1a6f4258b',
#' resource = '3d72cf36-ab53-4a2a-9988-a883d7488384',
#' layer = 'BC_Boundary_Terrestrial_Line',
#' query = "SELECT SHAPE_Length, geom FROM BC_Boundary_Terrestrial_Line WHERE SHAPE_Length < 100"
#' )
#' )
#'
#' ## Example of correcting import problems
#'
#' ## Some initial problems reading in the data
#' bcdc_get_data('d7e6c8c7-052f-4f06-b178-74c02c243ea4')
#' try(
#' bcdc_get_data('d7e6c8c7-052f-4f06-b178-74c02c243ea4')
#' )
#'
#' ## From bcdc_get_record we realize that the data is in xlsx format
#' bcdc_get_record('8620ce82-4943-43c4-9932-40730a0255d6')
#' try(
#' bcdc_get_record('8620ce82-4943-43c4-9932-40730a0255d6')
#' )
#'
#' ## bcdc_read_functions let's us know that bcdata
#' ## uses readxl::read_excel to import xlsx files
#' bcdc_read_functions()
#' try(
#' bcdc_read_functions()
#' )
#'
#' ## bcdata let's you know that this resource has
#' ## multiple worksheets
#' bcdc_get_data('8620ce82-4943-43c4-9932-40730a0255d6')
#' try(
#' bcdc_get_data('8620ce82-4943-43c4-9932-40730a0255d6')
#' )
#'
#' ## we can control what is read in from an excel file
#' ## using arguments from readxl::read_excel
#'
#' bcdc_get_data('8620ce82-4943-43c4-9932-40730a0255d6', sheet = 'Regional Districts')
#' try(
#' bcdc_get_data('8620ce82-4943-43c4-9932-40730a0255d6', sheet = 'Regional Districts')
#' )
#' }
#'
#' @export
Expand Down
Loading

0 comments on commit d780f10

Please sign in to comment.