Skip to content

Commit 5af522b

Browse files
authored
Merge pull request #359 from bcgov/format-air
Use air
2 parents c93f573 + 749252b commit 5af522b

47 files changed

Lines changed: 1378 additions & 754 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
^depends\.Rds$
2222
^revdep$
2323
^CRAN-SUBMISSION$
24+
^[\.]?air\.toml$
25+
^\.vscode$

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"Posit.air-vscode"
4+
]
5+
}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"[r]": {
3+
"editor.formatOnSave": true,
4+
"editor.defaultFormatter": "Posit.air-vscode"
5+
}
6+
}

R/bcdata-package.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
# See the License for the specific language governing permissions and limitations under the License.
1212

13-
1413
#' @keywords internal
1514
#'
1615
"_PACKAGE"
@@ -21,7 +20,7 @@ NULL
2120

2221
release_bullets <- function() {
2322
c(
24-
"Run test and check with internet turned off",
23+
"Run test and check with internet turned off",
2524
"Precompile vignettes"
2625
)
2726
}

R/bcdc-get-citation.R

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,29 @@ bcdc_get_citation <- function(record) {
5151

5252
#' @export
5353
bcdc_get_citation.default <- function(record) {
54-
stop("No bcdc_get_citation method for an object of class ", class(record),
55-
call. = FALSE)
54+
stop(
55+
"No bcdc_get_citation method for an object of class ",
56+
class(record),
57+
call. = FALSE
58+
)
5659
}
5760

5861
#' @export
5962
bcdc_get_citation.character <- function(record) {
60-
6163
if (grepl("/resource/", record)) {
6264
# A full url was passed including record and resource compenents.
6365
# Grab the resource id and strip it off the url
6466
resource <- slug_from_url(record)
6567
record <- gsub("/resource/.+", "", record)
6668
}
6769

68-
6970
rec <- bcdc_get_record(record)
7071

7172
bcdc_get_citation(rec)
72-
7373
}
7474

7575
#' @export
7676
bcdc_get_citation.bcdc_record <- function(record) {
77-
7877
bib_rec <- utils::bibentry(
7978
bibtype = "techreport",
8079
title = record$title,
@@ -87,9 +86,7 @@ bcdc_get_citation.bcdc_record <- function(record) {
8786
note = record$license_title
8887
)
8988

90-
structure(bib_rec,
91-
class = c("citation", setdiff(class(bib_rec), "citation"))
92-
)
89+
structure(bib_rec, class = c("citation", setdiff(class(bib_rec), "citation")))
9390
}
9491

9592
clean_org_name <- function(rec) {

R/bcdc-web-services.R

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
# See the License for the specific language governing permissions and limitations under the License.
1212

13-
1413
#' Query data from the B.C. Web Feature Service
1514
#'
1615
#' Queries features from the B.C. Web Feature Service. See
@@ -60,7 +59,7 @@
6059
#' res <- bcdc_query_geodata("bc-airports") %>%
6160
#' filter(PHYSICAL_ADDRESS %LIKE% 'Vict%')
6261
#' )
63-
#'
62+
#'
6463
#' # To query using %IN%
6564
#' try(
6665
#' res <- bcdc_query_geodata("bc-airports") %>%
@@ -111,13 +110,15 @@ bcdc_query_geodata <- function(record, crs = 3005) {
111110

112111
#' @export
113112
bcdc_query_geodata.default <- function(record, crs = 3005) {
114-
stop("No bcdc_query_geodata method for an object of class ", class(record),
115-
call. = FALSE)
113+
stop(
114+
"No bcdc_query_geodata method for an object of class ",
115+
class(record),
116+
call. = FALSE
117+
)
116118
}
117119

118120
#' @export
119121
bcdc_query_geodata.character <- function(record, crs = 3005) {
120-
121122
if (length(record) != 1) {
122123
stop("Only one record my be queried at a time.", call. = FALSE)
123124
}
@@ -137,8 +138,12 @@ bcdc_query_geodata.character <- function(record, crs = 3005) {
137138
cols_df <- feature_helper(record)
138139

139140
return(
140-
as.bcdc_promise(list(query_list = query_list, cli = cli, record = NULL,
141-
cols_df = cols_df))
141+
as.bcdc_promise(list(
142+
query_list = query_list,
143+
cli = cli,
144+
record = NULL,
145+
cols_df = cols_df
146+
))
142147
)
143148
}
144149

@@ -156,8 +161,9 @@ bcdc_query_geodata.character <- function(record, crs = 3005) {
156161
#' @export
157162
bcdc_query_geodata.bcdc_record <- function(record, crs = 3005) {
158163
if (!any(wfs_available(record$resource_df))) {
159-
stop("No Web Feature Service resource available for this data set.",
160-
call. = FALSE
164+
stop(
165+
"No Web Feature Service resource available for this data set.",
166+
call. = FALSE
161167
)
162168
}
163169

@@ -170,7 +176,9 @@ bcdc_query_geodata.bcdc_record <- function(record, crs = 3005) {
170176
))
171177

172178
if (grepl("_SP?G$", layer_name)) {
173-
message("You are accessing a simplified view of the data - see the catalogue record for details.")
179+
message(
180+
"You are accessing a simplified view of the data - see the catalogue record for details."
181+
)
174182
}
175183

176184
## Parameters for the API call
@@ -184,8 +192,12 @@ bcdc_query_geodata.bcdc_record <- function(record, crs = 3005) {
184192

185193
cols_df <- feature_helper(query_list$typeNames)
186194

187-
as.bcdc_promise(list(query_list = query_list, cli = cli, record = record,
188-
cols_df = cols_df))
195+
as.bcdc_promise(list(
196+
query_list = query_list,
197+
cli = cli,
198+
record = record,
199+
cols_df = cols_df
200+
))
189201
}
190202

191203
#' Get preview map from the B.C. Web Map Service
@@ -213,20 +225,23 @@ bcdc_query_geodata.bcdc_record <- function(record, crs = 3005) {
213225
#' )
214226
#' }
215227
#' @export
216-
bcdc_preview <- function(record) { # nocov start
228+
bcdc_preview <- function(record) {
229+
# nocov start
217230
if (!has_internet()) stop("No access to internet", call. = FALSE)
218231
UseMethod("bcdc_preview")
219232
}
220233

221234
#' @export
222235
bcdc_preview.default <- function(record) {
223-
stop("No bcdc_preview method for an object of class ", class(record),
224-
call. = FALSE)
236+
stop(
237+
"No bcdc_preview method for an object of class ",
238+
class(record),
239+
call. = FALSE
240+
)
225241
}
226242

227243
#' @export
228244
bcdc_preview.character <- function(record) {
229-
230245
if (is_whse_object_name(record)) {
231246
make_wms(record)
232247
} else {
@@ -236,30 +251,36 @@ bcdc_preview.character <- function(record) {
236251

237252
#' @export
238253
bcdc_preview.bcdc_record <- function(record) {
239-
240254
wfs_resource <- get_wfs_resource_from_record(record)
241255

242256
make_wms(basename(dirname(wfs_resource$url)))
243-
244257
}
245258

246-
make_wms <- function(x){
259+
make_wms <- function(x) {
247260
wms_url <- wms_base_url()
248-
wms_options <- leaflet::WMSTileOptions(format = "image/png",
249-
transparent = TRUE,
250-
attribution = "BC Data Catalogue (https://catalogue.data.gov.bc.ca/)")
251-
wms_legend <- glue::glue("{wms_url}?request=GetLegendGraphic&
261+
wms_options <- leaflet::WMSTileOptions(
262+
format = "image/png",
263+
transparent = TRUE,
264+
attribution = "BC Data Catalogue (https://catalogue.data.gov.bc.ca/)"
265+
)
266+
wms_legend <- glue::glue(
267+
"{wms_url}?request=GetLegendGraphic&
252268
format=image%2Fpng&
253269
width=20&
254270
height=20&
255-
layer=pub%3A{x}")
271+
layer=pub%3A{x}"
272+
)
256273

257274
leaflet::leaflet() %>%
258-
leaflet::addProviderTiles(leaflet::providers$CartoDB.Positron,
259-
options = leaflet::providerTileOptions(noWrap = TRUE)) %>%
260-
leaflet::addWMSTiles(wms_url,
261-
layers=glue::glue("pub:{x}"),
262-
options = wms_options) %>%
275+
leaflet::addProviderTiles(
276+
leaflet::providers$CartoDB.Positron,
277+
options = leaflet::providerTileOptions(noWrap = TRUE)
278+
) %>%
279+
leaflet::addWMSTiles(
280+
wms_url,
281+
layers = glue::glue("pub:{x}"),
282+
options = wms_options
283+
) %>%
263284
leaflet.extras::addWMSLegend(uri = wms_legend) %>%
264285
leaflet::setView(lng = -126.5, lat = 54.5, zoom = 5)
265286
} # nocov end
@@ -275,4 +296,3 @@ make_query_list <- function(layer_name, crs) {
275296
SRSNAME = paste0("EPSG:", crs)
276297
)
277298
}
278-

R/bcdc_browse.R

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,25 @@
4444
#' bcdc_browse("76b1b7a3-2112-4444-857a-afccf7b20da8")
4545
#' )
4646
#' }
47-
bcdc_browse <- function(query = NULL, browser = getOption("browser"),
48-
encodeIfNeeded = FALSE) {
49-
if(!has_internet()) stop("No access to internet", call. = FALSE) # nocov
47+
bcdc_browse <- function(
48+
query = NULL,
49+
browser = getOption("browser"),
50+
encodeIfNeeded = FALSE
51+
) {
52+
if (!has_internet()) stop("No access to internet", call. = FALSE) # nocov
5053

5154
base_url <- catalogue_base_url()
5255

53-
if (is.null(query)) {
56+
if (is.null(query)) {
5457
url <- base_url
5558
} else {
56-
5759
## Check if the record is valid, if not return a query.
5860
# Need to check via HEAD request to the api as the catalogue
5961
# doesn't return a 404 status code.
6062
cli <- bcdc_catalogue_client("action/package_show")
6163
res <- cli$head(query = list(id = query))
6264

63-
if(res$status_code == 404){
65+
if (res$status_code == 404) {
6466
stop("The specified record does not exist in the catalogue")
6567
## NB - previous version would show a catalogue search in the
6668
## browser, but with new catalogue it doesn't seem possible
@@ -73,14 +75,15 @@ bcdc_browse <- function(query = NULL, browser = getOption("browser"),
7375
}
7476

7577
## Facilitates testing
76-
if(interactive()){
78+
if (interactive()) {
7779
# nocov start
78-
utils::browseURL(url = url, browser = browser,
79-
encodeIfNeeded = encodeIfNeeded)
80+
utils::browseURL(
81+
url = url,
82+
browser = browser,
83+
encodeIfNeeded = encodeIfNeeded
84+
)
8085
# nocov end
8186
}
8287

8388
invisible(url)
8489
}
85-
86-

0 commit comments

Comments
 (0)