Quellcode durchsuchen

fix osem_as_measurements

development
noerw vor 1 Jahr
Ursprung
Commit
994f08ab94
3 geänderte Dateien mit 11 neuen und 8 gelöschten Zeilen
  1. 1
    0
      DESCRIPTION
  2. 2
    2
      R/measurement_utils.R
  3. 8
    6
      tests/testthat/test_measurements.R

+ 1
- 0
DESCRIPTION Datei anzeigen

@@ -13,6 +13,7 @@ Suggests:
maps,
maptools,
readr,
tibble,
rgeos,
sf,
knitr,

+ 2
- 2
R/measurement_utils.R Datei anzeigen

@@ -17,8 +17,8 @@ print.osem_measurements = function (x, ...) {
#' @param x A data.frame to attach the class to
#' @export
osem_as_measurements = function(x) {
ret = as.data.frame(x)
class(ret) = c('osem_measurements', class(x))
ret = tibble::as.tibble(x)
class(ret) = c('osem_measurements', class(ret))
ret
}


+ 8
- 6
tests/testthat/test_measurements.R Datei anzeigen

@@ -8,8 +8,9 @@ try({
test_that('measurements can be retrieved for a phenomenon', {
check_api()

measurements = osem_measurements('Windgeschwindigkeit')
measurements = osem_measurements(x = 'Windgeschwindigkeit')
expect_true(is.data.frame(measurements))
expect_true(tibble::is.tibble(measurements))
expect_true('osem_measurements' %in% class(measurements))
})

@@ -30,11 +31,6 @@ test_that('a response with no matching senseBoxes gives an error', {
expect_error(osem_measurements(x = 'Windgeschwindigkeit', exposure = 'indoor'), 'No senseBoxes found')
})

test_that('data.frame can be converted to measurements data.frame', {
df = osem_as_measurements(data.frame(c(1, 2), c('a', 'b')))
expect_equal(class(df), c('osem_measurements', 'data.frame'))
})

test_that('columns can be specified for phenomena', {
check_api()

@@ -126,6 +122,12 @@ test_that('[.osem_measurements maintains attributes', {
expect_true(all(attributes(m[1:nrow(m), ]) %in% attributes(m)))
})

test_that('data.frame can be converted to measurements data.frame', {
m = osem_measurements('Windrichtung')
df = osem_as_measurements(data.frame(c(1, 2), c('a', 'b')))
expect_equal(class(df), class(m))
})

test_that('requests can be cached', {
check_api()


Laden…
Abbrechen
Speichern