From 6ebfc7f50ac91a8a2517c3570ec51411483847b6 Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 6 Mar 2023 10:19:37 +0100 Subject: [PATCH] changed T and F to TRUE and FALSE --- .lintr | 2 +- R/api.R | 2 +- R/archive.R | 2 +- R/box.R | 4 ++-- R/box_utils.R | 12 ++++++------ man/osem_measurements_archive.Rd | 4 ++-- tests/testthat/test_archive.R | 9 +++++++++ vignettes/osem-history_revised.Rmd | 2 +- vignettes/osem-intro.Rmd | 16 ++++++++-------- 9 files changed, 31 insertions(+), 22 deletions(-) diff --git a/.lintr b/.lintr index e6d7545..77cb54c 100644 --- a/.lintr +++ b/.lintr @@ -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( # we use snake case camel_case_linter = NULL, diff --git a/R/api.R b/R/api.R index dff5046..9ff52b9 100644 --- a/R/api.R +++ b/R/api.R @@ -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. #' @return Result of a Request to openSenseMap API #' @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(...) if (!is.na(cache)) { filename = osem_cache_filename(path, query, host) %>% paste(cache, ., sep = '/') diff --git a/R/archive.R b/R/archive.R index a1bd2dc..7fad533 100644 --- a/R/archive.R +++ b/R/archive.R @@ -64,7 +64,7 @@ osem_measurements_archive.default = function (x, ...) { #' 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) stop('this function only works for exactly one senseBox!') diff --git a/R/box.R b/R/box.R index 9ab249e..5907356 100644 --- a/R/box.R +++ b/R/box.R @@ -159,7 +159,7 @@ parse_senseboxdata = function (boxdata) { boxdata[c( 'loc', 'locations', 'currentLocation', 'sensors', 'image', 'boxType', 'lastMeasurementAt', 'grouptag' )] = NULL - thebox = as.data.frame(boxdata, stringsAsFactors = F) + thebox = as.data.frame(boxdata, stringsAsFactors = FALSE) # parse timestamps (updatedAt might be not defined) thebox$createdAt = isostring_as_date(thebox$createdAt) @@ -176,7 +176,7 @@ parse_senseboxdata = function (boxdata) { # create a dataframe of sensors thebox$sensors = sensors %>% 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::select(phenomenon = title, id = X_id, unit, sensor = sensorType) %>% list diff --git a/R/box_utils.R b/R/box_utils.R index a21ef2d..9d59c2c 100644 --- a/R/box_utils.R +++ b/R/box_utils.R @@ -22,8 +22,8 @@ plot.sensebox = function (x, ..., mar = c(2, 2, 1, 1)) { oldpar = par() par(mar = mar) - plot(world, col = 'gray', xlim = bbox[c(1, 3)], ylim = bbox[c(2, 4)], axes = T, ...) - plot(geom, add = T, col = x$exposure, ...) + plot(world, col = 'gray', xlim = bbox[c(1, 3)], ylim = bbox[c(2, 4)], axes = TRUE, ...) + plot(geom, add = TRUE, col = x$exposure, ...) legend('left', legend = levels(x$exposure), col = 1:length(x$exposure), pch = 1) par(mar = oldpar$mar) @@ -39,7 +39,7 @@ print.sensebox = function(x, columns = c('name', 'exposure', 'lastMeasurement', #' @export summary.sensebox = function(object, ...) { - cat('boxes total:', nrow(object), fill = T) + cat('boxes total:', nrow(object), fill = TRUE) cat('\nboxes by exposure:') table(object$exposure) %>% print() cat('\nboxes by model:') @@ -59,10 +59,10 @@ summary.sensebox = function(object, ...) { oldest = object[object$createdAt == min(object$createdAt), ] newest = object[object$createdAt == max(object$createdAt), ] - cat('oldest box:', format(oldest$createdAt, '%F %T'), paste0('(', oldest$name, ')'), fill = T) - cat('newest box:', format(newest$createdAt, '%F %T'), paste0('(', newest$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 = TRUE) - cat('\nsensors per box:', fill = T) + cat('\nsensors per box:', fill = TRUE) lapply(object$phenomena, length) %>% as.numeric() %>% summary() %>% diff --git a/man/osem_measurements_archive.Rd b/man/osem_measurements_archive.Rd index 44827d9..b65754a 100644 --- a/man/osem_measurements_archive.Rd +++ b/man/osem_measurements_archive.Rd @@ -11,9 +11,9 @@ osem_measurements_archive(x, ...) x, fromDate, toDate = fromDate, - sensorFilter = ~T, + sensorFilter = ~TRUE, ..., - progress = T + progress = TRUE ) } \arguments{ diff --git a/tests/testthat/test_archive.R b/tests/testthat/test_archive.R index df5f204..07cb584 100644 --- a/tests/testthat/test_archive.R +++ b/tests/testthat/test_archive.R @@ -46,6 +46,15 @@ test_that('osem_measurements_archive works for one box', { 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', { check_api() if (is.null(boxes)) skip('no box data available') diff --git a/vignettes/osem-history_revised.Rmd b/vignettes/osem-history_revised.Rmd index 284d593..e612a60 100644 --- a/vignettes/osem-history_revised.Rmd +++ b/vignettes/osem-history_revised.Rmd @@ -66,7 +66,7 @@ summary(boxes) -> summary.data.frame 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. -```{r, message=F, warning=F} +```{r, message=FALSE, warning=FALSE} if (!require('maps')) install.packages('maps') if (!require('maptools')) install.packages('maptools') if (!require('rgeos')) install.packages('rgeos') diff --git a/vignettes/osem-intro.Rmd b/vignettes/osem-intro.Rmd index 773810d..615d0ac 100644 --- a/vignettes/osem-intro.Rmd +++ b/vignettes/osem-intro.Rmd @@ -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 datasets' structure. -```{r results = F} +```{r results = FALSE} library(magrittr) library(opensensmapr) @@ -48,7 +48,7 @@ couple of minutes ago. 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. -```{r, message=F, warning=F} +```{r, message=FALSE, warning=FALSE} if (!require('maps')) install.packages('maps') if (!require('maptools')) install.packages('maptools') 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 measurements: -```{r results = F, eval=FALSE} +```{r results = FALSE, eval=FALSE} pm25_sensors = osem_boxes( exposure = 'outdoor', 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. Luckily we can get the measurements filtered by a bounding box: -```{r, results=F, message=F} +```{r, results=FALSE, message=FALSE} library(sf) library(units) 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. -```{r bbox, results = F, eval=FALSE} +```{r bbox, results = FALSE, eval=FALSE} # construct a bounding box: 12 kilometers around Berlin berlin = st_point(c(13.4034, 52.5120)) %>% st_sfc(crs = 4326) %>% @@ -138,9 +138,9 @@ plot(pm25) Now we can get started with actual spatiotemporal data analysis. First, lets mask the seemingly uncalibrated sensors: -```{r, warning=F} +```{r, warning=FALSE} 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) ``` @@ -148,7 +148,7 @@ pm25 = mutate(pm25, invalid = sensorId %in% bad_sensors) Then plot the measuring locations, flagging the outliers: ```{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: