diff --git a/R/L_plus_R.R b/R/L_plus_R.R index 848b6b215d51e86aa7230dc686c0bd5c388f32a2..70316df35d4011886142f88903c324cbad0a50ae 100644 --- a/R/L_plus_R.R +++ b/R/L_plus_R.R @@ -66,11 +66,8 @@ L_plus_R <- function(pos, ws, X = NULL) { ## get L, R and L_plus_R noL <- length(pos[pos>=currentPos-ws/2 & pos < currentPos]) ## Number of SNPs to the left of the current SNP noR <- length(pos[pos<=currentPos+ws/2 & pos > currentPos]) ## Number of SNPs to the right of the current SNP - if(noL < 2 || noR < 2){ #Must be at least 2 to calculate n choose 2 - outputList$L_plus_R[i]<-NA - } else { - outputList$L_plus_R[i]<-choose(noL,2)+choose(noR,2) - } + ## if n < 2 then choose function will return 0 + outputList$L_plus_R[i]<-choose(noL,2)+choose(noR,2) } return(outputList) } diff --git a/tests/testthat/test-L_plus_R.R b/tests/testthat/test-L_plus_R.R index 3680384b0a4f21c56330639b1b12eec352317bb9..2e02d9eea91ed9e6df32328e1d38bde17a51a755 100644 --- a/tests/testthat/test-L_plus_R.R +++ b/tests/testthat/test-L_plus_R.R @@ -12,7 +12,7 @@ test_that("L_plus_R calculates L_plus_R statistic correctly", { expect_equal(L_plus_R(pos = df$POS, ws = 3000, X = NULL), list( position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500), - L_plus_R=c(NA,NA,67,58,51,46,43,42,43,46,51,58,67,NA,NA) + L_plus_R=c(91,78,67,58,51,46,43,42,43,46,51,58,67,78,91) )) }) @@ -23,7 +23,7 @@ test_that("L_plus_R calculates L_plus_R statistic correctly with a different win expect_equal(L_plus_R(pos = df$POS, ws = 1100, X = NULL), list( position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500), - L_plus_R=c(NA,NA,11,13,16,20,20,20,20,20,16,13,11,NA,NA) + L_plus_R=c(10,10,11,13,16,20,20,20,20,20,16,13,11,10,10) )) })