Skip to content

Commit

Permalink
CRAN version 1.2.111
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathancallahan committed Jul 8, 2020
1 parent da92a04 commit d2e1cc0
Show file tree
Hide file tree
Showing 288 changed files with 1,094 additions and 613 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Package
Package: PWFSLSmoke
Version: 1.2.109
Version: 1.2.111
Title: Utilities for Working with Air Quality Monitoring Data
Authors@R: c(
person("Jonathan", "Callahan", email="[email protected]", role=c("aut","cre")),
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,4 @@ importFrom(methods,as)
importFrom(rlang,":=")
importFrom(rlang,.data)
importFrom(utils,download.file)
importFrom(utils,installed.packages)
importFrom(utils,read.table)
16 changes: 16 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# PWFSLSmoke 1.2.111

CRAN manual review suggestions:

* Use `find.package()` instead of the much slower `installed.packages()` to
determine if a package is installed.
* When using `par()` to set graphical parameters, always use save the previously
set parameters and then `on.exit(par(opar))` as the very next line.
* Ensure that `tempdir()` or `tempfile()` are used in all examples, tests and
vignettes so that no files are written to user directories.
* Changed many examples from `\dontrun{}` to `\donttest{}`.

# PWFSLSmoke 1.2.110

* Tweaks for CRAN submission.

# PWFSLSmoke 1.2.109

* Removed logging setup from `initializeMazamaSpatialutils()`.
Expand Down
1 change: 0 additions & 1 deletion R/addEsriAddress.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#' @keywords internal
#' @export
#' @import MazamaCoreUtils
#' @importFrom utils installed.packages
#'
#' @title Add address information to a dataframe
#'
Expand Down
3 changes: 1 addition & 2 deletions R/addGoogleAddress.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#' @keywords internal
#' @export
#' @import MazamaCoreUtils
#' @importFrom utils installed.packages
#'
#' @title Add address information to a dataframe
#'
Expand Down Expand Up @@ -53,7 +52,7 @@ addGoogleAddress <- function(

# Use ggmap::revgeocode to return a dataframe with (address, street number, route, locality , ...)
# (2500 queries allowed per day in August, 2015)
if ('ggmap' %in% installed.packages()[,1]) {
if ( length(find.package("ggmap", quiet = TRUE)) > 0 ) {

for ( i in seq_len(nrow(df)) ) {

Expand Down
4 changes: 2 additions & 2 deletions R/addGoogleElevation.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @keywords internal
#' @export
#' @import MazamaCoreUtils
#' @importFrom utils installed.packages
#'
#' @title Add Elevation Data to a Dataframe
#' @param df dataframe with geolocation information (\emph{e.g.} those created by \code{wrcc_qualityControl()} or \code{airsis_qualityControl})
#' @param lonVar name of longitude variable in the incoming dataframe
Expand Down Expand Up @@ -69,7 +69,7 @@ addGoogleElevation <- function(
dfList <- list()
for (i in 1:loopCount) {

startIndex <- (i-1) * 300 + 1
startIndex <- (i - 1) * 300 + 1
if (i != loopCount) {
endIndex <- i * 300
} else {
Expand Down
14 changes: 6 additions & 8 deletions R/addUSGSElevation.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#' @export
#' @import MazamaCoreUtils
#'
#' @importFrom utils installed.packages
#'
#' @title Add Elevation Data to a Dataframe
#' @param df dataframe with geolocation information (\emph{e.g.} created by \code{wrcc_qualityControl()} or \code{airsis_qualityControl})
#' @param lonVar name of longitude variable in the incoming dataframe
Expand All @@ -24,7 +22,7 @@ addUSGSElevation <- function(
logger.debug(" ----- addUSGSElevation() ----- ")

# Sanity check -- make sure df does not have class "tbl_df" or "tibble"
df <- as.data.frame(df, stringsAsFactors=FALSE)
df <- as.data.frame(df, stringsAsFactors = FALSE)

# Sanity check -- names
if ( !lonVar %in% names(df) || !latVar %in% names(df) ) {
Expand All @@ -46,7 +44,7 @@ addUSGSElevation <- function(
# NOTE: If existingMeta is passed in, assume we are in an operational environment where we want to minimize web service calls.

# Sanity check -- make sure df does not have class "tbl_df" or "tibble"
df <- as.data.frame(df, stringsAsFactors=FALSE)
df <- as.data.frame(df, stringsAsFactors = FALSE)

for ( i in seq_len(nrow(df)) ) {
monitorID <- df[i,'monitorID']
Expand All @@ -73,10 +71,10 @@ addUSGSElevation <- function(
lon <- lons[i]
lat <- lats[i]

url$query <- list(x=lon,
y=lat,
units='Meters',
output='json')
url$query <- list(x = lon,
y = lat,
units = 'Meters',
output = 'json')

# Get and parse the return
r <- httr::GET(httr::build_url(url))
Expand Down
2 changes: 2 additions & 0 deletions R/airsis_createRawDataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#'
#' @examples
#' \dontrun{
#' library(PWFSLSmoke)
#'
#' raw <- airsis_createRawDataframe(startdate = 20160901,
#' provider = 'USFS',
#' unitID = '1033')
Expand Down
24 changes: 15 additions & 9 deletions R/monitor_aqi.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
#' @references \url{https://docs.airnowapi.org/aq101}
#' @examples
#' \dontrun{
#' library(PWFSLSmoke)
#'
#' ws_monitor <- monitor_subset(Northwest_Megafires, tlim=c(20150815,20150831))
#' aqi <- monitor_aqi(ws_monitor)
#' monitor_timeseriesPlot(aqi, monitorID=aqi$meta$monitorID[1], ylab="PM25 AQI")
#' }

# NOTE: set up with argument to handle pm25 only; but write code to handle other pollutants if we ever get there

monitor_aqi <- function(ws_monitor,
aqiParameter='pm25',
nowcastVersion='pm',
includeShortTerm=FALSE) {
monitor_aqi <- function(
ws_monitor,
aqiParameter = 'pm25',
nowcastVersion = 'pm',
includeShortTerm = FALSE
) {

# Sanity check
if ( monitor_isEmpty(ws_monitor) ) stop("ws_monitor object contains zero monitors")
Expand All @@ -40,7 +44,7 @@ monitor_aqi <- function(ws_monitor,
data[data<0] <- 0

# TODO: include/expand checks to ensure values are appropriately truncated
if ( aqiParameter=="pm25" || nowcastVersion=="pm" ) {
if ( aqiParameter == "pm25" || nowcastVersion == "pm" ) {
digits <- 1
} else {
digits <- 0
Expand Down Expand Up @@ -80,10 +84,12 @@ monitor_aqi <- function(ws_monitor,

if ( parameter == "pm25") {
# From Table 2 at https://www.ecfr.gov/cgi-bin/retrieveECFR?n=40y6.0.1.1.6#ap40.6.58_161.g
breakpointsTable <- data.frame(rangeLow=c(0.0, 12.1, 35.5, 55.5, 150.5, 250.5, 350.5),
rangeHigh=c(12.0, 35.4, 55.4, 150.4, 250.4, 350.4, 500.4),
aqiLow=c(0, 51, 101, 151, 201, 301, 401),
aqiHigh=c(50, 100, 150, 200, 300, 400, 500))
breakpointsTable <- data.frame(
rangeLow = c(0.0, 12.1, 35.5, 55.5, 150.5, 250.5, 350.5),
rangeHigh = c(12.0, 35.4, 55.4, 150.4, 250.4, 350.4, 500.4),
aqiLow = c(0, 51, 101, 151, 201, 301, 401),
aqiHigh = c(50, 100, 150, 200, 300, 400, 500)
)
} else {
stop("only pm25 currently supported")
}
Expand Down
7 changes: 6 additions & 1 deletion R/monitor_asDataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@
#' @seealso \code{\link{monitor_nowcast}}
#' @seealso \code{\link{monitor_dailyStatistic}}
#' @examples
#' \dontrun{
#' \donttest{
#' library(PWFSLSmoke)
#'
#' wa <- monitor_subset(Northwest_Megafires, stateCodes='WA')
#'
#' Omak_df <- monitor_asDataframe(wa, monitorID='530470013_01',
#' extraColumns=c('nowcast','dailyAvg'),
#' metaColumns=c('aqsID','siteName','timezone'),
#' tlim=c(20150801,20150901))
#'
#' dplyr::glimpse(Omak_df)
#' }


Expand Down
4 changes: 4 additions & 0 deletions R/monitor_collapse.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@
#' @export
#'
#' @examples
#' library(PWFSLSmoke)
#'
#' N_M <- Northwest_Megafires
#' # monitor_leaflet(N_M) # to identify Spokane monitorIDs
#'
#' Spokane <- monitor_subsetBy(N_M, stringr::str_detect(N_M$meta$monitorID,'^53063'))
#' Spokane_min <- monitor_collapse(Spokane, monitorID='Spokane_min', FUN=min)
#' Spokane_max <- monitor_collapse(Spokane, monitorID='Spokane_max', FUN=max)
#'
#' monitor_timeseriesPlot(Spokane, tlim=c(20150619,20150626),
#' style='gnats', shadedNight=TRUE)
#' monitor_timeseriesPlot(Spokane_max, col='red', type='s', add=TRUE)
Expand Down
10 changes: 8 additions & 2 deletions R/monitor_combine.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@
#' objects. This can be used to 'grow' a \emph{ws_monitor} object by appending subsequent months
#' or years. (Note, however, that this can be CPU intensive process.)
#' @examples
#' \dontrun{
#' \donttest{
#' library(PWFSLSmoke)
#' initializeMazamaSpatialUtils()
#'
#' monitorList <- list()
#' monitorList[[1]] <- airsis_createMonitorObject(20160701, 20161231, 'USFS', '1031')
#' monitorList[[2]] <- airsis_createMonitorObject(20160701, 20161231, 'USFS', '1032')
#' monitorList[[3]] <- airsis_createMonitorObject(20160701, 20161231, 'USFS', '1033')
#' monitorList[[4]] <- airsis_createMonitorObject(20160701, 20161231, 'USFS', '1034')
#' ws_monitor <- monitor_combine(monitorList)
#' monitor_leaflet(ws_monitor)
#'
#' if ( interactive() ) {
#' monitor_leaflet(ws_monitor)
#' }
#' }

monitor_combine <- function(monitorList) {
Expand Down
5 changes: 3 additions & 2 deletions R/monitor_dailyBarplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
#' @export
#'
#' @examples
#' \dontrun{
#' library(PWFSLSmoke)
#'
#' N_M <- monitor_subset(Northwest_Megafires, tlim = c(20150715, 20150930))
#' main <- "Daily Average PM2.5 for Omak, WA"
#' monitor_dailyBarplot(N_M, monitorID = "530470013_01", main = main,
#' labels_x_nudge = 1)
#' addAQILegend(fill = rev(AQI$colors), pch = NULL)
#' }

monitor_dailyBarplot <- function(ws_monitor,
monitorID = NULL,
tlim = NULL,
Expand Down
2 changes: 1 addition & 1 deletion R/monitor_dailyStatistic.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' The returned \emph{ws_monitor} object has a daily time axis where each
#' \code{datetime} is set to the beginning of each day, 00:00:00, local time.
#' @examples
#' \dontrun{
#' \donttest{
#' N_M <- monitor_subset(Northwest_Megafires, tlim=c(20150801,20150831))
#' WinthropID <- '530470010_01'
#' TwispID <- '530470009_01'
Expand Down
7 changes: 6 additions & 1 deletion R/monitor_dailyStatisticList.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@
#'
#' @references \link{monitor_dailyStatistic}
#' @examples
#' \dontrun{
#' \donttest{
#' library(PWFSLSmoke)
#'
#' airnow <- airnow_loadLatest()
#' nw <- monitor_subset(airnow, stateCodes = c('WA','OR','ID','MT'))
#' dailyList <- monitor_dailyStatisticList(nw)
#'
#' monitor_leaflet(dailyList[["America/Los_Angeles"]])
#'
#' monitor_leaflet(dailyList[["America/Boise"]])
#'
#' monitor_leaflet(dailyList[["America/Denver"]])
#' }

Expand Down
4 changes: 2 additions & 2 deletions R/monitor_dailyThreshold.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
#'
#' The returned \emph{ws_monitor} object has a daily time axis where each time is set to 00:00, local time.
#' @examples
#' \dontrun{
#' library(PWFSLSmoke)
#'
#' N_M <- monitor_subset(Northwest_Megafires, tlim=c(20150801,20150831))
#' Twisp <- monitor_subset(N_M, monitorIDs='530470009_01')
#' Twisp_daily <- monitor_dailyThreshold(Twisp, "unhealthy", dayStart='midnight', minHours=1)
#' monitor_timeseriesPlot(Twisp_daily, type='h', lwd=6, ylab="Hours")
#' title("Twisp, Washington Hours per day Above 'Unhealthy', 2015")
#' }

monitor_dailyThreshold <- function(ws_monitor,
threshold="unhealthy",
Expand Down
2 changes: 2 additions & 0 deletions R/monitor_distance.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#' @return Vector of of distances (km).
#' @seealso \code{\link{distance}}
#' @examples
#' library(PWFSLSmoke)
#'
#' N_M <- Northwest_Megafires
#' # Walla Walla
#' WW_lon <- -118.330278
Expand Down
22 changes: 13 additions & 9 deletions R/monitor_downloadAnnual.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,21 @@
#' \href{https://haze.airfire.org/monitoring/latest/RData/}{https://haze.airfire.org/monitoring/latest/RData/}
#' @seealso \code{\link{monitor_loadDaily}}
#' @examples
#' \dontrun{
#' monitor_loadLatest() %>%
#' monitor_subset(stateCodes=CONUS) %>%
#' monitor_map()
#' \donttest{
#' library(PWFSLSmoke)
#'
#' monitor_loadAnnual(2018) %>%
#' monitor_subset(stateCodes = "WA", tlim = c(20180701, 20181001)) %>%
#' monitor_timeseriesPlot(style = 'gnats')
#' }

monitor_downloadAnnual <- function(year = NULL,
parameter='PM2.5',
baseUrl='https://haze.airfire.org/monitoring',
dataDir = "~/Data/monitoring/RData",
...) {
monitor_downloadAnnual <- function(
year = NULL,
parameter='PM2.5',
baseUrl='https://haze.airfire.org/monitoring',
dataDir = "~/Data/monitoring/RData",
...
) {

# Validate parameters --------------------------------------------------------

Expand Down
4 changes: 3 additions & 1 deletion R/monitor_downloadDaily.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
#' \href{https://haze.airfire.org/monitoring/latest/RData/}{https://haze.airfire.org/monitoring/latest/RData/}
#' @seealso \code{\link{monitor_loadDaily}}
#' @examples
#' \dontrun{
#' \donttest{
#' library(PWFSLSmoke)
#'
#' monitor_loadLatest() %>%
#' monitor_subset(stateCodes=CONUS) %>%
#' monitor_map()
Expand Down
4 changes: 3 additions & 1 deletion R/monitor_downloadLatest.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
#' \href{https://haze.airfire.org/monitoring/latest/RData/}{https://haze.airfire.org/monitoring/latest/RData/}
#' @seealso \code{\link{monitor_loadDaily}}
#' @examples
#' \dontrun{
#' \donttest{
#' library(PWFSLSmoke)
#'
#' monitor_loadLatest() %>%
#' monitor_subset(stateCodes=CONUS) %>%
#' monitor_map()
Expand Down
21 changes: 15 additions & 6 deletions R/monitor_dygraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,25 @@
#' in RStudio's 'Viewer' tab.
#' @return Initiates the interactive dygraph plot in RStudio's 'Viewer' tab.
#' @examples
#' \dontrun{
#' \donttest{
#' library(PWFSLSmoke)
#'
#' # Napa Fires -- October, 2017
#' ca <- airnow_load(2017) %>%
#' monitor_subset(tlim=c(20171001,20171101), stateCodes='CA')
#'
#' Vallejo <- monitor_subset(ca, monitorIDs='060950004_01')
#' Napa_Fires <- monitor_subsetByDistance(ca,
#' longitude = Vallejo$meta$longitude,
#' latitude = Vallejo$meta$latitude,
#' radius = 50)
#' monitor_dygraph(Napa_Fires, title='Napa Fires in California, Oct. 2017')
#'
#' Napa_Fires <- monitor_subsetByDistance(
#' ca,
#' longitude = Vallejo$meta$longitude,
#' latitude = Vallejo$meta$latitude,
#' radius = 50
#' )
#'
#' if ( interactive() ) {
#' monitor_dygraph(Napa_Fires, title='Napa Fires in California, Oct. 2017')
#' }
#' }

monitor_dygraph <- function(ws_monitor,
Expand Down
Loading

0 comments on commit d2e1cc0

Please sign in to comment.