Skip to content

Commit 885f61f

Browse files
committed
revert: allow data frames to pass class check and update tests
1 parent 48b6a4e commit 885f61f

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

R/lengthDS.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#'
1313
lengthDS <- function(x){
1414
x.val <- .loadServersideObject(x)
15-
.checkClass(obj = x.val, obj_name = x, permitted_classes = c("character", "factor", "integer", "logical", "numeric", "list"))
15+
.checkClass(obj = x.val, obj_name = x, permitted_classes = c("character", "factor", "integer", "logical", "numeric", "list", "data.frame"))
1616
list(length = length(x.val), class = class(x.val))
1717
}
1818
#AGGREGATE FUNCTION

tests/testthat/test-smk-lengthDS.R

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,24 @@ test_that("lengthDS throws error when object does not exist", {
5656
)
5757
})
5858

59-
test_that("lengthDS throws error when object is not a permitted type", {
60-
bad_input <- data.frame(a = 1:3)
61-
expect_error(
62-
lengthDS("bad_input"),
63-
regexp = "must be of type"
64-
)
59+
test_that("simple lengthDS, numeric data.frame", {
60+
input <- data.frame(v1 = c(0.0, 1.0, 2.0, 3.0, 4.0), v2 = c(4.0, 3.0, 2.0, 1.0, 0.0))
61+
62+
res <- lengthDS("input")
63+
64+
expect_equal(class(res), "list")
65+
expect_equal(res$length, 2)
66+
expect_equal(res$class, "data.frame")
67+
})
68+
69+
test_that("simple lengthDS, character data.frame", {
70+
input <- data.frame(v1 = c("0.0", "1.0", "2.0", "3.0", "4.0"), v2 = c("4.0", "3.0", "2.0", "1.0", "0.0"), stringsAsFactors = FALSE)
71+
72+
res <- lengthDS("input")
73+
74+
expect_equal(class(res), "list")
75+
expect_equal(res$length, 2)
76+
expect_equal(res$class, "data.frame")
6577
})
6678

6779
#

0 commit comments

Comments
 (0)