Skip to content

Commit

Permalink
Merge pull request #89 from bcgov/remove-wqbc
Browse files Browse the repository at this point in the history
Remove wqbc and update DOC codes
  • Loading branch information
ateucher authored Mar 25, 2024
2 parents 93711f4 + c3311a4 commit 669cb02
Show file tree
Hide file tree
Showing 15 changed files with 1,237 additions and 153 deletions.
94 changes: 21 additions & 73 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches:
- main
- master
branches: [main, master]
pull_request:
branches:
- main
- master
branches: [main, master]
schedule:
- cron: '0 8 * * *'

Expand All @@ -23,88 +21,38 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@master
- uses: r-lib/actions/setup-pandoc@v2

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v2
- uses: r-lib/actions/setup-r@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Session info
run: |
options(width = 100)
pkgs <- installed.packages()[, "Package"]
sessioninfo::session_info(pkgs, include_base = TRUE)
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- name: Upload check results
if: failure()
uses: actions/upload-artifact@master
- uses: r-lib/actions/setup-r-dependencies@v2
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
extra-packages: any::rcmdcheck
needs: check

- name: action-slack
if: failure()
env:
SLACK_WEBHOOK_URL: ${{ secrets.POISSON_SLACK_WEBHOOK_URL }}
uses: 8398a7/[email protected]
- uses: r-lib/actions/check-r-package@v2
with:
status: ${{ job.status }}
author_name: "github action: ${{github.workflow}}"
fields: repo, ref, commit, author, message
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
48 changes: 0 additions & 48 deletions .github/workflows/coverage.yaml

This file was deleted.

51 changes: 51 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# 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

jobs:
test-coverage:
if: "!contains(github.event.head_commit.message, 'skip ci')"
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: Test coverage
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
3 changes: 2 additions & 1 deletion R/check_guidelines.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ check_guidelines <- function(x = NULL){

if(is.null(x)){
message("reading data from BC Data Catalogue ...")
x <- bcdata::bcdc_get_data(record = "85d3990a-ec0a-4436-8ebd-150de3ba0747")
x <- bcdata::bcdc_get_data(record = "85d3990a-ec0a-4436-8ebd-150de3ba0747",
show_col_types = FALSE)
x <- process_limits(x)
}

Expand Down
23 changes: 14 additions & 9 deletions R/functions_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ process_limits <- function(limits){
stringr::str_c(" (", limits$LimitNotes[limits$PC], ").")))

limits$LimitNotes[limits$PC] <- limit_notes
limits <- dplyr::select(limits, -.data$PC)
limits <- dplyr::select(limits, -"PC")

#### end convert background percent

Expand Down Expand Up @@ -79,11 +79,11 @@ wqg_clean <- function(data, sigfig) {
data %>%
dplyr::mutate(Notes = gsub("NA", "", paste(.data$ConditionNotes, .data$MethodNotes))) %>%
dplyr::mutate(Notes = dplyr::if_else(.data$Notes == " ", NA_character_, .data$Notes)) %>%
dplyr::select(.data$Variable, .data$Component, Value = .data$Use,
.data$Media, .data$Type, `Predicted Effect Level` = .data$PredictedEffectLevel,
.data$Status, `WQG Narrative` = .data$NarrativeWQG, .data$Notes,
.data$Guideline, .data$Reference, .data$`Reference Link`,
.data$`Overview Report Link`, .data$`Technical Document Link`)
dplyr::select("Variable", "Component", Value = "Use",
"Media", "Type", `Predicted Effect Level` = "PredictedEffectLevel",
"Status", `WQG Narrative` = "NarrativeWQG", "Notes",
"Guideline", "Reference", "Reference Link",
"Overview Report Link", "Technical Document Link")
}

