Skip to content

Commit

Permalink
add new check that excludes the first column when checking if all are…
Browse files Browse the repository at this point in the history
… numeric (#65)
  • Loading branch information
arunge authored Jan 9, 2024
1 parent c6e054a commit b82006b
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: DataTools
Type: Package
Title: Data Tools for Shiny Apps
Version: 23.12.2.1
Version: 23.12.2.2
Authors@R: c(
person("Antonia", "Runge", email = "antonia.runge@inwt-statistics.de", role = c("cre", "aut"))
)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export("%>%")
export(checkAnyNonNumericColumns)
export(checkErrorNoNumericColumns)
export(checkNonNumericColumnsExceptFirst)
export(checkWarningEmptyValues)
export(cutAllLongStrings)
export(downUploadButtonServer)
Expand Down
4 changes: 4 additions & 0 deletions R/02-importData-selectData.R
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ selectSourceServer <- function(id,

# reset ckanGroup, ckanRecord, ckanResourceTypes
updateTextInput(session, "repoFilter-ckanMeta", value = "")

req(internetCon())
updatePickerInput(session,
"repoFilter-ckanGroup",
choices = getCKANGroupChoices(groupList = ckanNetworks()),
Expand Down Expand Up @@ -529,6 +531,7 @@ selectSourceServer <- function(id,
bindEvent(input[["resourceLoad-resetCKAN"]])

observe({
req(internetCon())
logDebug("Apply Meta filter")
updateSelectizeInput(session,
"resourceFilter-ckanRecord",
Expand All @@ -545,6 +548,7 @@ selectSourceServer <- function(id,
bindEvent(input[["repoFilter-applyMeta"]])

observe({
req(internetCon())
logDebug("Apply Network filter")
updateSelectizeInput(session,
"resourceFilter-ckanRecord",
Expand Down
24 changes: 24 additions & 0 deletions R/03-checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ checkAnyNonNumericColumns <- function(data) {
TRUE
}

#' Check Non-Numeric Columns Except First
#'
#' Check for any non-numeric columns, exclude the first column. Check can be applied as custom
#' checks in importDataServer.
#'
#' @param data data to be checked
#' @export
checkNonNumericColumnsExceptFirst <- function(data) {
if (ncol(data) < 2) {
return("Less than 2 columns.")
}

data <- data[, -1, drop = FALSE]

nNumericCol <- sum(findNumericCol(as.data.frame(data,
stringsAsFactors = FALSE)))

if (nNumericCol < ncol(data)) {
return("Please provide a dataset with all numeric variables except the first column.")
}

TRUE
}

#' Check Error No Numeric Columns
#'
#' Check for minimal numeric columns. Check can be applied as customErrorChecks in importDataServer.
Expand Down
15 changes: 15 additions & 0 deletions man/checkNonNumericColumnsExceptFirst.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions tests/testthat/test-checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ test_that("Test checkAnyNonNumericColumns()", {
expect_true(checkAnyNonNumericColumns(testData))
})

test_that("Test checkAnyNonNumericColumns()", {
testData <- data.frame(x = 1:3,
y = c("a", "b", "c"),
stringsAsFactors = FALSE)
expect_equal(checkNonNumericColumnsExceptFirst(testData),
"Please provide a dataset with all numeric variables except the first column.")

testData <- data.frame(x = 1:3,
y = 5:7)
expect_true(checkNonNumericColumnsExceptFirst(testData))

testData <- data.frame(a = c("a", "b", "c"),
x = 1:3,
y = 5:7,
stringsAsFactors = FALSE)
expect_true(checkNonNumericColumnsExceptFirst(testData))
})

test_that("Test checkErrorNoNumericColumns()", {
testData <- data.frame(x = 1:3,
y = c("a", "b", "c"),
Expand Down

0 comments on commit b82006b

Please sign in to comment.