Skip to content

Commit

Permalink
RS-9583: Throw nicer error with non .sav files (#20)
Browse files Browse the repository at this point in the history
* Throw nicer error with non .sav files

* Trim whitespace from input file names
  • Loading branch information
JustinCCYap committed Nov 25, 2021
1 parent cbace5f commit b0d4755
Show file tree
Hide file tree
Showing 3 changed files with 15 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: flipData
Type: Package
Title: Functions for extracting and describing data
Version: 1.5.3
Version: 1.5.4
Author: Displayr <opensource@displayr.com>
Maintainer: Displayr <opensource@displayr.com>
Description: Functions for extracting data from formulas and
Expand Down
8 changes: 8 additions & 0 deletions R/mergingandstackingutilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@
#' @importFrom flipAPI IsDisplayrCloudDriveAvailable
readDataSets <- function(data.set.names, min.data.sets = 1)
{
data.set.names <- vapply(data.set.names, trimws, character(1),
USE.NAMES = FALSE)

if (length(data.set.names) < min.data.sets)
stop("At least ", min.data.sets, " data set(s) are required.")

if (!all(grepl('.+\\.sav$', data.set.names))) {
stop("An input data file was not an SPSS .sav data file. ",
"Only SPSS .sav data files are accepted.")
}

if (IsDisplayrCloudDriveAvailable())
readDataSetsFromDisplayrCloudDrive(data.set.names)
else
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-mergingandstackingutilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,11 @@ test_that("parseVariableWildcardForMerging", {
"wildcard input 'Pepsi*'."), fixed = TRUE)
})

test_that("readDataSets: Non .sav files throw nice error", {
expect_error(readDataSets(c('file1.csv', 'file2.csv')),
paste0("An input data file was not an SPSS .sav data file. ",
"Only SPSS .sav data files are accepted."))
})

if (file.exists("Combined data set.sav"))
file.remove("Combined data set.sav")

0 comments on commit b0d4755

Please sign in to comment.