diff --git a/DESCRIPTION b/DESCRIPTION index 47af142..fbc462c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,15 +1,14 @@ Package: HeatStress Type: Package Title: Calculate heat stress indices -Version: 1.0.6 -Date: 2019-03-11 +Version: 1.0.7 +Date: 2019-07-01 Author: A. Casanueva Maintainer: A.Casanueva Description: Calculate heat stress indices based on meteorological data. -License: file LICENCE -RoxygenNote: 6.0.1 -Depends: R (>= 2.10.0) +License: file LICENSE +RoxygenNote: 6.1.1 +Depends: R (>= 2.10.0), magrittr Suggests: testthat, assertthat Imports: stats -Encoding: ISO-8859-1 - +Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index e3bfb2f..a863898 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,9 +9,13 @@ export(fTg) export(fTnwb) export(hi) export(humidex) +export(indexShow) export(swbgt) export(tashurs2vap.pres) export(wbgt.Bernard) export(wbgt.Liljegren) export(wbt.Stull) +importFrom(magrittr,"%>%") importFrom(stats,optimize) +importFrom(utils,packageDescription) +importFrom(utils,read.table) diff --git a/NEWS b/NEWS index 5248489..db600cf 100644 --- a/NEWS +++ b/NEWS @@ -15,4 +15,10 @@ Changes in version 1.0.4 * Inclusion of more heat indices. Changes in version 1.0.5 - * Arrange assert statments in wrapper function to speed up calculation of wbgt.Liljegren. \ No newline at end of file + * Arrange assert statments in wrapper function to speed up calculation of wbgt.Liljegren. + +Changes in version 1.0.6 + * Correct bug in assertion statement. + +Changes in version 1.0.7 + * Update README.md \ No newline at end of file diff --git a/R/HeatStress.R b/R/HeatStress.R index fa1b196..4d6a076 100644 --- a/R/HeatStress.R +++ b/R/HeatStress.R @@ -4,8 +4,14 @@ #' #' The package \code{HeatStress} provides methods to calculate heat stress indices. #' -#' @name HeatStress -#' @docType package +#' Check the details of the indices and input variables: +#' +#' \code{library(HeatStress)} +#' +#' \code{indexShow()} +#' +#' +#' #' @details #' #' The following calculation methods are implemented: @@ -21,6 +27,9 @@ #' \item \code{discomInd}: Calculation of the discomfort index (Coccolo et al. 2016 and references therein). #' \item \code{hi}: Calculation of the heat index (Buzan et al. 2015 and references therein). -#' } +#' } +#' @name HeatStress +#' @docType package +#' NULL #"_PACKAGE" diff --git a/R/indexShow.R b/R/indexShow.R new file mode 100644 index 0000000..0bb66c1 --- /dev/null +++ b/R/indexShow.R @@ -0,0 +1,27 @@ +#' @title List all available heat indices +#' @description Print a table with a summary of the available indices +#' @return Print a table on the screen with the following columns: +#' \itemize{ +#' \item \strong{code}: Code of the index. +#' \item \strong{longname}: Long description of the index +#' \item \strong{index.fun}: The name of the internal function used to calculate it +#' \item \strong{tas, dewp, hurs, wind, radiation}: A logical value (0/1) indicating the input variables required for index calculation. Temperature and either dew point temperature or relative humidity need to be always provided. +#' \item \strong{units}: The units of the index. +#' } +#' @author A. Casanueva +#' @export + +indexShow <- function() { + read.master() +} + +#' @keywords internal +#' @importFrom magrittr %>% +#' @importFrom utils read.table + +read.master <- function() { + system.file("master", package = "HeatStress") %>% read.table(header = TRUE, + sep = ";", + stringsAsFactors = FALSE, + na.strings = "") +} \ No newline at end of file diff --git a/R/rhooks.R b/R/rhooks.R new file mode 100644 index 0000000..d02292a --- /dev/null +++ b/R/rhooks.R @@ -0,0 +1,32 @@ +#' @importFrom utils packageDescription + +.onAttach <- function(...) { + pkgname <- "HeatStress" + ver <- packageDescription(pkgname)$Version + builddate <- packageDescription(pkgname)$Date + mess <- paste(pkgname, " version ", ver, " (", builddate,") is loaded", sep = "") + packageStartupMessage(mess) + url <- paste0("https://raw.githubusercontent.com/anacv/", pkgname, "/master/DESCRIPTION") + b <- tryCatch(suppressWarnings(readLines(url)), error = function(er) { + er <- NULL + return(er) + }) + if (!is.null(b)) { + latest.ver <- package_version(gsub("Version: ", "", b[grep("^Version", b)])) + if (ver < latest.ver) { + ver.mess1 <- paste0("WARNING: Your current version of ", pkgname, " (v", ver, ") is not up-to-date") + ver.mess <- paste0("Get the latest stable version (", latest.ver, + ") using ") + packageStartupMessage(ver.mess1) + packageStartupMessage(ver.mess) + } else if (ver > latest.ver) { + ver.mess1 <- paste0("WARNING: Your current version of ", pkgname, " (v", ver, + ") is ahead of the master branch version (", latest.ver, ")") + ver.mess <- paste0("Development version may have an unexpected behaviour") + packageStartupMessage(ver.mess1) + packageStartupMessage(ver.mess) + } + } + packageStartupMessage("Use 'indexShow()' for an overview of the available heat indices") +} +# End \ No newline at end of file diff --git a/README.md b/README.md index d1dd169..749cbfe 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,29 @@ # HeatStress Heat Stress indices for Heat-Shield + +## What is `HeatStress`? + +**HeatStress** is a R package for the calculation of heat stress indices. It has been developed in the framework of the Horizon2020 [HEAT-SHIELD project](www.heat-shield.eu). + +**** + +### Installation + +The recommended procedure for installing the package is using the devtools package. + +```R +devtools::install_github("anacv/HeatStress") +``` + +A list of all available indices and the atomic functions calculating them is printed on screen with: + +```R +library(HeatStress) +indexShow() +``` + +### Reference and further information: + +This package was used in the development of climate change scenarios of heat stress, in the following publications: +* Casanueva et al. 2019. Climate projections of a multi-variate heat stress index: the role of downscaling and bias correction, *Geoscientific Model Development*, https://www.geosci-model-dev-discuss.net/gmd-2018-294/ +* Casanueva et al. 2019. Escalating environmental heat exposure – a future threat for the European workforce, *Regional Environmental Change*. diff --git a/inst/master b/inst/master new file mode 100644 index 0000000..0be66eb --- /dev/null +++ b/inst/master @@ -0,0 +1,11 @@ +code;longname;indexfun;tas;dewp;hurs;wind;radiation;units +wbt;Wet Bulb Temperature; wbt.Stull;1;0;1;0;0;degC +wbgt_shade;Wet Bulb Globe Temperature (shade);wbgt.Bernard;1;1;0;0;0;degC +wbgt_sun;Wet Bulb Globe Temperature (sun);wbgt.Liljegren;1;1;0;1;1;degC +swbgt;simplified wet bulb globe temperature;swbgt;1;0;1;0;0;degC +apparentTemp;apparent temperature;apparentTemp;1;0;1;1;0;degC +effectiveTemp;effective temperature;effectiveTemp;1;0;1;1;0;degC +humidex;humidex;humidex;1;0;1;0;0;degC +discomInd;discomfort index;discomInd;1;0;1;0;0;degC +hi;heat index;hi;1;0;1;0;0;degF + diff --git a/man/HeatStress.Rd b/man/HeatStress.Rd index 728d13a..c54be4a 100644 --- a/man/HeatStress.Rd +++ b/man/HeatStress.Rd @@ -11,6 +11,12 @@ Calculate heat stress indices \details{ The package \code{HeatStress} provides methods to calculate heat stress indices. +Check the details of the indices and input variables: + +\code{library(HeatStress)} + +\code{indexShow()} + The following calculation methods are implemented: diff --git a/man/fTnwb.Rd b/man/fTnwb.Rd index 88f4115..1effe7e 100644 --- a/man/fTnwb.Rd +++ b/man/fTnwb.Rd @@ -4,8 +4,8 @@ \alias{fTnwb} \title{Calculation of the natural wet bulb temperature.} \usage{ -fTnwb(tas, dewp, relh, Pair, wind, min.speed, radiation, propDirect, zenith, - irad = 1, SurfAlbedo = 0.4, tolerance = 1e-04) +fTnwb(tas, dewp, relh, Pair, wind, min.speed, radiation, propDirect, + zenith, irad = 1, SurfAlbedo = 0.4, tolerance = 1e-04) } \arguments{ \item{tas}{vector of temperature in degC.} diff --git a/man/indexShow.Rd b/man/indexShow.Rd new file mode 100644 index 0000000..d33a388 --- /dev/null +++ b/man/indexShow.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/indexShow.R +\name{indexShow} +\alias{indexShow} +\title{List all available heat indices} +\usage{ +indexShow() +} +\value{ +Print a table on the screen with the following columns: +\itemize{ +\item \strong{code}: Code of the index. +\item \strong{longname}: Long description of the index +\item \strong{index.fun}: The name of the internal function used to calculate it +\item \strong{tas, dewp, hurs, wind, radiation}: A logical value (0/1) indicating the input variables required for index calculation. Temperature and either dew point temperature or relative humidity need to be always provided. +\item \strong{units}: The units of the index. +} +} +\description{ +Print a table with a summary of the available indices +} +\author{ +A. Casanueva +} diff --git a/man/wbgt.Bernard.Rd b/man/wbgt.Bernard.Rd index bf7b042..283e1a0 100644 --- a/man/wbgt.Bernard.Rd +++ b/man/wbgt.Bernard.Rd @@ -4,7 +4,8 @@ \alias{wbgt.Bernard} \title{Calculation of wet bulb globe temperature, following Bernard's method.} \usage{ -wbgt.Bernard(tas, dewp, tolerance = 1e-04, noNAs = TRUE, swap = FALSE) +wbgt.Bernard(tas, dewp, tolerance = 1e-04, noNAs = TRUE, + swap = FALSE) } \arguments{ \item{tas}{vector of air temperature in degC.} diff --git a/man/wbgt.Liljegren.Rd b/man/wbgt.Liljegren.Rd index 0a6854b..3581afe 100644 --- a/man/wbgt.Liljegren.Rd +++ b/man/wbgt.Liljegren.Rd @@ -4,8 +4,8 @@ \alias{wbgt.Liljegren} \title{Calculation of wet bulb globe temperature, following Liljegren's method.} \usage{ -wbgt.Liljegren(tas, dewp, wind, radiation, dates, lon, lat, tolerance = 1e-04, - noNAs = TRUE, swap = FALSE, hour = FALSE) +wbgt.Liljegren(tas, dewp, wind, radiation, dates, lon, lat, + tolerance = 1e-04, noNAs = TRUE, swap = FALSE, hour = FALSE) } \arguments{ \item{tas}{vector of temperature in degC.}