Browse Source

fix osem_as_measurements

development
noerw 11 months ago
parent
commit
994f08ab94
3 changed files with 11 additions and 8 deletions
  1. 1
    0
      DESCRIPTION
  2. 2
    2
      R/measurement_utils.R
  3. 8
    6
      tests/testthat/test_measurements.R

+ 1
- 0
DESCRIPTION View File

@@ -13,6 +13,7 @@ Suggests:
13 13
     maps,
14 14
     maptools,
15 15
     readr,
16
+    tibble,
16 17
     rgeos,
17 18
     sf,
18 19
     knitr,

+ 2
- 2
R/measurement_utils.R View File

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

+ 8
- 6
tests/testthat/test_measurements.R View File

@@ -8,8 +8,9 @@ try({
8 8
 test_that('measurements can be retrieved for a phenomenon', {
9 9
   check_api()
10 10
 
11
+  measurements = osem_measurements('Windgeschwindigkeit')
11 12
   measurements = osem_measurements(x = 'Windgeschwindigkeit')
12
-  expect_true(is.data.frame(measurements))
13
+  expect_true(tibble::is.tibble(measurements))
13 14
   expect_true('osem_measurements' %in% class(measurements))
14 15
 })
15 16
 
@@ -30,11 +31,6 @@ test_that('a response with no matching senseBoxes gives an error', {
30 31
   expect_error(osem_measurements(x = 'Windgeschwindigkeit', exposure = 'indoor'), 'No senseBoxes found')
31 32
 })
32 33
 
33
-test_that('data.frame can be converted to measurements data.frame', {
34
-  df = osem_as_measurements(data.frame(c(1, 2), c('a', 'b')))
35
-  expect_equal(class(df), c('osem_measurements', 'data.frame'))
36
-})
37
-
38 34
 test_that('columns can be specified for phenomena', {
39 35
   check_api()
40 36
 
@@ -126,6 +122,12 @@ test_that('[.osem_measurements maintains attributes', {
126 122
   expect_true(all(attributes(m[1:nrow(m), ]) %in% attributes(m)))
127 123
 })
128 124
 
125
+test_that('data.frame can be converted to measurements data.frame', {
126
+  m = osem_measurements('Windrichtung')
127
+  df = osem_as_measurements(data.frame(c(1, 2), c('a', 'b')))
128
+  expect_equal(class(df), class(m))
129
+})
130
+
129 131
 test_that('requests can be cached', {
130 132
   check_api()
131 133
 

Loading…
Cancel
Save