add_lookup <- function(x) {
Expand All @@ -97,7 +97,7 @@ add_lookup_condition <- function(x){
}

get_lookup_codes <- function(Limit, lookup, Condition) {
if(!is.null(lookup)){
if (!is.null(lookup)) {
col_names <- paste0(colnames(lookup), collapse = " ")
lookup_parameters <- stringr::str_match_all(col_names, "EMS_.{4}")
Condition <- paste0(lookup_parameters[[1]], sep = " ", collapse = "")
Expand Down Expand Up @@ -165,7 +165,11 @@ lookup_choices <- function(data, cvalue_codes){
}

get_data <- function(file_name, resource = NULL){
data <- try(bcdata::bcdc_get_data(record = file_name, resource = resource), silent = TRUE)
data <- try(bcdata::bcdc_get_data(
record = file_name,
resource = resource,
show_col_types = FALSE
), silent = TRUE)
if (is_try_error(data)){
i <- file_name
internal_data <- internal_tables[[i]]
Expand All @@ -186,6 +190,7 @@ get_data <- function(file_name, resource = NULL){
data <- data
data
}
data
# TODO: Temporary workaround until CU lookup tables updated in BCDC
dplyr::rename(data, dplyr::any_of(c("EMS_1103" = "EMS_1126")))
}

6 changes: 3 additions & 3 deletions R/functions_limits.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ test_condition <- function(x, cvalues) {
if(is.na(x))
return (TRUE)
# pass condition for look-up values
if(!stringr::str_detect(x, "[>|<|=]"))
if (!stringr::str_detect(x, "[>|<|=]"))
return(TRUE)
x <- try(eval(parse(text = x), envir = cvalues), silent = TRUE)
if(class(x) != "logical")
if(!is.logical(x))
return (FALSE)
if(is.na(x))
return (FALSE)
Expand All @@ -14,7 +14,7 @@ test_condition <- function(x, cvalues) {

calc_limit <- function(x, cvalues) {
x <- try(eval(parse(text = as.character(x)), envir = cvalues), silent = TRUE)
if(class(x) != "numeric")
if (!is.numeric(x))
return (NA)
x
}
Expand Down
2 changes: 1 addition & 1 deletion R/functions_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gt_table <- function(x, cvalues) {
title = variable,
subtitle = gt::html(cvalues)
) %>%
gt::fmt_missing(columns = gt::everything()) %>%
gt::sub_missing(columns = gt::everything()) %>%
gt::cols_align(
align = "center",
columns = gt::everything()
Expand Down
6 changes: 4 additions & 2 deletions R/mod_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ mod_data_server <- function(input, output, session) {
observe({

file_name <- "85d3990a-ec0a-4436-8ebd-150de3ba0747"
limit_resource <- "6f32a85b-a3d9-44c3-9a14-15175eba25b6"
limits <- get_data(file_name, resource = limit_resource)
## TODO: Temporary workaround until CU lookup tables updated in BCDC
# limit_resource <- "6f32a85b-a3d9-44c3-9a14-15175eba25b6"
# limits <- get_data(file_name, resource = limit_resource)
limits <- readr::read_csv("all-wqgs-2.csv", show_col_types = FALSE)

limits <- try(process_limits(limits))
if (is_try_error(limits)) {
Expand Down
4 changes: 4 additions & 0 deletions R/namespace.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
#' @importFrom rlang .data
#' @rawNamespace import(shiny, except = p)
NULL

ignore_unused_imports <- function() {
webshot::install_phantomjs
}
Binary file modified R/sysdata.rda
Binary file not shown.
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ knitr::opts_chunk$set(

<!-- badges: start -->
[![img](https://img.shields.io/badge/Lifecycle-Maturing-007EC6)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)
[![R-CMD-check](https://github.com/bcgov/shinywqg/workflows/R-CMD-check/badge.svg)](https://github.com/poissonconsulting/shinywqg/actions)
[![Codecov test coverage](https://codecov.io/gh/bcgov/shinywqg/branch/master/graph/badge.svg)](https://codecov.io/gh/poissonconsulting/shinywqg?branch=master)
[![R-CMD-check](https://github.com/bcgov/shinywqg/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/bcgov/shinywqg/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/bcgov/shinywqg/branch/master/graph/badge.svg)](https://codecov.io/gh/bcgov/shinywqg?branch=master)
[![Apache license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
<!-- badges: end -->

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<!-- badges: start -->

[![img](https://img.shields.io/badge/Lifecycle-Maturing-007EC6)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)
[![R-CMD-check](https://github.com/bcgov/shinywqg/workflows/R-CMD-check/badge.svg)](https://github.com/poissonconsulting/shinywqg/actions)
[![R-CMD-check](https://github.com/bcgov/shinywqg/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/bcgov/shinywqg/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/bcgov/shinywqg/branch/master/graph/badge.svg)](https://codecov.io/gh/poissonconsulting/shinywqg?branch=master)
coverage](https://codecov.io/gh/bcgov/shinywqg/branch/master/graph/badge.svg)](https://codecov.io/gh/bcgov/shinywqg?branch=master)
[![Apache
license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
<!-- badges: end -->
Expand Down Expand Up @@ -78,9 +78,9 @@ implemented.
Once a new version of the guidelines have been added to the BC Data
Catalogue you will need to update the internal backup data.

- Open `data-raw/internal.R`
- Run the script from the top to bottom
- Deploy the app
- Open `data-raw/internal.R`
- Run the script from the top to bottom
- Deploy the app

#### How to Add New Lookup Tables

Expand Down
Loading

0 comments on commit 669cb02

Please sign in to comment.