fix osem_as_measurements

measurements_archive
noerw il y a 6 ans
Parent 97768e7cdb
révision 994f08ab94

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

@ -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,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()

Chargement…
Annuler
Enregistrer