diff --git a/pkg/R/feasibility.R b/pkg/R/feasibility.R index 6061485..51ef8b2 100644 --- a/pkg/R/feasibility.R +++ b/pkg/R/feasibility.R @@ -2,7 +2,7 @@ # find straigtforward contradictions of the form 0 <= b or 0 == b has_contradiction <- function(A,b,tol){ if (nrow(A)==0) return(FALSE) - if (ncol(A)==0 & abs(b) > tol) return(TRUE) + if (ncol(A)==0 & all(abs(b) > tol)) return(TRUE) any(rowSums(abs(A)>tol) == 0 & (abs(b)>tol)) } diff --git a/pkg/R/substval.R b/pkg/R/substval.R index cf3aac4..2e84bd7 100644 --- a/pkg/R/substval.R +++ b/pkg/R/substval.R @@ -9,6 +9,7 @@ #' @param b \code{[numeric]} vector #' @param variables \code{[numeric|logical|character]} vector of column indices in \code{A} #' @param values \code{[numeric]} vecor of values to substitute. +#' @param remove_columns Remove spurious columns when substituting? #' #' @return A \code{list} with the following components: #' @@ -19,13 +20,17 @@ #' #' #' @export -subst_value <- function(A, b, variables, values){ +subst_value <- function(A, b, variables, values, remove_columns=FALSE){ check_sys(A=A, b=b) if ( is.character(variables) ){ variables <- match(variables,colnames(A)) } b <- as.vector(b - A[,variables,drop=FALSE] %*% values) - A <- A[,-variables,drop=FALSE] + if (remove_columns){ + A <- A[,-variables,drop=FALSE] + } else { + A[,variables] <- 0 + } list(A=A, b=b) -} \ No newline at end of file +} diff --git a/pkg/tests/testthat/test_substitute.R b/pkg/tests/testthat/test_substitute.R index a9837b4..8cc347b 100644 --- a/pkg/tests/testthat/test_substitute.R +++ b/pkg/tests/testthat/test_substitute.R @@ -10,17 +10,17 @@ subst_value(A,b,1,1) test_that("value substitution",{ expect_equivalent( - subst_value(A,b,1,0) + subst_value(A,b,1,0,remove_columns=TRUE) , list(A=A[,2:3],b=b) ) expect_equivalent( - subst_value(A,b,c(1,3),c(0,1)) + subst_value(A,b,c(1,3),c(0,1),remove_columns=TRUE) ,list(A=A[,2,drop=FALSE],b=b-9:12) ) colnames(A) <- paste0("x",seq_len(ncol(A))) expect_equivalent( - subst_value(A,b,"x1",0) + subst_value(A,b,"x1",0,remove_columns=TRUE) , list(A=A[,2:3],b=b) ) -}) \ No newline at end of file +})