From a8a1effa488385bbf30ce267c85220c595a65f1f Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Sat, 13 Jan 2018 15:17:23 +0100 Subject: [PATCH] make R CMD check --as-cran pass fixes #9 also update examples & shorten their runtime a bit --- .Rbuildignore | 3 ++- .gitignore | 2 ++ DESCRIPTION | 18 ++++++++++++------ NAMESPACE | 2 ++ R/box.R | 2 +- R/box_utils.R | 4 ++-- R/measurement.R | 8 +++----- R/measurement_utils.R | 3 +-- R/opensensmapr.R | 10 +++++----- R/phenomena.R | 4 ++-- man/opensensmapr.Rd | 11 +++++++---- man/osem_as_sensebox.Rd | 4 ++-- man/osem_box.Rd | 2 +- man/osem_measurements.Rd | 8 +++----- man/osem_phenomena.Rd | 4 ++-- 15 files changed, 47 insertions(+), 38 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index d357573..d1a82a8 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,4 @@ ^.*\.Rproj$ ^\.Rproj\.user$ -^tools/.*$ +^CHANGES\.md$ +^tools*$ diff --git a/.gitignore b/.gitignore index c0b492c..0cc62cc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,7 @@ .Rhistory .RData .Ruserdata +..Rcheck *.log +opensensmapr_*.tar.gz diff --git a/DESCRIPTION b/DESCRIPTION index 15c41de..3cbb1bb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,13 +15,19 @@ Suggests: rgeos, sf, knitr, - rmarkdown + rmarkdown, + lubridate, + units Author: Norwin Roosen -Maintainer: Norwin Roosen -Description: This package ingests data (measurements, sensorstations) from the - API of opensensemap.org for analysis in R. - The package aims to be compatible with sf and the tidyverse. -License: GPL-2 +Maintainer: Norwin Roosen +Description: Download data (environmental measurements, sensorstations) from the + API of open data sensor web platform 'opensensemap.org' for analysis in R. + This platform provides realtime data of more than 1000 low-cost sensor + stations for PM10, PM2.5, temperature, humidity, UV-A intensity and more + phenomena. + The package aims to be compatible with sf and the tidyverse, and provides + several helper functions for data exploration and transformation. +License: GPL (>= 2) | file LICENSE Encoding: UTF-8 LazyData: true RoxygenNote: 6.0.1 diff --git a/NAMESPACE b/NAMESPACE index bdd93a5..89b3a1a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -24,5 +24,7 @@ export(osem_measurements) export(osem_phenomena) export(st_as_sf.osem_measurements) export(st_as_sf.sensebox) +importFrom(graphics,legend) +importFrom(graphics,par) importFrom(graphics,plot) importFrom(magrittr,"%>%") diff --git a/R/box.R b/R/box.R index d5076a9..dcc2b73 100644 --- a/R/box.R +++ b/R/box.R @@ -85,7 +85,7 @@ osem_boxes = function (exposure = NA, model = NA, grouptag = NA, #' @export #' @examples #' # get a specific box by ID -#' b = osem_box('593bcd656ccf3b0011791f5a') +#' b = osem_box('57000b8745fd40c8196ad04c') #' osem_box = function (boxId, endpoint = 'https://api.opensensemap.org') { get_box_(boxId, endpoint = endpoint) diff --git a/R/box_utils.R b/R/box_utils.R index 8992ba7..c8be288 100644 --- a/R/box_utils.R +++ b/R/box_utils.R @@ -75,7 +75,7 @@ summary.sensebox = function(object, ...) { # ============================================================================== # -#' Converts a foreign object to an sensebox data.frame. +#' Converts a foreign object to a sensebox data.frame. #' @param x A data.frame to attach the class to #' @export osem_as_sensebox = function(x) { @@ -120,6 +120,6 @@ mutate.sensebox = dplyr_class_wrapper(osem_as_sensebox) #' @return The object with an st_geometry column attached. #' @export st_as_sf.sensebox = function (x, ...) { - sf:::st_as_sf.data.frame(x, ..., coords = c('lon', 'lat'), crs = 4326) + NextMethod(x, ..., coords = c('lon', 'lat'), crs = 4326) } diff --git a/R/measurement.R b/R/measurement.R index b24cbaf..48b69e9 100644 --- a/R/measurement.R +++ b/R/measurement.R @@ -36,9 +36,7 @@ osem_measurements = function (x, ...) UseMethod('osem_measurements') #' @export #' @examples #' # get measurements from all boxes -#' \dontrun{ -#' osem_measurements('PM2.5') -#' } +#' osem_measurements('Windrichtung') #' osem_measurements.default = function (x, ...) { bbox = structure(c(-180, -90, 180, 90), class = 'bbox') @@ -54,7 +52,7 @@ osem_measurements.default = function (x, ...) { #' bbox = structure(c(7, 51, 8, 52), class = 'bbox') #' osem_measurements(bbox, 'Temperatur') #' -#' points = sf::st_multipoint(matrix(c(7, 8, 51, 52), 2, 2)) +#' points = sf::st_multipoint(matrix(c(7.5, 7.8, 51.7, 52), 2, 2)) #' bbox2 = sf::st_bbox(points) #' osem_measurements(bbox2, 'Temperatur', exposure = 'outdoor') #' @@ -80,7 +78,7 @@ osem_measurements.bbox = function (x, phenomenon, exposure = NA, #' osem_measurements(b, phenomenon = 'Temperatur') #' #' # ...or a single box -#' b = osem_box('593bcd656ccf3b0011791f5a') +#' b = osem_box('57000b8745fd40c8196ad04c') #' osem_measurements(b, phenomenon = 'Temperatur') #' osem_measurements.sensebox = function (x, phenomenon, exposure = NA, diff --git a/R/measurement_utils.R b/R/measurement_utils.R index e7acc83..75d83d1 100644 --- a/R/measurement_utils.R +++ b/R/measurement_utils.R @@ -56,6 +56,5 @@ mutate.osem_measurements = dplyr_class_wrapper(osem_as_measurements) #' @return The object with an st_geometry column attached. #' @export st_as_sf.osem_measurements = function (x, ...) { - sf:::st_as_sf.data.frame(x, ..., coords = c('lon', 'lat'), crs = 4326) + NextMethod(x, ..., coords = c('lon', 'lat'), crs = 4326) } - diff --git a/R/opensensmapr.R b/R/opensensmapr.R index 7a8b6ef..e1b1833 100644 --- a/R/opensensmapr.R +++ b/R/opensensmapr.R @@ -7,8 +7,8 @@ #' \item general statistics about the openSenseMap database. #' } #' Additionally, helper functions are provided to ease the integration with the -#' \code{\link{sf}} package for spatial analysis as well as \code{\link{dplyr}} -#' for general data handling. +#' \code{\link[sf]{sf}} package for spatial analysis as well as +#' \code{\link[dplyr]{dplyr}} for general data handling. #' #' @section Retrieving senseBox metadata: #' On the openSenseMap, measurements are provided by sensors which are assigned @@ -44,7 +44,7 @@ #' \item a list of senseBoxes, previously retrieved through #' \code{\link{osem_box}} or \code{\link{osem_boxes}}. #' \item a geographic bounding box, which can be generated with the -#' \code{\link{sf}} package. +#' \code{\link[sf]{sf}} package. #' \item a time frame #' \item a exposure type of the given box #' } @@ -63,7 +63,7 @@ #' Transform a foreign object to a sensebox data.frame or osem_measurements #' by attaching the required classes and attributes. #' \item \code{\link{st_as_sf.sensebox}} & \code{\link{st_as_sf.osem_measurements}}: -#' Transform the senseBoxes or measurements into an \code{\link{sf}} +#' Transform the senseBoxes or measurements into an \code{\link[sf]{sf}} #' compatible format for spatial analysis. #' \item \code{filter.sensebox()} & \code{mutate.sensebox()}: for use with #' \code{\link{dplyr}}. @@ -76,7 +76,7 @@ #' @name opensensmapr '_PACKAGE' -#' @importFrom graphics plot +#' @importFrom graphics plot legend par #' @importFrom magrittr %>% `%>%` = magrittr::`%>%` diff --git a/R/phenomena.R b/R/phenomena.R index 1309e5e..a6caa06 100644 --- a/R/phenomena.R +++ b/R/phenomena.R @@ -23,9 +23,9 @@ osem_phenomena = function (boxes) UseMethod('osem_phenomena') #' osem_boxes(grouptag = 'ifgi', exposure = 'outdoor', date = Sys.time()) #' ) #' -#' # get phenomena with at least 10 sensors on opensensemap +#' # get phenomena with at least 30 sensors on opensensemap #' phenoms = osem_phenomena(osem_boxes()) -#' names(phenoms[phenoms > 9]) +#' names(phenoms[phenoms > 29]) #' osem_phenomena.sensebox = function (boxes) { p = Reduce(`c`, boxes$phenomena) %>% # get all the row contents in a single vector diff --git a/man/opensensmapr.Rd b/man/opensensmapr.Rd index 21c1d82..72ddee2 100644 --- a/man/opensensmapr.Rd +++ b/man/opensensmapr.Rd @@ -14,8 +14,8 @@ The opensensmapr package provides functions for \item general statistics about the openSenseMap database. } Additionally, helper functions are provided to ease the integration with the -\code{\link{sf}} package for spatial analysis as well as \code{\link{dplyr}} -for general data handling. +\code{\link[sf]{sf}} package for spatial analysis as well as +\code{\link[dplyr]{dplyr}} for general data handling. } \section{Retrieving senseBox metadata}{ @@ -54,7 +54,7 @@ given phenomenon only. A subset of measurements may be selected by \item a list of senseBoxes, previously retrieved through \code{\link{osem_box}} or \code{\link{osem_boxes}}. \item a geographic bounding box, which can be generated with the - \code{\link{sf}} package. + \code{\link[sf]{sf}} package. \item a time frame \item a exposure type of the given box } @@ -73,8 +73,11 @@ The package aims to be compatible with the tidyverse. Helpers are implemented to ease the further usage of the retrieved data: \itemize{ + \item \code{\link{osem_as_sensebox}} & \code{\link{osem_as_measurements}}: + Transform a foreign object to a sensebox data.frame or osem_measurements + by attaching the required classes and attributes. \item \code{\link{st_as_sf.sensebox}} & \code{\link{st_as_sf.osem_measurements}}: - Transform the senseBoxes or measurements into an \code{\link{sf}} + Transform the senseBoxes or measurements into an \code{\link[sf]{sf}} compatible format for spatial analysis. \item \code{filter.sensebox()} & \code{mutate.sensebox()}: for use with \code{\link{dplyr}}. diff --git a/man/osem_as_sensebox.Rd b/man/osem_as_sensebox.Rd index 904cca1..9d13a07 100644 --- a/man/osem_as_sensebox.Rd +++ b/man/osem_as_sensebox.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/box_utils.R \name{osem_as_sensebox} \alias{osem_as_sensebox} -\title{Converts a foreign object to an sensebox data.frame.} +\title{Converts a foreign object to a sensebox data.frame.} \usage{ osem_as_sensebox(x) } @@ -10,5 +10,5 @@ osem_as_sensebox(x) \item{x}{A data.frame to attach the class to} } \description{ -Converts a foreign object to an sensebox data.frame. +Converts a foreign object to a sensebox data.frame. } diff --git a/man/osem_box.Rd b/man/osem_box.Rd index cecb0ac..656d5a9 100644 --- a/man/osem_box.Rd +++ b/man/osem_box.Rd @@ -19,7 +19,7 @@ Get a single senseBox by its ID } \examples{ # get a specific box by ID -b = osem_box('593bcd656ccf3b0011791f5a') +b = osem_box('57000b8745fd40c8196ad04c') } \seealso{ diff --git a/man/osem_measurements.Rd b/man/osem_measurements.Rd index 735cb07..7ec3b90 100644 --- a/man/osem_measurements.Rd +++ b/man/osem_measurements.Rd @@ -64,15 +64,13 @@ a bounding box spanning the whole world. \examples{ # get measurements from all boxes -\dontrun{ -osem_measurements('PM2.5') -} +osem_measurements('Windrichtung') # get measurements from sensors within a bounding box bbox = structure(c(7, 51, 8, 52), class = 'bbox') osem_measurements(bbox, 'Temperatur') -points = sf::st_multipoint(matrix(c(7, 8, 51, 52), 2, 2)) +points = sf::st_multipoint(matrix(c(7.5, 7.8, 51.7, 52), 2, 2)) bbox2 = sf::st_bbox(points) osem_measurements(bbox2, 'Temperatur', exposure = 'outdoor') @@ -81,7 +79,7 @@ b = osem_boxes(grouptag = 'ifgi') osem_measurements(b, phenomenon = 'Temperatur') # ...or a single box -b = osem_box('593bcd656ccf3b0011791f5a') +b = osem_box('57000b8745fd40c8196ad04c') osem_measurements(b, phenomenon = 'Temperatur') } diff --git a/man/osem_phenomena.Rd b/man/osem_phenomena.Rd index 14f7b0f..f16e823 100644 --- a/man/osem_phenomena.Rd +++ b/man/osem_phenomena.Rd @@ -34,9 +34,9 @@ osem_phenomena( osem_boxes(grouptag = 'ifgi', exposure = 'outdoor', date = Sys.time()) ) -# get phenomena with at least 10 sensors on opensensemap +# get phenomena with at least 30 sensors on opensensemap phenoms = osem_phenomena(osem_boxes()) -names(phenoms[phenoms > 9]) +names(phenoms[phenoms > 29]) } \seealso{