mirror of
https://github.com/sensebox/opensensmapr
synced 2025-03-11 20:30:27 +01:00
make R CMD check --as-cran pass
fixes #9 also update examples & shorten their runtime a bit
This commit is contained in:
parent
44d9026936
commit
a8a1effa48
15 changed files with 47 additions and 38 deletions
|
@ -1,3 +1,4 @@
|
||||||
^.*\.Rproj$
|
^.*\.Rproj$
|
||||||
^\.Rproj\.user$
|
^\.Rproj\.user$
|
||||||
^tools/.*$
|
^CHANGES\.md$
|
||||||
|
^tools*$
|
||||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,5 +3,7 @@
|
||||||
.Rhistory
|
.Rhistory
|
||||||
.RData
|
.RData
|
||||||
.Ruserdata
|
.Ruserdata
|
||||||
|
..Rcheck
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
|
opensensmapr_*.tar.gz
|
||||||
|
|
18
DESCRIPTION
18
DESCRIPTION
|
@ -15,13 +15,19 @@ Suggests:
|
||||||
rgeos,
|
rgeos,
|
||||||
sf,
|
sf,
|
||||||
knitr,
|
knitr,
|
||||||
rmarkdown
|
rmarkdown,
|
||||||
|
lubridate,
|
||||||
|
units
|
||||||
Author: Norwin Roosen
|
Author: Norwin Roosen
|
||||||
Maintainer: Norwin Roosen <maintenance@nroo.de>
|
Maintainer: Norwin Roosen <bugs@nroo.de>
|
||||||
Description: This package ingests data (measurements, sensorstations) from the
|
Description: Download data (environmental measurements, sensorstations) from the
|
||||||
API of opensensemap.org for analysis in R.
|
API of open data sensor web platform 'opensensemap.org' for analysis in R.
|
||||||
The package aims to be compatible with sf and the tidyverse.
|
This platform provides realtime data of more than 1000 low-cost sensor
|
||||||
License: GPL-2
|
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
|
Encoding: UTF-8
|
||||||
LazyData: true
|
LazyData: true
|
||||||
RoxygenNote: 6.0.1
|
RoxygenNote: 6.0.1
|
||||||
|
|
|
@ -24,5 +24,7 @@ export(osem_measurements)
|
||||||
export(osem_phenomena)
|
export(osem_phenomena)
|
||||||
export(st_as_sf.osem_measurements)
|
export(st_as_sf.osem_measurements)
|
||||||
export(st_as_sf.sensebox)
|
export(st_as_sf.sensebox)
|
||||||
|
importFrom(graphics,legend)
|
||||||
|
importFrom(graphics,par)
|
||||||
importFrom(graphics,plot)
|
importFrom(graphics,plot)
|
||||||
importFrom(magrittr,"%>%")
|
importFrom(magrittr,"%>%")
|
||||||
|
|
2
R/box.R
2
R/box.R
|
@ -85,7 +85,7 @@ osem_boxes = function (exposure = NA, model = NA, grouptag = NA,
|
||||||
#' @export
|
#' @export
|
||||||
#' @examples
|
#' @examples
|
||||||
#' # get a specific box by ID
|
#' # get a specific box by ID
|
||||||
#' b = osem_box('593bcd656ccf3b0011791f5a')
|
#' b = osem_box('57000b8745fd40c8196ad04c')
|
||||||
#'
|
#'
|
||||||
osem_box = function (boxId, endpoint = 'https://api.opensensemap.org') {
|
osem_box = function (boxId, endpoint = 'https://api.opensensemap.org') {
|
||||||
get_box_(boxId, endpoint = endpoint)
|
get_box_(boxId, endpoint = endpoint)
|
||||||
|
|
|
@ -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
|
#' @param x A data.frame to attach the class to
|
||||||
#' @export
|
#' @export
|
||||||
osem_as_sensebox = function(x) {
|
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.
|
#' @return The object with an st_geometry column attached.
|
||||||
#' @export
|
#' @export
|
||||||
st_as_sf.sensebox = function (x, ...) {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,7 @@ osem_measurements = function (x, ...) UseMethod('osem_measurements')
|
||||||
#' @export
|
#' @export
|
||||||
#' @examples
|
#' @examples
|
||||||
#' # get measurements from all boxes
|
#' # get measurements from all boxes
|
||||||
#' \dontrun{
|
#' osem_measurements('Windrichtung')
|
||||||
#' osem_measurements('PM2.5')
|
|
||||||
#' }
|
|
||||||
#'
|
#'
|
||||||
osem_measurements.default = function (x, ...) {
|
osem_measurements.default = function (x, ...) {
|
||||||
bbox = structure(c(-180, -90, 180, 90), class = 'bbox')
|
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')
|
#' bbox = structure(c(7, 51, 8, 52), class = 'bbox')
|
||||||
#' osem_measurements(bbox, 'Temperatur')
|
#' 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)
|
#' bbox2 = sf::st_bbox(points)
|
||||||
#' osem_measurements(bbox2, 'Temperatur', exposure = 'outdoor')
|
#' osem_measurements(bbox2, 'Temperatur', exposure = 'outdoor')
|
||||||
#'
|
#'
|
||||||
|
@ -80,7 +78,7 @@ osem_measurements.bbox = function (x, phenomenon, exposure = NA,
|
||||||
#' osem_measurements(b, phenomenon = 'Temperatur')
|
#' osem_measurements(b, phenomenon = 'Temperatur')
|
||||||
#'
|
#'
|
||||||
#' # ...or a single box
|
#' # ...or a single box
|
||||||
#' b = osem_box('593bcd656ccf3b0011791f5a')
|
#' b = osem_box('57000b8745fd40c8196ad04c')
|
||||||
#' osem_measurements(b, phenomenon = 'Temperatur')
|
#' osem_measurements(b, phenomenon = 'Temperatur')
|
||||||
#'
|
#'
|
||||||
osem_measurements.sensebox = function (x, phenomenon, exposure = NA,
|
osem_measurements.sensebox = function (x, phenomenon, exposure = NA,
|
||||||
|
|
|
@ -56,6 +56,5 @@ mutate.osem_measurements = dplyr_class_wrapper(osem_as_measurements)
|
||||||
#' @return The object with an st_geometry column attached.
|
#' @return The object with an st_geometry column attached.
|
||||||
#' @export
|
#' @export
|
||||||
st_as_sf.osem_measurements = function (x, ...) {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
#' \item general statistics about the openSenseMap database.
|
#' \item general statistics about the openSenseMap database.
|
||||||
#' }
|
#' }
|
||||||
#' Additionally, helper functions are provided to ease the integration with the
|
#' Additionally, helper functions are provided to ease the integration with the
|
||||||
#' \code{\link{sf}} package for spatial analysis as well as \code{\link{dplyr}}
|
#' \code{\link[sf]{sf}} package for spatial analysis as well as
|
||||||
#' for general data handling.
|
#' \code{\link[dplyr]{dplyr}} for general data handling.
|
||||||
#'
|
#'
|
||||||
#' @section Retrieving senseBox metadata:
|
#' @section Retrieving senseBox metadata:
|
||||||
#' On the openSenseMap, measurements are provided by sensors which are assigned
|
#' On the openSenseMap, measurements are provided by sensors which are assigned
|
||||||
|
@ -44,7 +44,7 @@
|
||||||
#' \item a list of senseBoxes, previously retrieved through
|
#' \item a list of senseBoxes, previously retrieved through
|
||||||
#' \code{\link{osem_box}} or \code{\link{osem_boxes}}.
|
#' \code{\link{osem_box}} or \code{\link{osem_boxes}}.
|
||||||
#' \item a geographic bounding box, which can be generated with the
|
#' \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 time frame
|
||||||
#' \item a exposure type of the given box
|
#' \item a exposure type of the given box
|
||||||
#' }
|
#' }
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
#' Transform a foreign object to a sensebox data.frame or osem_measurements
|
#' Transform a foreign object to a sensebox data.frame or osem_measurements
|
||||||
#' by attaching the required classes and attributes.
|
#' by attaching the required classes and attributes.
|
||||||
#' \item \code{\link{st_as_sf.sensebox}} & \code{\link{st_as_sf.osem_measurements}}:
|
#' \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.
|
#' compatible format for spatial analysis.
|
||||||
#' \item \code{filter.sensebox()} & \code{mutate.sensebox()}: for use with
|
#' \item \code{filter.sensebox()} & \code{mutate.sensebox()}: for use with
|
||||||
#' \code{\link{dplyr}}.
|
#' \code{\link{dplyr}}.
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
#' @name opensensmapr
|
#' @name opensensmapr
|
||||||
'_PACKAGE'
|
'_PACKAGE'
|
||||||
|
|
||||||
#' @importFrom graphics plot
|
#' @importFrom graphics plot legend par
|
||||||
|
|
||||||
#' @importFrom magrittr %>%
|
#' @importFrom magrittr %>%
|
||||||
`%>%` = magrittr::`%>%`
|
`%>%` = magrittr::`%>%`
|
||||||
|
|
|
@ -23,9 +23,9 @@ osem_phenomena = function (boxes) UseMethod('osem_phenomena')
|
||||||
#' osem_boxes(grouptag = 'ifgi', exposure = 'outdoor', date = Sys.time())
|
#' 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())
|
#' phenoms = osem_phenomena(osem_boxes())
|
||||||
#' names(phenoms[phenoms > 9])
|
#' names(phenoms[phenoms > 29])
|
||||||
#'
|
#'
|
||||||
osem_phenomena.sensebox = function (boxes) {
|
osem_phenomena.sensebox = function (boxes) {
|
||||||
p = Reduce(`c`, boxes$phenomena) %>% # get all the row contents in a single vector
|
p = Reduce(`c`, boxes$phenomena) %>% # get all the row contents in a single vector
|
||||||
|
|
|
@ -14,8 +14,8 @@ The opensensmapr package provides functions for
|
||||||
\item general statistics about the openSenseMap database.
|
\item general statistics about the openSenseMap database.
|
||||||
}
|
}
|
||||||
Additionally, helper functions are provided to ease the integration with the
|
Additionally, helper functions are provided to ease the integration with the
|
||||||
\code{\link{sf}} package for spatial analysis as well as \code{\link{dplyr}}
|
\code{\link[sf]{sf}} package for spatial analysis as well as
|
||||||
for general data handling.
|
\code{\link[dplyr]{dplyr}} for general data handling.
|
||||||
}
|
}
|
||||||
\section{Retrieving senseBox metadata}{
|
\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
|
\item a list of senseBoxes, previously retrieved through
|
||||||
\code{\link{osem_box}} or \code{\link{osem_boxes}}.
|
\code{\link{osem_box}} or \code{\link{osem_boxes}}.
|
||||||
\item a geographic bounding box, which can be generated with the
|
\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 time frame
|
||||||
\item a exposure type of the given box
|
\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:
|
Helpers are implemented to ease the further usage of the retrieved data:
|
||||||
|
|
||||||
\itemize{
|
\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}}:
|
\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.
|
compatible format for spatial analysis.
|
||||||
\item \code{filter.sensebox()} & \code{mutate.sensebox()}: for use with
|
\item \code{filter.sensebox()} & \code{mutate.sensebox()}: for use with
|
||||||
\code{\link{dplyr}}.
|
\code{\link{dplyr}}.
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
% Please edit documentation in R/box_utils.R
|
% Please edit documentation in R/box_utils.R
|
||||||
\name{osem_as_sensebox}
|
\name{osem_as_sensebox}
|
||||||
\alias{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{
|
\usage{
|
||||||
osem_as_sensebox(x)
|
osem_as_sensebox(x)
|
||||||
}
|
}
|
||||||
|
@ -10,5 +10,5 @@ osem_as_sensebox(x)
|
||||||
\item{x}{A data.frame to attach the class to}
|
\item{x}{A data.frame to attach the class to}
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Converts a foreign object to an sensebox data.frame.
|
Converts a foreign object to a sensebox data.frame.
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ Get a single senseBox by its ID
|
||||||
}
|
}
|
||||||
\examples{
|
\examples{
|
||||||
# get a specific box by ID
|
# get a specific box by ID
|
||||||
b = osem_box('593bcd656ccf3b0011791f5a')
|
b = osem_box('57000b8745fd40c8196ad04c')
|
||||||
|
|
||||||
}
|
}
|
||||||
\seealso{
|
\seealso{
|
||||||
|
|
|
@ -64,15 +64,13 @@ a bounding box spanning the whole world.
|
||||||
|
|
||||||
\examples{
|
\examples{
|
||||||
# get measurements from all boxes
|
# get measurements from all boxes
|
||||||
\dontrun{
|
osem_measurements('Windrichtung')
|
||||||
osem_measurements('PM2.5')
|
|
||||||
}
|
|
||||||
|
|
||||||
# get measurements from sensors within a bounding box
|
# get measurements from sensors within a bounding box
|
||||||
bbox = structure(c(7, 51, 8, 52), class = 'bbox')
|
bbox = structure(c(7, 51, 8, 52), class = 'bbox')
|
||||||
osem_measurements(bbox, 'Temperatur')
|
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)
|
bbox2 = sf::st_bbox(points)
|
||||||
osem_measurements(bbox2, 'Temperatur', exposure = 'outdoor')
|
osem_measurements(bbox2, 'Temperatur', exposure = 'outdoor')
|
||||||
|
|
||||||
|
@ -81,7 +79,7 @@ b = osem_boxes(grouptag = 'ifgi')
|
||||||
osem_measurements(b, phenomenon = 'Temperatur')
|
osem_measurements(b, phenomenon = 'Temperatur')
|
||||||
|
|
||||||
# ...or a single box
|
# ...or a single box
|
||||||
b = osem_box('593bcd656ccf3b0011791f5a')
|
b = osem_box('57000b8745fd40c8196ad04c')
|
||||||
osem_measurements(b, phenomenon = 'Temperatur')
|
osem_measurements(b, phenomenon = 'Temperatur')
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,9 @@ osem_phenomena(
|
||||||
osem_boxes(grouptag = 'ifgi', exposure = 'outdoor', date = Sys.time())
|
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())
|
phenoms = osem_phenomena(osem_boxes())
|
||||||
names(phenoms[phenoms > 9])
|
names(phenoms[phenoms > 29])
|
||||||
|
|
||||||
}
|
}
|
||||||
\seealso{
|
\seealso{
|
||||||
|
|
Loading…
Add table
Reference in a new issue