From c9fc58071124172f2047e5f531ec2e76fbd56067 Mon Sep 17 00:00:00 2001 From: Eva Marques Date: Wed, 12 Jun 2024 09:23:25 -0400 Subject: [PATCH 1/8] debug again --- LICENSE.txt => LICENSE | 0 R/download_ghcnh.R | 3 ++- R/plot_cws.R | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) rename LICENSE.txt => LICENSE (100%) diff --git a/LICENSE.txt b/LICENSE similarity index 100% rename from LICENSE.txt rename to LICENSE diff --git a/R/download_ghcnh.R b/R/download_ghcnh.R index ba90208..c8f8847 100644 --- a/R/download_ghcnh.R +++ b/R/download_ghcnh.R @@ -113,6 +113,7 @@ download_ghcnh_station <- function(site_id, year) { #' @param te end date #' @param area a sf, sfc, SpatRaster or SpatVector object #' @return a data.frame with the GHCN-H stations observations in the area +#' @importFrom dplyr between download_ghcnh <- function(ts, te, area) { stopifnot( "ts and te should be POSIXct objects" = @@ -143,7 +144,7 @@ download_ghcnh <- function(ts, te, area) { return(NULL) } else { ghcnh <- format_ghcnh(ghcnh) - ghcnh <- ghcnh[which(between(ghcnh$time, ts, te)), ] + ghcnh <- ghcnh[which(dplyr::between(ghcnh$time, ts, te)), ] return(ghcnh) } } diff --git a/R/plot_cws.R b/R/plot_cws.R index 0650310..ee69c03 100644 --- a/R/plot_cws.R +++ b/R/plot_cws.R @@ -301,11 +301,11 @@ map_observations_imp <- function(data, scale_fill_gradientn(colours = c("white", "grey"), na.value = NA) + tidyterra::scale_color_whitebox_c( palette = "bl_yl_rd", - labels = scales::label_number(suffix = paste0("ºC")), + labels = scales::label_number(suffix = paste0("C")), n.breaks = 12, guide = guide_legend(reverse = TRUE) ) + - guides(fill = guide_legend(title = "Imperviousness (%)")) + + guides(fill = guide_legend(title = "Imperviousness")) + labs( title = title, subtitle = date From e7b94b93f9bae8ba5df629099a976238902478ee Mon Sep 17 00:00:00 2001 From: Eva Marques Date: Wed, 12 Jun 2024 10:16:06 -0400 Subject: [PATCH 2/8] debuuuuug --- NAMESPACE | 30 ++++++++++++++++++++++++------ R/calib_cws.R | 2 ++ R/class_hourly_temp.R | 2 ++ R/clean_cws.R | 3 ++- R/download_ghcnh.R | 5 ++--- R/download_purpleair.R | 17 +++++++++++++++-- R/estimate_measurement_error.R | 1 + R/format_observations.R | 5 +++++ R/generate_unique_site_id.R | 12 ++++++------ R/load_weatherunderground.R | 2 +- R/plot_cws.R | 12 ++++++------ man/hourly_boxplot_networks.Rd | 2 +- 12 files changed, 67 insertions(+), 26 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index abb4d54..42cb8aa 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,18 +16,36 @@ export(plot_ts_ref) export(request_sensor_history) export(summarize_hourly_temp) export(tile_ts) -import(RCurl) -import(data.table) -import(dplyr) import(ggplot2) import(ggspatial) import(httr) import(sftime) -import(stats) -import(tidyr) -import(tidyterra) import(utils) +importFrom(RCurl,url.exists) +importFrom(data.table,as.data.table) +importFrom(data.table,data.table) +importFrom(data.table,fread) +importFrom(dplyr,between) +importFrom(dplyr,filter) +importFrom(dplyr,group_by) +importFrom(dplyr,n) +importFrom(dplyr,rename) +importFrom(dplyr,summarise) +importFrom(dplyr,summarize) +importFrom(dplyr,ungroup) importFrom(jsonlite,fromJSON) importFrom(lubridate,floor_date) +importFrom(lubridate,with_tz) importFrom(methods,new) +importFrom(sf,st_bbox) importFrom(stats,median) +importFrom(stats,quantile) +importFrom(terra,as.polygons) +importFrom(terra,mask) +importFrom(terra,project) +importFrom(terra,vect) +importFrom(tidyr,drop_na) +importFrom(tidyterra,geom_spatraster) +importFrom(tidyterra,geom_spatraster_contour) +importFrom(tidyterra,geom_spatvector) +importFrom(tidyterra,scale_color_whitebox_c) diff --git a/R/calib_cws.R b/R/calib_cws.R index 78ff740..4fde687 100644 --- a/R/calib_cws.R +++ b/R/calib_cws.R @@ -8,6 +8,8 @@ #' @return a list with the calibrated observations, the average bias, #' the number of reference stations used to compute the bias, and the #' start and end time of the observations. +#' @importFrom dplyr filter group_by summarise ungroup +#' @importFrom stats median calib_cws <- function(x, ref, max_dist = 10000) { temp_err <- site_id <- geometry <- network <- temp <- dist_to_ref <- NULL stopifnot( diff --git a/R/class_hourly_temp.R b/R/class_hourly_temp.R index 6272d93..3edfac0 100644 --- a/R/class_hourly_temp.R +++ b/R/class_hourly_temp.R @@ -3,6 +3,7 @@ setClass("hourly_temp", contains = c("data.frame") ) + setValidity("hourly_temp", function(object) { stopifnot( "object is not a data.frame" = @@ -41,6 +42,7 @@ setValidity("hourly_temp", function(object) { #' @param network the name of the network #' @return a hourly_temp object #' @importFrom methods new +#' @importFrom dplyr rename #' @author Eva Marques hourly_temp <- function(x, temp = "temp", diff --git a/R/clean_cws.R b/R/clean_cws.R index e2968d8..c3bea04 100644 --- a/R/clean_cws.R +++ b/R/clean_cws.R @@ -2,7 +2,7 @@ #' @param data formatted sftime (with columns: site_id, temp, time) #' @param na_thresh threshold of NA to remove a station (0 <= na_tresh <= 1) #' @return cleaned data.frame -#' @import dplyr +#' @importFrom dplyr group_by n summarize manage_na <- function(data, na_thresh = 0.1) { stopifnot( "threshold must be between 0 and 1" = @@ -93,6 +93,7 @@ clean_cws <- function(x) { #' @param epsg_m crs in meters (default: epsg:32119) #' @param res resolution of the squares in meters (default: 100km) #' @return sf of polygons +#' @importFrom terra vect project mask as.polygons cut_area <- function(area, epsg_m = "epsg:32119", res = 100000) { # project area with a crs in meters area_m <- area |> diff --git a/R/download_ghcnh.R b/R/download_ghcnh.R index c8f8847..4797a51 100644 --- a/R/download_ghcnh.R +++ b/R/download_ghcnh.R @@ -71,9 +71,8 @@ find_nearest_ghcnh <- function(lat, lon) { #' @return a data.frame with the GHCN-H station raw data #' @author Eva Marques #' @export -#' @import RCurl -#' @import tidyr -#' @import dplyr +#' @importFrom RCurl url.exists +#' @importFrom tidyr drop_na #' @import utils download_ghcnh_station <- function(site_id, year) { temperature <- NULL diff --git a/R/download_purpleair.R b/R/download_purpleair.R index 0aa9822..93a08e5 100644 --- a/R/download_purpleair.R +++ b/R/download_purpleair.R @@ -95,7 +95,18 @@ request_sensor_history <- function(start_ts, } } - +#' Load PurpleAir sensors history data +#' @param nwlat North-west latitude +#' @param selat South-east latitude +#' @param nwlng North-west longitude +#' @param selng South-east longitude +#' @param location_type Location type +#' @param start_ts Start timestamp +#' @param end_ts End timestamp +#' @param api_key API key for PurpleAir +#' @param average Average time in minutes +#' @param fields Fields to be included in the data +#' @return A data frame with sensors history data request_sensors_history <- function(nwlat, selat, nwlng, @@ -147,12 +158,12 @@ request_sensors_history <- function(nwlat, } } -# to be tested #' Download all PurpleAir stations data in area between two dates #' @param ts start date #' @param te end date #' @param area a sf, sfc, SpatRaster or SpatVector object #' @param api_key API key for PurpleAir +#' @importFrom sf st_bbox download_pa <- function(ts, te, area, api_key) { bounds <- area |> format_area() |> @@ -177,6 +188,8 @@ download_pa <- function(ts, te, area, api_key) { #' @param storage_file file path where PurpleAir data is stored #' @param api_key API key for PurpleAir #' @import utils +#' @importFrom data.table data.table +#' @importFrom dplyr between load_pa <- function(ts, te, area, storage_file = NULL, api_key = NULL) { if (is.null(storage_file)) { pa <- download_pa(ts, te, area, api_key) diff --git a/R/estimate_measurement_error.R b/R/estimate_measurement_error.R index e954cc7..2d7f0bd 100644 --- a/R/estimate_measurement_error.R +++ b/R/estimate_measurement_error.R @@ -43,6 +43,7 @@ find_closest_ref <- function(cws, ref) { #' with columns site_id and geometry #' @return sf (or inherited) object with additional columns temp_ref, temp_err, #' ref_id, dist_to_ref +#' @importFrom dplyr rename est_temp_error <- function(cws, ref) { # check column names cols <- c("site_id", "temp", "geometry", "time") diff --git a/R/format_observations.R b/R/format_observations.R index d60336d..4e92c10 100644 --- a/R/format_observations.R +++ b/R/format_observations.R @@ -10,6 +10,8 @@ #' @author Eva Marques #' @importFrom lubridate floor_date #' @importFrom stats median +#' @importFrom dplyr group_by summarise ungroup +#' @importFrom data.table as.data.table #' @export summarize_hourly_temp <- function(x, time, temp, lat, lon) { stopifnot( @@ -47,6 +49,7 @@ summarize_hourly_temp <- function(x, time, temp, lat, lon) { #' @param raw_temp_unit the initial temperature unit #' @param raw_crs the initial coordinate reference system #' @return sftime from hourly_temp class +#' @importFrom lubridate with_tz floor_date #' @author Eva Marques #' @export format_pa <- function(raw, @@ -92,6 +95,7 @@ format_pa <- function(raw, #' @param raw_temp_unit the initial temperature unit #' @param raw_crs the initial coordinate reference system #' @return sftime from hourly_temp class +#' @importFrom lubridate floor_date #' @author Eva Marques #' @export format_wu <- function(raw, @@ -141,6 +145,7 @@ format_wu <- function(raw, #' and columns "Year", "Month", "Day", "Hour", "temperature", "Latitude", #' "Longitude", "temperature_Source_Code" #' @return sftime from hourly_temp class +#' @importFrom dplyr rename #' @author Eva Marques #' @export format_ghcnh <- function(raw) { diff --git a/R/generate_unique_site_id.R b/R/generate_unique_site_id.R index feacf34..cf375d3 100644 --- a/R/generate_unique_site_id.R +++ b/R/generate_unique_site_id.R @@ -1,9 +1,9 @@ -# ` @title Generate unique sensor ID -# ` @description This function generates a unique sensor "id" column based on -# ` the latitude and longitude of the sensor. -# ` @param x A data.frame, data.table, sf or sftime with columns "lat" and "lon" -# ` @return A data frame with an additional column "id" -# ` @author Eva Marques +#' @title Generate unique sensor ID +#' @description This function generates a unique sensor "id" column based on +#' the latitude and longitude of the sensor. +#' @param x A data.frame, data.table, sf or sftime with columns "lat" and "lon" +#' @return A data frame with an additional column "id" +#' @author Eva Marques generate_site_id <- function(x) { stopifnot( "lat and lon columns are missing" = diff --git a/R/load_weatherunderground.R b/R/load_weatherunderground.R index 83c816c..c9aa30c 100644 --- a/R/load_weatherunderground.R +++ b/R/load_weatherunderground.R @@ -4,7 +4,7 @@ #' @param area Area of interest #' @param inventory an sf object with inventory of #' @return a data.table with the raw WU data -#' @import data.table +#' @importFrom data.table fread #' @author Eva Marques #' Weather Underground stations (see create_wu_inventory function) load_wu <- function(ts, te, area, inventory) { diff --git a/R/plot_cws.R b/R/plot_cws.R index ee69c03..cae0e25 100644 --- a/R/plot_cws.R +++ b/R/plot_cws.R @@ -177,10 +177,10 @@ tile_ts <- function(data) { #' @param data data frame or sftime with all the network, contains "network" #' column #' @param var continuous variable to boxplot (in general: temp) -#' @return A ggplo2 object with the boxplots +#' @return A ggplot2 object with the boxplots #' @export #' @import ggplot2 -#' @import stats +#' @importFrom stats quantile #' @author Eva Marques hourly_boxplot_networks <- function(data, var) { network <- NULL @@ -223,7 +223,7 @@ hourly_boxplot_networks <- function(data, var) { #' @import ggplot2 #' @import ggspatial -#' @import tidyterra +#' @importFrom tidyterra geom_spatvector map_observations <- function(data, var, background, @@ -276,7 +276,7 @@ map_observations <- function(data, #' @import ggplot2 #' @import ggspatial -#' @import tidyterra +#' @importFrom tidyterra geom_spatraster scale_color_whitebox_c map_observations_imp <- function(data, var, imp, @@ -335,8 +335,8 @@ map_observations_imp <- function(data, #' @import ggplot2 #' @import ggspatial -#' @import tidyterra -#' @import stats +#' @importFrom tidyterra geom_spatraster geom_spatraster_contour +#' @importFrom stats quantile map_observations_hw <- function(data, var, imp, diff --git a/man/hourly_boxplot_networks.Rd b/man/hourly_boxplot_networks.Rd index 48fef62..278c777 100644 --- a/man/hourly_boxplot_networks.Rd +++ b/man/hourly_boxplot_networks.Rd @@ -13,7 +13,7 @@ column} \item{var}{continuous variable to boxplot (in general: temp)} } \value{ -A ggplo2 object with the boxplots +A ggplot2 object with the boxplots } \description{ Hourly boxplot of temperature for per network (network) From 1c7af75d1ab193e481bd5560828e8b87850e95ed Mon Sep 17 00:00:00 2001 From: Eva Marques Date: Wed, 12 Jun 2024 10:24:46 -0400 Subject: [PATCH 3/8] fix linting --- R/calib_cws.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/calib_cws.R b/R/calib_cws.R index 4fde687..20ae5d8 100644 --- a/R/calib_cws.R +++ b/R/calib_cws.R @@ -12,6 +12,7 @@ #' @importFrom stats median calib_cws <- function(x, ref, max_dist = 10000) { temp_err <- site_id <- geometry <- network <- temp <- dist_to_ref <- NULL + hour <- NULL stopifnot( "max_dist must be between 0 and 20000" = max_dist > 0 & max_dist <= 20000 From 032767a69535bd31e40c2a638d05179dfd5c1519 Mon Sep 17 00:00:00 2001 From: Eva Marques Date: Wed, 12 Jun 2024 14:30:55 -0400 Subject: [PATCH 4/8] Update README.md Add some references --- README.md | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e865487..4cf53f2 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,30 @@ # brassens -The development of this library is in progress +The development of this library is in progress. -## A package to deal with Citizen Weather Stationsdata +## A package to deal with Citizen Weather Stations temperature data - calls to PurpleAir API from R session to recover timeseries of temperature on a given spatial area -- cleaning non-conventional measurements of temperature with statistical tools +- formatting data +- cleaning non-conventional measurements of temperature with statistical tools (CrowdQC+ library) +- calibration with reference stations (GHCNh dataset used by default) - ## Directory structure - `./R`: R functions - `./vignettes`: illustrative examples of milestone analyses - `./tests/testthat`: testing routines for R code +## References + +CrowdQC+ library: +Fenner, D., Bechtel, B., Demuzere, M., Kittner, J. and Meier, F. (2021): CrowdQC+ – A quality-control for crowdsourced air-temperature observations enabling world-wide urban climate applications. Frontiers in Environmental Science 9: 720747. DOI: 10.3389/fenvs.2021.720747. + +Global Historical Climatology Network - hourly: +Menne, Matthew J.; Noone, Simon; Casey, Nancy W.; Dunn, Robert H.; McNeill, Shelley; Kantor, Diana; Thorne, Peter W.; Orcutt, Karen; Cunningham, Sam; Risavi, Nicholas. 2023. Global Historical Climatology Network-Hourly (GHCNh). NOAA National Centers for Environmental Information. https://doi.org/DOI. [2024/06/12] + +PurpleAir data download functions adapted from +Callahan J, Martin H, Wilson K, Brasel T, Miller H (2023). AirSensor: Process and Display Data from Air Quality Sensors. R package version 1.1.1, https://CRAN.R-project.org/package=AirSensor. + +PurpleAir: https://www2.purpleair.com +WeatherUnderground: https://www.wunderground.com + From 99235e14899b73945580ebd6d1c07228e2499274 Mon Sep 17 00:00:00 2001 From: Eva Marques Date: Wed, 12 Jun 2024 14:31:12 -0400 Subject: [PATCH 5/8] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4cf53f2..5c2e8b1 100644 --- a/README.md +++ b/README.md @@ -15,16 +15,16 @@ The development of this library is in progress. ## References -CrowdQC+ library: +CrowdQC+ library: Fenner, D., Bechtel, B., Demuzere, M., Kittner, J. and Meier, F. (2021): CrowdQC+ – A quality-control for crowdsourced air-temperature observations enabling world-wide urban climate applications. Frontiers in Environmental Science 9: 720747. DOI: 10.3389/fenvs.2021.720747. -Global Historical Climatology Network - hourly: +Global Historical Climatology Network - hourly: Menne, Matthew J.; Noone, Simon; Casey, Nancy W.; Dunn, Robert H.; McNeill, Shelley; Kantor, Diana; Thorne, Peter W.; Orcutt, Karen; Cunningham, Sam; Risavi, Nicholas. 2023. Global Historical Climatology Network-Hourly (GHCNh). NOAA National Centers for Environmental Information. https://doi.org/DOI. [2024/06/12] -PurpleAir data download functions adapted from +PurpleAir data download functions adapted from Callahan J, Martin H, Wilson K, Brasel T, Miller H (2023). AirSensor: Process and Display Data from Air Quality Sensors. R package version 1.1.1, https://CRAN.R-project.org/package=AirSensor. -PurpleAir: https://www2.purpleair.com +PurpleAir: https://www2.purpleair.com WeatherUnderground: https://www.wunderground.com From a92b3d2e6d175a47ab1b282c1dc67576e69bfb02 Mon Sep 17 00:00:00 2001 From: Eva Marques Date: Wed, 12 Jun 2024 14:32:46 -0400 Subject: [PATCH 6/8] Update README.md --- README.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5c2e8b1..925ed25 100644 --- a/README.md +++ b/README.md @@ -15,16 +15,14 @@ The development of this library is in progress. ## References -CrowdQC+ library: +**CrowdQC+ library** Fenner, D., Bechtel, B., Demuzere, M., Kittner, J. and Meier, F. (2021): CrowdQC+ – A quality-control for crowdsourced air-temperature observations enabling world-wide urban climate applications. Frontiers in Environmental Science 9: 720747. DOI: 10.3389/fenvs.2021.720747. -Global Historical Climatology Network - hourly: -Menne, Matthew J.; Noone, Simon; Casey, Nancy W.; Dunn, Robert H.; McNeill, Shelley; Kantor, Diana; Thorne, Peter W.; Orcutt, Karen; Cunningham, Sam; Risavi, Nicholas. 2023. Global Historical Climatology Network-Hourly (GHCNh). NOAA National Centers for Environmental Information. https://doi.org/DOI. [2024/06/12] +**Global Historical Climatology Network - hourly** +Menne, Matthew J.; Noone, Simon; Casey, Nancy W.; Dunn, Robert H.; McNeill, Shelley; Kantor, Diana; Thorne, Peter W.; Orcutt, Karen; Cunningham, Sam; Risavi, Nicholas. 2023. Global Historical Climatology Network-Hourly (GHCNh). NOAA National Centers for Environmental Information. https://doi.org/DOI. [accessed on 2024/06/12] -PurpleAir data download functions adapted from +**PurpleAir data download functions adapted from** Callahan J, Martin H, Wilson K, Brasel T, Miller H (2023). AirSensor: Process and Display Data from Air Quality Sensors. R package version 1.1.1, https://CRAN.R-project.org/package=AirSensor. -PurpleAir: https://www2.purpleair.com -WeatherUnderground: https://www.wunderground.com - - +**PurpleAir:** https://www2.purpleair.com +**WeatherUnderground:** https://www.wunderground.com From 531a00636ca60f848afc008a55d22031b5b48e24 Mon Sep 17 00:00:00 2001 From: Eva Marques Date: Wed, 12 Jun 2024 14:36:08 -0400 Subject: [PATCH 7/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 925ed25..0048c8e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ The development of this library is in progress. Fenner, D., Bechtel, B., Demuzere, M., Kittner, J. and Meier, F. (2021): CrowdQC+ – A quality-control for crowdsourced air-temperature observations enabling world-wide urban climate applications. Frontiers in Environmental Science 9: 720747. DOI: 10.3389/fenvs.2021.720747. **Global Historical Climatology Network - hourly** -Menne, Matthew J.; Noone, Simon; Casey, Nancy W.; Dunn, Robert H.; McNeill, Shelley; Kantor, Diana; Thorne, Peter W.; Orcutt, Karen; Cunningham, Sam; Risavi, Nicholas. 2023. Global Historical Climatology Network-Hourly (GHCNh). NOAA National Centers for Environmental Information. https://doi.org/DOI. [accessed on 2024/06/12] +Menne, Matthew J.; Noone, Simon; Casey, Nancy W.; Dunn, Robert H.; McNeill, Shelley; Kantor, Diana; Thorne, Peter W.; Orcutt, Karen; Cunningham, Sam; Risavi, Nicholas. 2023. Global Historical Climatology Network-Hourly (GHCNh). NOAA National Centers for Environmental Information. [accessed on 2024/06/12] **PurpleAir data download functions adapted from** Callahan J, Martin H, Wilson K, Brasel T, Miller H (2023). AirSensor: Process and Display Data from Air Quality Sensors. R package version 1.1.1, https://CRAN.R-project.org/package=AirSensor. From 77f6f3de67f7a5caa3f67dd18e0e64a27b0359ff Mon Sep 17 00:00:00 2001 From: Eva Marques Date: Wed, 12 Jun 2024 16:29:19 -0400 Subject: [PATCH 8/8] Delete .github/workflows/test-coverage.yaml --- .github/workflows/test-coverage.yaml | 111 --------------------------- 1 file changed, 111 deletions(-) delete mode 100644 .github/workflows/test-coverage.yaml diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml deleted file mode 100644 index 5213bbf..0000000 --- a/.github/workflows/test-coverage.yaml +++ /dev/null @@ -1,111 +0,0 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples -# also derived from https://github.com/we-cli/coverage-badge-action -# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help -on: - push: - branches: [main, master] - pull_request: - branches: [main, master] - -name: test-coverage-local - -jobs: - test-coverage: - runs-on: ubuntu-latest - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - - steps: - - uses: actions/checkout@v4 - - - uses: r-lib/actions/setup-r@v2 - with: - use-public-rspm: true - - - uses: r-lib/actions/setup-r-dependencies@v2 - with: - extra-packages: any::covr - needs: coverage - - - name: Cache C++ and R dependencies - uses: actions/cache@v2 - with: - path: | - ~/.cache/R - ~/.local/share/R - key: dependencies-${{ runner.os }}-${{ hashFiles('**/DESCRIPTION') }} - restore-keys: | - dependencies-${{ runner.os }}- - - - name: Test coverage - run: > - Rscript -e - "covd<-covr::coverage_to_list()$totalcoverage; - write.table(covd[length(covd)], file = '${{ github.workspace }}/local_cov.Rout', row.names = F, col.names = F)" - shell: bash - - - name: Get Values - id: get-values - shell: bash - run: | - COV=$(cat ${{ github.workspace }}/local_cov.Rout) - echo "Patch coverage read from local_cov.Rout: $COV" - echo "coverage=$COV" >> $GITHUB_OUTPUT - - - name: Checkout gh-pages - uses: actions/checkout@v4 - with: - ref: gh-pages - - - name: Patch comparison - id: patch-comparison - shell: bash - run: | - cov_patch="${{ steps.get-values.outputs.coverage }}" - if [[ ! -f cov_current.Rout ]]; then - cov_current=0 - else - cov_current=$(cat cov_current.Rout) - fi - echo "Current coverage: $cov_current" - - if (( $(echo "$cov_patch >= $cov_current" | bc -l) )); then - echo "Patch coverage ($cov_patch) is greater than or equal to current coverage ($cov_current)." - echo "cov_update=$cov_patch" >> $GITHUB_OUTPUT - else - echo "Patch coverage ($cov_patch) is less than current coverage ($cov_current)." - exit 1 - fi - - - name: Overwrite cov_current.Rout - if: ${{ github.event_name == 'push' }} - shell: bash - run: | - cov_update="${{ steps.patch-comparison.outputs.cov_update }}" - touch cov_current.Rout - echo "$cov_update" > cov_current.Rout - - - name: Create Badges - shell: bash - run: | - npm i -g badgen-cli - export COV=${{ steps.get-values.outputs.coverage }} - COLOR=$(node -p '+process.env.COV >= 95 ? `green` : `orange`') - mkdir -p badges - badgen -j coverage -s $COV% -c $COLOR > badges/coverage.svg - - - name: Deploy Badges - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: "Update badges [skip ci] & cov_current.Rout" - branch: gh-pages - skip_fetch: true - skip_checkout: true - - # Without this, will get Error: - # Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/home/runner/work/coverage-badge-action/coverage-badge-action/action.yml'. - # Did you forget to run actions/checkout before running your local action? - - name: Checkout Back - uses: actions/checkout@v4 - with: - ref: ${{ github.ref }}