Skip to content

Commit

Permalink
fixed edge case when column type has more than 1 classes (#906)
Browse files Browse the repository at this point in the history
Co-authored-by: Junlue Zhao <[email protected]>
  • Loading branch information
2 people authored and GitHub Enterprise committed Oct 19, 2020
1 parent f1902e3 commit 0d2397f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
14 changes: 9 additions & 5 deletions R/RawDataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,17 @@ RawDataset <- R6::R6Class( # nolint
if (class_type == "factor") {
include_factors <- TRUE
}
return_cols <- private$.colnames[which(vapply(lapply(private$.raw_data, class),
`%in%`,
logical(1), table = class_type)
)]
return_cols <- private$.colnames[which(vapply(
lapply(private$.raw_data, class),
function(x, target_class_name) any(x %in% target_class_name),
logical(1),
target_class_name = class_type))]

if (!include_factors) {
factor_columns <- private$.colnames[which(lapply(private$.raw_data, class) == "factor")]
factor_columns <- private$.colnames[which(vapply(
lapply(private$.raw_data, class),
function(x) any(x %in% "factor"),
logical(1)))]
return_cols <- setdiff(return_cols, factor_columns)
}
return(return_cols)
Expand Down
4 changes: 2 additions & 2 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ mockup
modularization
modularize
modularized
multisessions
multithreaded
namespaced
npaszty
numericInput
Expand All @@ -101,5 +103,3 @@ tm
triggerings
ui
waddella
multisessions
multithreaded
15 changes: 15 additions & 0 deletions tests/testthat/test-Dataset_classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ test_that("RawDataset basics", {
x
)

})

test_that("RawDataset edge case: column types with more than 1 classes", {

# class(x$y) is [1] "POSIXct" "POSIXt", i.e. a vector of length 2
x <- data.frame(
x = c(1, 2),
y = c(as.POSIXct("2020-10-16"), as.POSIXct("2020-10-17")),
z = factor(c("a", "b")),
a = c("a", "b"),
b = factor(c(1, 2)), stringsAsFactors = FALSE)
obj <- RawDataset$new(x)
expect_equal(obj$get_character_colnames(), "a")
expect_equal(obj$get_factor_colnames(), c("z", "b"))
expect_equal(obj$get_numeric_colnames(), "x")

})

Expand Down

0 comments on commit 0d2397f

Please sign in to comment.