Skip to content

Commit

Permalink
Issue rqtl#142: let calc_sdp() take a vector
Browse files Browse the repository at this point in the history
  • Loading branch information
kbroman committed Dec 15, 2020
1 parent 44d1ec7 commit e48ddd7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
- Make the [vdiffr](https://vdiffr.r-lib.org) package optional: only
test the plots locally, and only if vdiffr is installed.

- `calc_sdp()` can now take a plain vector (Issue #142).

### Bug fixes

- Fixed [Issue #181](https://github.com/rqtl/qtl2/issues/181), where
Expand Down
11 changes: 8 additions & 3 deletions R/calc_sdp.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ calc_sdp <-
function(geno)
{
# tolerate data frames, but convert to matrix
if(!is.matrix(geno) && is.data.frame(geno))
geno <- as.matrix(geno)
if(!is.matrix(geno)) stop("geno should be a matrix")
if(!is.matrix(geno)) {
if(is.data.frame(geno)) {
geno <- as.matrix(geno)
} else {
geno <- rbind(geno)
dimnames(geno) <- NULL
}
}

n_str <- ncol(geno)

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-calc_sdp.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ test_that("calc_sdp works", {
g <- g[n_AA > 0 & n_AA < 8,]
expect_equal(calc_sdp(g),
apply(g, 1, function(a) sum(((a-1)/2)*2^(seq(along=a)-1))))

expect_equal( calc_sdp( c(1,1,1,3,1,1,1,1) ), 8)
expect_equal( calc_sdp( data.frame(1,1,1,3,1,1,1,1)), 8)

})


Expand Down

0 comments on commit e48ddd7

Please sign in to comment.