From 994f08ab945dd1af845aeecde6aab135678e7cb3 Mon Sep 17 00:00:00 2001 From: noerw Date: Thu, 7 Jun 2018 00:04:50 +0200 Subject: [PATCH] fix osem_as_measurements --- DESCRIPTION | 1 + R/measurement_utils.R | 4 ++-- tests/testthat/test_measurements.R | 14 ++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 61b2f56..b33a19e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,6 +13,7 @@ Suggests: maps, maptools, readr, + tibble, rgeos, sf, knitr, diff --git a/R/measurement_utils.R b/R/measurement_utils.R index de174f9..447ddf3 100644 --- a/R/measurement_utils.R +++ b/R/measurement_utils.R @@ -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 } diff --git a/tests/testthat/test_measurements.R b/tests/testthat/test_measurements.R index fab5425..5a22af6 100644 --- a/tests/testthat/test_measurements.R +++ b/tests/testthat/test_measurements.R @@ -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()