From 49d57b1bdadf431dc4010f44d386f96211ba5c53 Mon Sep 17 00:00:00 2001 From: Sam Albers Date: Tue, 9 Sep 2025 14:09:42 -0700 Subject: [PATCH 1/4] add stations article --- hakaiApi/.Rbuildignore | 1 + hakaiApi/DESCRIPTION | 1 + hakaiApi/vignettes/articles/.gitignore | 4 ++ .../articles/Viewing-Recent-Stations.Rmd | 52 +++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 hakaiApi/vignettes/articles/.gitignore create mode 100644 hakaiApi/vignettes/articles/Viewing-Recent-Stations.Rmd diff --git a/hakaiApi/.Rbuildignore b/hakaiApi/.Rbuildignore index 5a94d9f..2d36ad0 100644 --- a/hakaiApi/.Rbuildignore +++ b/hakaiApi/.Rbuildignore @@ -6,3 +6,4 @@ ^_pkgdown\.yml$ ^docs$ ^pkgdown$ +^vignettes/articles$ diff --git a/hakaiApi/DESCRIPTION b/hakaiApi/DESCRIPTION index 958eb87..c76b643 100644 --- a/hakaiApi/DESCRIPTION +++ b/hakaiApi/DESCRIPTION @@ -37,3 +37,4 @@ Encoding: UTF-8 Language: en-CA RoxygenNote: 7.3.2 Config/testthat/edition: 3 +Config/Needs/website: rmarkdown diff --git a/hakaiApi/vignettes/articles/.gitignore b/hakaiApi/vignettes/articles/.gitignore new file mode 100644 index 0000000..9e2bd63 --- /dev/null +++ b/hakaiApi/vignettes/articles/.gitignore @@ -0,0 +1,4 @@ +*.html +*.R + +/.quarto/ diff --git a/hakaiApi/vignettes/articles/Viewing-Recent-Stations.Rmd b/hakaiApi/vignettes/articles/Viewing-Recent-Stations.Rmd new file mode 100644 index 0000000..413fbf7 --- /dev/null +++ b/hakaiApi/vignettes/articles/Viewing-Recent-Stations.Rmd @@ -0,0 +1,52 @@ +--- +title: "Viewing Recent Stations" +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +One of the endpoints accessed by the `hakaiApi` package is the stations endpoint. This endpoint provides metadata about stations, including their geographic coordinates. This information can be useful for visualizing the locations of stations on a map. In R we can either make static maps using `ggplot2` or interactive maps using `mapview` to quickly visualize the locations of stations. We need to install the `bcmaps` package to get a base map of British Columbia as well as the `sf` package to handle spatial data and the `ggplot2` and `mapview` packages for visualization. + +```{r setup} +library(hakaiApi) +library(ggplot2) +library(mapview) +library(bcmaps) +library(sf) +``` + +We first need to access the stations endpoint using the `Client` class from the `hakaiApi` package. We can then use the `get_stations` method to retrieve a data frame of stations. If you don't have the sf package installed you will prompted to install that at this point. + +```{r get-data} +hakai_client <- hakaiApi::Client$new("https://hecate.hakai.org/api") +stations <- hakai_client$get_stations() +``` + +Because we want to plot the stations and some sensible basemap, we need to created a clipped polygon of British Columbia that contains all the stations. We can do this by creating a bounding box around the stations and then using the `st_intersection` function from the `sf` package to clip the BC polygon to that bounding box. +```{r interaction} +#| warning=FALSE +bc <- bcmaps::bc_bound_hres() + +points_bbox <- st_bbox(stations) |> + st_as_sfc() |> + st_transform(st_crs(bc)) +clipped_polygon <- st_intersection(bc, points_bbox) +``` + +Once we have the clipped polygon, we can plot the stations on top of it using `ggplot2` or `mapview`. Here is an example of a static map using `ggplot2`: +```{r ggplot2} +ggplot() + + geom_sf(data = clipped_polygon) + + geom_sf(data = stations, aes(color = station_id), size = 3) + + theme_minimal() + + theme(legend.position = "bottom") +``` + +And here is an example of an interactive map using `mapview`: +```{r mapview, message=FALSE} +mapview::mapview(stations) +``` From d07c466c8cdd8a73fe8e6a72e3e616924c14dd7e Mon Sep 17 00:00:00 2001 From: Sam Albers Date: Tue, 9 Sep 2025 14:15:50 -0700 Subject: [PATCH 2/4] add needed packages --- .github/workflows/pkgdown.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 3d4d7b8..7db134a 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -36,7 +36,7 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::pkgdown, local::. + extra-packages: any::pkgdown, local::., bcmaps, sf, ggplot2 needs: website working-directory: hakaiApi From 1967cdaa6e8da196ad2c288bc465503c13c3be1a Mon Sep 17 00:00:00 2001 From: Sam Albers Date: Tue, 9 Sep 2025 14:42:18 -0700 Subject: [PATCH 3/4] workaround --- hakaiApi/data-raw/stations.rds | Bin 0 -> 1367 bytes .../articles/Viewing-Recent-Stations.Rmd | 6 ++++++ 2 files changed, 6 insertions(+) create mode 100644 hakaiApi/data-raw/stations.rds diff --git a/hakaiApi/data-raw/stations.rds b/hakaiApi/data-raw/stations.rds new file mode 100644 index 0000000000000000000000000000000000000000..8240b21c668cf1ce4b473a1ef12f004450bea942 GIT binary patch literal 1367 zcmV-d1*rNTiwFP!000001KpQvY*SSn!0+0-v6eU>0%}O0sm1~8#`@T!CWO1KrMp?_ z>e@YY*6woeX;;?XJMO*RTGV8L4c z7)jKOt^T|A^l<@=96x!J_TK;F{LcBG|Nq>3&VZ4kC_P12R#5s%c%&+OgFEY6LHF>o zfudH!Zv#bB2Dn$XCsV2<=B39vxcC^7RZ|a&AQ_1~G6hsljTIbLx;aHPm9?pKtHUUc zah-_gRD`9jj`pOK#*SSQN@LRsuOy8~NfmRu<%lE;rV@9o>fjQid6m&GC)Ht-OX5dx z4^JmKLFV$(+MEOwc?8u<^7gx)+Sd#qv*woYEU%Wn%gvTSp$&${XOLl zWq_7OyGtXN*;^eBmqsqw>0rQTD|xo#u=}AOr#%cT9CrUQ`EPSs1vw0;STg2p+4TLF zc{ApcRN|f2lw{4YoVEKV&5)DYCGY<_Q_HJw1Kexit~)tI9m(t!zGT>M6VpHLUj&Q} z^c8r@`8cO2`Sj}ZO5MOS*zE6SeZjn-S0YikEfvx9#_qB3Jj0$>9=+r5%%LkX4@e6y z?QylGMj7_&1C{fki=?z`)tf&}Ofl>icCPQadP3R|_3=BgJGUA3((}(|wmw2Sw#7@A zZy#KQdE53&-^K4pX@7Knzje!7414YPaeiHzG*bHY+Xuc{VAyk4Jtx+_Ksq+(Oyhyx z!wl;U&7PfknUvN%Tle^zPKNC|ee&#)GsKZT(Y7?T2C{IvEA)*(IyPU+n)JKX3|n(` z?7c-JF|BFGi?@ydZGQd1Ivr`Gx+nYIzrrx=+{nJSL$46i)_;)$S&yMZR{bJ6p%lHY{r@_k`bRlg@-YIT%r zEB^GjyFDE}fkAW5Y_=FpaJkxoy}Ljs$#KEtL6U&f7;g%s6%{2+R%gL4d%3+{)*t9* zT}4K-y`|M^Z?V{%tqr!O7Mso9)NC)d$X;Hz&lBwI^|8T0a{{R{GFz;nP$=i*?_qbj zp?{BzkT@RWhs~D8V)Hhi$Lr3u6i^ggz}nDgZE-Z&ZBAR0)#-HD?HJV&7)0@SY*dkA z0vET~LM5C57UGWL=;Ck!Qj-EQZH5EI7PCc^WOcZF(A_;Qch8_TRIdG3dEZsy^zPkKD!m|V?tiDQbD33$zc)lj!zs=1lj6O zYiC22#v5=(vWs0e0e_iH=DOBViG+D6o=k|EA>NOy=b|$F7nl=;8K$*q`-ce1xm9sA zhT_`8Of@fwKoM~b8Mr9aX|#9-t&RyugmtIgITx@Ij?bR%?=CK!OPvzIzUuCHSiq7V ZBpisqsa!)uhWX5b{sLC{LhU;d000OazQO Date: Tue, 9 Sep 2025 14:52:14 -0700 Subject: [PATCH 4/4] try that --- hakaiApi/vignettes/articles/Viewing-Recent-Stations.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hakaiApi/vignettes/articles/Viewing-Recent-Stations.Rmd b/hakaiApi/vignettes/articles/Viewing-Recent-Stations.Rmd index 2ea4950..88dd703 100644 --- a/hakaiApi/vignettes/articles/Viewing-Recent-Stations.Rmd +++ b/hakaiApi/vignettes/articles/Viewing-Recent-Stations.Rmd @@ -29,7 +29,7 @@ stations <- hakai_client$get_stations() ```{r get-data-actually} #| echo: FALSE -stations <- readRDS("data-raw/stations.rds") +stations <- readRDS("../../data-raw/stations.rds") ``` Because we want to plot the stations and some sensible basemap, we need to created a clipped polygon of British Columbia that contains all the stations. We can do this by creating a bounding box around the stations and then using the `st_intersection` function from the `sf` package to clip the BC polygon to that bounding box.