Skip to content

Commit

Permalink
Add some initial tests. Overhaul the build process.
Browse files Browse the repository at this point in the history
  • Loading branch information
ConorIA committed Oct 8, 2017
1 parent af21a38 commit 512e2fe
Show file tree
Hide file tree
Showing 17 changed files with 299 additions and 117 deletions.
21 changes: 12 additions & 9 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
image: conoria/alpine-r
before_script:
- export _R_CHECK_CRAN_INCOMING_=FALSE
- export _R_CHECK_FORCE_SUGGESTS_=TRUE

variables:
BUILD_FLAGS: "--no-build-vignettes --no-manual"

test:
r-base:
stage: test
image: r-base
script:
- apk add --no-cache mariadb-dev
- R CMD build . ${BUILD_FLAGS}
- Rscript -e 'devtools::install_deps(dependencies = TRUE)'
- R CMD check $(ls -1t *.tar.gz | head -n 1) ${BUILD_FLAGS} --as-cran
- apt-get update -qq
- apt-get install -y --no-install-recommends libmariadbclient-dev libcurl4-openssl-dev libssh2-1-dev libssl-dev libxml2-dev git
- Rscript -e 'install.packages(c("devtools", "roxygen2", "testthat", "covr"), repos = "https://cran.rstudio.com/")'
- Rscript -e 'devtools::install_deps()'
- Rscript -e 'devtools::check()'
- Rscript -e 'covr::codecov(type = "all", quiet = FALSE)'
7 changes: 5 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: senamhiR
Type: Package
Title: A Collection of Functions to Obtain Peruvian Climate Data
Version: 0.4.1
Date: 2017-03-24
Version: 0.4.2
Date: 2017-10-08
Authors@R: c(person(given = c("Conor", "I."), family = "Anderson",
role = c("aut","cre"), email = "[email protected]"),
person(given = c("William", "A."), family = "Gough", role = "ths",
Expand All @@ -27,6 +27,9 @@ Imports:
utils,
XML,
zoo
Suggests:
testthat,
covr
License: GPL (>= 3)
URL: https://gitlab.com/ConorIA/senamhiR/
BugReports: https://gitlab.com/ConorIA/senamhiR/issues
Expand Down
2 changes: 1 addition & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
#' }
#'
#' @examples
#' catalogue
#' \dontrun{catalogue}
"catalogue"

4 changes: 4 additions & 0 deletions R/qc.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ qc <- function(dat) {
}
}

if (length(unique(format(dat$Fecha, format = "%Y"))) == 1) {
stop("You've passed a one-year table. We need (many) additional years of data for context.")
}

if (grepl("Observations", colnames(dat)[15])) {
observations <- select(dat, 15) %>% unlist
} else {
Expand Down
4 changes: 4 additions & 0 deletions R/senamhiR.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ senamhiR <- function(station, year, tasks, fallback, write_mode = "z") {
station <- trimws(unlist(strsplit(station, split = ",")))
}

if (!station %in% catalogue$StationID) {
stop("The station requested is not a valid station.")
}

# If tasks is not specified (good), use MySQL
if (missing(tasks)) {
dataout <- list()
Expand Down
6 changes: 6 additions & 0 deletions R/station_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@ station_search <- function(name = NULL, ignore.case = TRUE, glob = FALSE, region
# If `region` is not NULL, filter by name
if (!is.null(region)) {
index <- index[which(catalogue$Region == toupper(region))]
if (length(index) == 0) {
stop("No data found for that region. Did you spell it correctly?")
}
}

# If `config` is not NULL, filter by name
if (!is.null(config)) {
index <- index[grep(config, catalogue$Configuration[index], ignore.case = ignore.case,
...)]
if (length(index) == 0) {
stop("No data found for that config. Did you pass \"m\" or \"h\"?")
}
}

# Make a table with the info we want
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.onLoad <- function(libname = find.package("senamhiR"), pkgname = "senamhiR") {
.onAttach <- function(libname = find.package("senamhiR"), pkgname = "senamhiR") {
packageStartupMessage("The information accessed by this package was compiled and maintained by Peru's National Meteorology and Hydrology Service (Senamhi). The use of this data is of your sole responsibility.")
}
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ knitr::opts_chunk$set(echo = TRUE)
library(senamhiR)
```

[![build status](https://gitlab.com/ConorIA/senamhiR/badges/master/build.svg)](https://gitlab.com/ConorIA/senamhiR/commits/master) [![Build status](https://ci.appveyor.com/api/projects/status/60kbu1b7wkf7akqn?svg=true)](https://ci.appveyor.com/project/ConorIA/senamhir-bxb45)
[![build status](https://gitlab.com/ConorIA/senamhiR/badges/master/build.svg)](https://gitlab.com/ConorIA/senamhiR/commits/master) [![Build status](https://ci.appveyor.com/api/projects/status/60kbu1b7wkf7akqn?svg=true)](https://ci.appveyor.com/project/ConorIA/senamhir-bxb45) [![codecov](https://codecov.io/gl/ConorIA/senamhiR/branch/master/graph/badge.svg)](https://codecov.io/gl/ConorIA/senamhiR)

The package provides an automated solution for the acquisition of archived Peruvian climate and hydrology data directly within R. The data was compiled from the Senamhi website, and contains all of the data that was available as of March 2017. This data was originally converted from HTML, and is stored in a MySQL database in tibble format.

Expand Down
Loading

0 comments on commit 512e2fe

Please sign in to comment.