changed T and F to TRUE and FALSE

master
jan 1 year ago
parent 0e1d9e3cad
commit 6ebfc7f50a

@ -1,4 +1,4 @@
exclusions: list.files(path = 'inst/doc', full.names = T) exclusions: list.files(path = 'inst/doc', full.names = TRUE)
linters: with_defaults( linters: with_defaults(
# we use snake case # we use snake case
camel_case_linter = NULL, camel_case_linter = NULL,

@ -94,7 +94,7 @@ get_stats_ = function (endpoint, cache) {
#' @param cache Optional path to a directory were responses will be cached. If not NA, no requests will be made when a request for the given is already cached. #' @param cache Optional path to a directory were responses will be cached. If not NA, no requests will be made when a request for the given is already cached.
#' @return Result of a Request to openSenseMap API #' @return Result of a Request to openSenseMap API
#' @noRd #' @noRd
osem_get_resource = function (host, path, ..., type = 'parsed', progress = T, cache = NA) { osem_get_resource = function (host, path, ..., type = 'parsed', progress = TRUE, cache = NA) {
query = list(...) query = list(...)
if (!is.na(cache)) { if (!is.na(cache)) {
filename = osem_cache_filename(path, query, host) %>% paste(cache, ., sep = '/') filename = osem_cache_filename(path, query, host) %>% paste(cache, ., sep = '/')

@ -64,7 +64,7 @@ osem_measurements_archive.default = function (x, ...) {
#' sensorFilter = sensors #' sensorFilter = sensors
#' ) #' )
#' } #' }
osem_measurements_archive.sensebox = function (x, fromDate, toDate = fromDate, sensorFilter = ~ T, ..., progress = T) { osem_measurements_archive.sensebox = function (x, fromDate, toDate = fromDate, sensorFilter = ~ TRUE, ..., progress = TRUE) {
if (nrow(x) != 1) if (nrow(x) != 1)
stop('this function only works for exactly one senseBox!') stop('this function only works for exactly one senseBox!')

@ -159,7 +159,7 @@ parse_senseboxdata = function (boxdata) {
boxdata[c( boxdata[c(
'loc', 'locations', 'currentLocation', 'sensors', 'image', 'boxType', 'lastMeasurementAt', 'grouptag' 'loc', 'locations', 'currentLocation', 'sensors', 'image', 'boxType', 'lastMeasurementAt', 'grouptag'
)] = NULL )] = NULL
thebox = as.data.frame(boxdata, stringsAsFactors = F) thebox = as.data.frame(boxdata, stringsAsFactors = FALSE)
# parse timestamps (updatedAt might be not defined) # parse timestamps (updatedAt might be not defined)
thebox$createdAt = isostring_as_date(thebox$createdAt) thebox$createdAt = isostring_as_date(thebox$createdAt)
@ -176,7 +176,7 @@ parse_senseboxdata = function (boxdata) {
# create a dataframe of sensors # create a dataframe of sensors
thebox$sensors = sensors %>% thebox$sensors = sensors %>%
recursive_lapply(function (x) if (is.null(x)) NA else x) %>% # replace NULLs with NA recursive_lapply(function (x) if (is.null(x)) NA else x) %>% # replace NULLs with NA
lapply(as.data.frame, stringsAsFactors = F) %>% lapply(as.data.frame, stringsAsFactors = FALSE) %>%
dplyr::bind_rows(.) %>% dplyr::bind_rows(.) %>%
dplyr::select(phenomenon = title, id = X_id, unit, sensor = sensorType) %>% dplyr::select(phenomenon = title, id = X_id, unit, sensor = sensorType) %>%
list list

@ -22,8 +22,8 @@ plot.sensebox = function (x, ..., mar = c(2, 2, 1, 1)) {
oldpar = par() oldpar = par()
par(mar = mar) par(mar = mar)
plot(world, col = 'gray', xlim = bbox[c(1, 3)], ylim = bbox[c(2, 4)], axes = T, ...) plot(world, col = 'gray', xlim = bbox[c(1, 3)], ylim = bbox[c(2, 4)], axes = TRUE, ...)
plot(geom, add = T, col = x$exposure, ...) plot(geom, add = TRUE, col = x$exposure, ...)
legend('left', legend = levels(x$exposure), col = 1:length(x$exposure), pch = 1) legend('left', legend = levels(x$exposure), col = 1:length(x$exposure), pch = 1)
par(mar = oldpar$mar) par(mar = oldpar$mar)
@ -39,7 +39,7 @@ print.sensebox = function(x, columns = c('name', 'exposure', 'lastMeasurement',
#' @export #' @export
summary.sensebox = function(object, ...) { summary.sensebox = function(object, ...) {
cat('boxes total:', nrow(object), fill = T) cat('boxes total:', nrow(object), fill = TRUE)
cat('\nboxes by exposure:') cat('\nboxes by exposure:')
table(object$exposure) %>% print() table(object$exposure) %>% print()
cat('\nboxes by model:') cat('\nboxes by model:')
@ -59,10 +59,10 @@ summary.sensebox = function(object, ...) {
oldest = object[object$createdAt == min(object$createdAt), ] oldest = object[object$createdAt == min(object$createdAt), ]
newest = object[object$createdAt == max(object$createdAt), ] newest = object[object$createdAt == max(object$createdAt), ]
cat('oldest box:', format(oldest$createdAt, '%F %T'), paste0('(', oldest$name, ')'), fill = T) cat('oldest box:', format(oldest$createdAt, '%F %T'), paste0('(', oldest$name, ')'), fill = TRUE)
cat('newest box:', format(newest$createdAt, '%F %T'), paste0('(', newest$name, ')'), fill = T) cat('newest box:', format(newest$createdAt, '%F %T'), paste0('(', newest$name, ')'), fill = TRUE)
cat('\nsensors per box:', fill = T) cat('\nsensors per box:', fill = TRUE)
lapply(object$phenomena, length) %>% lapply(object$phenomena, length) %>%
as.numeric() %>% as.numeric() %>%
summary() %>% summary() %>%

@ -11,9 +11,9 @@ osem_measurements_archive(x, ...)
x, x,
fromDate, fromDate,
toDate = fromDate, toDate = fromDate,
sensorFilter = ~T, sensorFilter = ~TRUE,
..., ...,
progress = T progress = TRUE
) )
} }
\arguments{ \arguments{

@ -46,6 +46,15 @@ test_that('osem_measurements_archive works for one box', {
expect_s3_class(m, c('data.frame')) expect_s3_class(m, c('data.frame'))
}) })
test_that('osem_measurements_archive sensorFilter works for one box', {
check_api()
if (is.null(box)) skip('no box data could be fetched')
m = osem_measurements_archive(box, as.POSIXlt('2018-08-08'), sensorFilter = ~ phenomenon == 'Temperatur')
expect_length(m, 2) # one column for Temperatur + createdAt
expect_s3_class(m, c('data.frame'))
})
test_that('osem_measurements_archive fails for multiple boxes', { test_that('osem_measurements_archive fails for multiple boxes', {
check_api() check_api()
if (is.null(boxes)) skip('no box data available') if (is.null(boxes)) skip('no box data available')

@ -66,7 +66,7 @@ summary(boxes) -> summary.data.frame
Another feature of interest is the spatial distribution of the boxes: `plot()` Another feature of interest is the spatial distribution of the boxes: `plot()`
can help us out here. This function requires a bunch of optional dependencies though. can help us out here. This function requires a bunch of optional dependencies though.
```{r, message=F, warning=F} ```{r, message=FALSE, warning=FALSE}
if (!require('maps')) install.packages('maps') if (!require('maps')) install.packages('maps')
if (!require('maptools')) install.packages('maptools') if (!require('maptools')) install.packages('maptools')
if (!require('rgeos')) install.packages('rgeos') if (!require('rgeos')) install.packages('rgeos')

@ -28,7 +28,7 @@ Its main goals are to provide means for:
Before we look at actual observations, lets get a grasp of the openSenseMap Before we look at actual observations, lets get a grasp of the openSenseMap
datasets' structure. datasets' structure.
```{r results = F} ```{r results = FALSE}
library(magrittr) library(magrittr)
library(opensensmapr) library(opensensmapr)
@ -48,7 +48,7 @@ couple of minutes ago.
Another feature of interest is the spatial distribution of the boxes: `plot()` Another feature of interest is the spatial distribution of the boxes: `plot()`
can help us out here. This function requires a bunch of optional dependencies though. can help us out here. This function requires a bunch of optional dependencies though.
```{r, message=F, warning=F} ```{r, message=FALSE, warning=FALSE}
if (!require('maps')) install.packages('maps') if (!require('maps')) install.packages('maps')
if (!require('maptools')) install.packages('maptools') if (!require('maptools')) install.packages('maptools')
if (!require('rgeos')) install.packages('rgeos') if (!require('rgeos')) install.packages('rgeos')
@ -82,7 +82,7 @@ We should check how many sensor stations provide useful data: We want only those
boxes with a PM2.5 sensor, that are placed outdoors and are currently submitting boxes with a PM2.5 sensor, that are placed outdoors and are currently submitting
measurements: measurements:
```{r results = F, eval=FALSE} ```{r results = FALSE, eval=FALSE}
pm25_sensors = osem_boxes( pm25_sensors = osem_boxes(
exposure = 'outdoor', exposure = 'outdoor',
date = Sys.time(), # ±4 hours date = Sys.time(), # ±4 hours
@ -104,7 +104,7 @@ We could call `osem_measurements(pm25_sensors)` now, however we are focusing on
a restricted area of interest, the city of Berlin. a restricted area of interest, the city of Berlin.
Luckily we can get the measurements filtered by a bounding box: Luckily we can get the measurements filtered by a bounding box:
```{r, results=F, message=F} ```{r, results=FALSE, message=FALSE}
library(sf) library(sf)
library(units) library(units)
library(lubridate) library(lubridate)
@ -113,7 +113,7 @@ library(dplyr)
``` ```
Since the API takes quite long to response measurements, especially filtered on space and time, we do not run the following chunks for publication of the package on CRAN. Since the API takes quite long to response measurements, especially filtered on space and time, we do not run the following chunks for publication of the package on CRAN.
```{r bbox, results = F, eval=FALSE} ```{r bbox, results = FALSE, eval=FALSE}
# construct a bounding box: 12 kilometers around Berlin # construct a bounding box: 12 kilometers around Berlin
berlin = st_point(c(13.4034, 52.5120)) %>% berlin = st_point(c(13.4034, 52.5120)) %>%
st_sfc(crs = 4326) %>% st_sfc(crs = 4326) %>%
@ -138,9 +138,9 @@ plot(pm25)
Now we can get started with actual spatiotemporal data analysis. Now we can get started with actual spatiotemporal data analysis.
First, lets mask the seemingly uncalibrated sensors: First, lets mask the seemingly uncalibrated sensors:
```{r, warning=F} ```{r, warning=FALSE}
outliers = filter(pm25, value > 100)$sensorId outliers = filter(pm25, value > 100)$sensorId
bad_sensors = outliers[, drop = T] %>% levels() bad_sensors = outliers[, drop = TRUE] %>% levels()
pm25 = mutate(pm25, invalid = sensorId %in% bad_sensors) pm25 = mutate(pm25, invalid = sensorId %in% bad_sensors)
``` ```
@ -148,7 +148,7 @@ pm25 = mutate(pm25, invalid = sensorId %in% bad_sensors)
Then plot the measuring locations, flagging the outliers: Then plot the measuring locations, flagging the outliers:
```{r} ```{r}
st_as_sf(pm25) %>% st_geometry() %>% plot(col = factor(pm25$invalid), axes = T) st_as_sf(pm25) %>% st_geometry() %>% plot(col = factor(pm25$invalid), axes = TRUE)
``` ```
Removing these sensors yields a nicer time series plot: Removing these sensors yields a nicer time series plot:

Loading…
Cancel
Save