Skip to content

Commit

Permalink
Merge pull request #79 from bczernecki/dev
Browse files Browse the repository at this point in the history
fixes for CRAN policy
  • Loading branch information
bczernecki authored Oct 12, 2022
2 parents b7f9211 + 1604968 commit 600a3bc
Show file tree
Hide file tree
Showing 78 changed files with 1,214 additions and 550 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
^\.github$
^\.Rhistory$
^\.lintr$
vignettes/articles/usecase.Rmd
^pkgdown$
^.codecov.yml$

8 changes: 8 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
coverage:
status:
patch:
default:
target: 60%
project:
default:
target: 60%
37 changes: 29 additions & 8 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ jobs:
config:
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-18.04, r: 'release'}
- {os: ubuntu-18.04, r: '3.6'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-20.04, r: 'release'}
- {os: ubuntu-20.04, r: '3.6'}
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
Expand Down Expand Up @@ -74,14 +75,15 @@ jobs:
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "18.04"))')
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
remotes::install_cran("covr")
remotes::install_cran("xml2")
remotes::install_cran("DT")
shell: Rscript {0}

- name: Session info
Expand All @@ -94,7 +96,7 @@ jobs:
- name: Check
env:
_R_CHECK_CRAN_INCOMING_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran", "--run-donttest"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Show testthat output
Expand All @@ -103,12 +105,31 @@ jobs:
shell: bash

- name: Upload check results
if: failure()
if: always()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check

- name: Test coverage
run: covr::codecov()
shell: Rscript {0}
- name: Codecov
run: |
covr::codecov()
shell: Rscript {0}

- name: Test coverage report
if: always()
run: |
covr_report <- covr::package_coverage(wrap = TRUE)
covr::report(x = covr_report, file = 'covr_report.html')
print(getwd())
print(dir())
shell: Rscript {0}

- name: Upload test coverage report
if: always()
uses: actions/upload-artifact@v3
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: |
covr_report.html
lib
48 changes: 48 additions & 0 deletions .github/workflows/html5-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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, dev, devel]
pull_request:
branches: [main, master, dev, devel]

name: HTML5 check

jobs:
HTML5-check:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: 'devel'
http-user-agent: 'release'
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
dependencies: 'character()'

- name: Install pdflatex
run: sudo apt-get install texlive-latex-base texlive-fonts-recommended texlive-fonts-extra texlive-latex-extra

- name: Install tidy and pandoc
run: sudo apt install tidy pandoc

- name: Install dependencies
run: R -e 'install.packages(c("knitr", "rmarkdown", "XML", "httr", "data.table", "maps", "dplyr", "tidyr", "xml2", "testthat"))'

- uses: r-lib/actions/check-r-package@v2
with:
args: 'c("--as-cran")'
build_args: 'character()'
error-on: '"note"'
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
_R_CHECK_CRAN_INCOMING_: false
LANG: "en_US.UTF.8"
39 changes: 39 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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
name: pkgdown
on:
push:
branches: [main, master, dev, devel]
pull_request:
branches: [main, master, dev, devel]
release:
types: [published]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
container: bczernecki/meteo:latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Checkout Project
uses: actions/checkout@v1

