From 0eb1b4e8f2ebb5f12c37c081749f8b4c874e26ad Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Mon, 24 Feb 2020 08:16:44 -0800 Subject: [PATCH 1/2] use inherits instead of class(x) == --- R/sequences.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/sequences.R b/R/sequences.R index 2f6fce8..dd19e74 100644 --- a/R/sequences.R +++ b/R/sequences.R @@ -57,7 +57,7 @@ DNAbin2genind <- function(x, pop=NULL, exp.char=c("a","t","g","c"), polyThres=1/ ## sort out col/row names ## ## check if col.names is in matrix format and change to vector format - if(class(col.names)=="matrix") col.names <- as.vector(col.names) + if(inherits(col.names, "matrix")) col.names <- as.vector(col.names) colnames(temp) <- col.names # restore correct names rownames(temp) <- rownames(x) From cd932e8a80adda938ba697b5d52431dfab60cb0d Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Fri, 27 Mar 2020 16:38:33 -0700 Subject: [PATCH 2/2] add test --- tests/testthat/test_conversion.R | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/testthat/test_conversion.R diff --git a/tests/testthat/test_conversion.R b/tests/testthat/test_conversion.R new file mode 100644 index 0000000..34a39d7 --- /dev/null +++ b/tests/testthat/test_conversion.R @@ -0,0 +1,10 @@ +context("data conversions") + +test_that("DNAbin2genind works properly", { + + data("woodmouse", package = "ape") + wm <- DNAbin2genind(woodmouse) + expect_is(wm, "genind") + expect_equal(nInd(wm), nrow(woodmouse)) + +})