From 53911ff2e39589ed05904aab3f1270977b10daa5 Mon Sep 17 00:00:00 2001 From: Michal Stolarczyk Date: Thu, 13 Sep 2018 11:07:06 -0400 Subject: [PATCH] Fix #7 double slashes, start working on unit tests --- R/loadConfig.R | 8 +++++++- tests/testthat/test_utils.R | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/test_utils.R diff --git a/R/loadConfig.R b/R/loadConfig.R index 23036791..9767ac5c 100644 --- a/R/loadConfig.R +++ b/R/loadConfig.R @@ -142,7 +142,13 @@ expandPath = function(path) { if (length(parts) < 2) { return(parts) } if (identical(".", parts[1])) { parts = parts[2:length(parts)] } - # Expand any environment variables and return the complete path. + # Expand any environment variables and return the complete path + if(.Platform$OS.type=="unix") { + # Prevent double slashes + if(any(parts=="/")){ + parts[which(parts=="/")]="" + } + } fullPath = do.call(file.path, lapply(parts, expand)) return(fullPath) } diff --git a/tests/testthat/test_utils.R b/tests/testthat/test_utils.R new file mode 100644 index 00000000..df99dbc0 --- /dev/null +++ b/tests/testthat/test_utils.R @@ -0,0 +1,13 @@ +context("Utils") + +DF=mtcars +newDF=listifyDF(DF) + +test_that("listifyDF is a yields correct object type", { + expect_is(listifyDF(DF = DF),'data.frame') + expect_is(listifyDF(DF = DF)[[1]],'list') +}) + +test_that("listifyDF does not change the dimensions",{ + expect_equal(dim(listifyDF(DF)), dim(DF)) +}) \ No newline at end of file