Skip to content

Commit

Permalink
Fix bug in micomp when using one named output
Browse files Browse the repository at this point in the history
  • Loading branch information
nunofachada committed Aug 3, 2016
1 parent 8560825 commit 3627f1e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: micompr
Title: Multivariate Independent Comparison of Observations
Version: 1.0.1
Date: 2016-07-31
Date: 2016-08-03
Authors@R: person("Nuno", "Fachada", email = "faken@fakenmc.com",
role = c("aut", "cre"))
Maintainer: Nuno Fachada <faken@fakenmc.com>
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# micompr 1.0.1

* Fix bug in grpoutputs when loading files with just one output
* Fix bug in micomp when using one named output

# micompr 1.0.0

Expand Down
14 changes: 10 additions & 4 deletions R/micomp.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,18 @@ micomp <- function(
ncomp <- length(comps)
cmp_names <- vector(mode = "character", length = ncomp)

# Did the user specify output names? Or should we provide some default names?
if (length(outputs) == 1) {
nout <- outputs
outputs <- paste("out", 1:nout, sep = "")
# Did user specify output names or a number of outputs?
if ((length(outputs) == 1) && (is.numeric(outputs))) {

# User specified number of outputs, set default names
nout <- trunc(outputs)
outputs <- paste("out", 1:trunc(outputs), sep = "")

} else {

# User specified output names, determine number of outputs
nout <- length(outputs)

}

# List of grouped outputs for each comparison
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test_micomp.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ test_that("micomp constructs the expected objects", {
files = c(files, files),
lvls = c("NLOK", "JEXOK"))))

# 5 - One named output, one variance to explain, two comparisons, explicit
# Pillay test
mic5 <- micomp("TheOutput", 0.9,
list(
list(name = "NLOKvsJEXNOSHUFF",
folders = c(dir_nl_ok, dir_jex_noshuff),
files = c(files, files),
lvls = c("NLOK", "JEXNOSHUFF")),
list(name = "NLOKvsJEXDIFF",
folders = c(dir_nl_ok, dir_jex_diff),
files = c(files, files),
lvls = c("NLOK", "JEXDIFF"))),
mnv_test = "Pillai")

##### Start testing #####

# Check object dimensions
Expand All @@ -99,6 +113,7 @@ test_that("micomp constructs the expected objects", {
expect_equal(dim(mic2), c(7, 3))
expect_equal(dim(mic3), c(6, 3))
expect_equal(dim(mic4), c(1, 1))
expect_equal(dim(mic5), c(1, 2))

# Check object row names
expect_equal(rownames(mic1a), outputs)
Expand All @@ -107,6 +122,7 @@ test_that("micomp constructs the expected objects", {
expect_equal(rownames(mic3),
c("out1", "out2", "out3", "out4", "out5", "out6"))
expect_equal(rownames(mic4), c("out1"))
expect_equal(rownames(mic5), c("TheOutput"))

# Check object column names
expect_equal(colnames(mic1a),
Expand All @@ -118,6 +134,7 @@ test_that("micomp constructs the expected objects", {
expect_equal(colnames(mic3),
c("NLOKvsJEXOK", "NLOKvsJEXNOSHUFF", "NLOKvsJEXDIFF"))
expect_equal(colnames(mic4), "NLOKvsJEXOK")
expect_equal(colnames(mic5), c("NLOKvsJEXNOSHUFF", "NLOKvsJEXDIFF"))

# Check properties of sub-objects
for (i in 1:dim(mic1a)[1]) {
Expand Down

0 comments on commit 3627f1e

Please sign in to comment.