- name: Checked for installed packages
run: |
sudo apt-get install -y libfontconfig1-dev libharfbuzz-dev libfribidi-dev rsync
R -e 'install.packages(c("pkgdown", "openair", "rnaturalearthdata"))'
R -e 'installed.packages()[, 1:3]'
- name: Build book
run: |
Rscript -e 'pkgdown::build_site()'
- name: Deploy to GitHub pages 🚀
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ climate.Rproj
.DS_Store
covr_report.html
lib
docs
pkgdown
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: climate
Title: Interface to Download Meteorological (and Hydrological) Datasets
Version: 1.0.5
Version: 1.1.0
Authors@R: c(person(given = "Bartosz",
family = "Czernecki",
role = c("aut", "cre"),
Expand All @@ -27,9 +27,9 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.1
Depends:
R (>= 3.1)
R (>= 3.5.0)
Imports:
XML,
httr,
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export(meteo_noaa_co2)
export(meteo_noaa_hourly)
export(meteo_ogimet)
export(nearest_stations_imgw)
export(nearest_stations_nooa)
export(nearest_stations_noaa)
export(nearest_stations_ogimet)
export(ogimet_daily)
export(ogimet_hourly)
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# climate 1.1.0

* A new approach for handling CRAN policy for resolving problems if network issues are detected or some of the external services are temporarily down.
* Adding `allow_failure` argument used by default that turns off automatic debugging but avoid warnings and errors for most typical use cases
* re-factoring of unit tests
* documentation build with CI/CD
* updating vignettes and examples, including the way to use climate with Python


# climate 1.0.5

* `meteo_imgw` family of functions supports multiple names as argument - bug fix
Expand Down
10 changes: 5 additions & 5 deletions R/clean_metadata_hydro.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ clean_metadata_hydro = function(address, interval) {
test_url(link = address, output = temp)
a = readLines(temp, warn = FALSE)

a = iconv(a, from = "cp1250", to = "ASCII//TRANSLIT") # usuwamy polskie znaki, bo to robi spore "kuku"
a = gsub(a, pattern = "\\?", replacement = "") # usuwamy znaki zapytania powstale po konwersji
a = iconv(a, from = "cp1250", to = "ASCII//TRANSLIT") # remove polish characters
a = gsub(a, pattern = "\\?", replacement = "") # removing extra characters after conversion

# additional workarounds for mac os but not only...
a = gsub(x = a, pattern = "'", replacement = "")
Expand Down Expand Up @@ -40,8 +40,8 @@ clean_metadata_hydro = function(address, interval) {
b = cbind(b, tmp)
}
b = list("H" = data.frame(parameters = b[, 1]),
"Q" = data.frame(parameters = b[, 2]),
"T" = data.frame(parameters = b[, 3]))
"Q" = data.frame(parameters = b[, 2]),
"T" = data.frame(parameters = b[, 3]))
}
b
return(b)
}
11 changes: 2 additions & 9 deletions R/clean_metadata_meteo.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@
#' @importFrom stats na.omit
#' @keywords internal
#'
#' @examples
#' \donttest{
#' my_add = paste0("https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/",
#' "dane_meteorologiczne/dobowe/synop/s_d_format.txt")
#' climate:::clean_metadata_meteo(address = my_add, rank = "synop", interval = "hourly")
#' }
#'

clean_metadata_meteo = function(address, rank = "synop", interval = "hourly") {

temp = tempfile()
test_url(link = address, output = temp)
a = readLines(temp, warn = FALSE)

a = iconv(a, from = "cp1250", to = "ASCII//TRANSLIT") # usuwamy polskie znaki, bo to robi spore "kuku"
a = gsub(a, pattern = "\\?", replacement = "") # usuwamy znaki zapytania powstale po konwersji
a = iconv(a, from = "cp1250", to = "ASCII//TRANSLIT")
a = gsub(a, pattern = "\\?", replacement = "")

# additional workarounds for mac os but not only...
a = gsub(x = a, pattern = "'", replacement = "")
Expand Down
2 changes: 1 addition & 1 deletion R/get_coord_from_string.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ get_coord_from_string = function(txt, pattern = "Longitude") {
wsp = suppressWarnings(as.numeric(tmp)[1] + (as.numeric(tmp)[2] * 5 / 3) / 100)

if (hemisphere %in% c("W", "S")) {
wsp = wsp * -1
wsp = wsp*-1
}
return(wsp)
}
41 changes: 36 additions & 5 deletions R/hydro_imgw_annual.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,55 @@
#' "short" - default, values with shorten names,
#' "full" - full English description,
#' "polish" - original names in the dataset
#' @param allow_failure logical - whether to proceed or stop on failure. By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE
#' @param ... other parameters that may be passed to the 'shortening' function that shortens column names
#' @importFrom XML readHTMLTable
#' @importFrom utils download.file unzip read.csv
#' @importFrom data.table fread
#' @export
#' @examples
#' \donttest{
#' yearly = hydro_imgw_annual(year = 2000, value = "H", station = "ANNOPOL")
#' head(yearly)
#' hydro_yearly = hydro_imgw_annual(year = 2000, value = "H", station = "ANNOPOL")
#' }
hydro_imgw_annual = function(year,
coords = FALSE,
value = "H",
station = NULL,
col_names = "short", ...) {
# options(RCurlOptions = list(ssl.verifypeer = FALSE)) # required on windows for RCurl
translit = check_locale()
col_names = "short",
allow_failure = TRUE,
...) {

if (allow_failure) {
tryCatch(hydro_imgw_annual_bp(year,
coords,
value,
station,
col_names,
...),
error = function(e){
message(paste("Problems with downloading data.",
"Run function with argument allow_failure = FALSE",
"to see more details"))})
} else {
hydro_imgw_annual_bp(year,
coords,
value,
station,
col_names,
...)
}
}

#' @keywords internal
#' @noRd
hydro_imgw_annual_bp = function(year = year,
coords = coords,
value = value,
station = station,
col_names = col_names,
...) {

translit = check_locale()
base_url = "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/"
interval = "semiannual_and_annual"
interval_pl = "polroczne_i_roczne"
Expand Down
Loading

0 comments on commit 600a3bc

Please sign in to comment.