R: all possible combinations from a vector of elements with 2 possible conditions (+/-)

markers <- LETTERS[1:5]

test <- expand.grid(lapply(seq(markers), function(x) c("+","-")),stringsAsFactors=FALSE)

> test
   Var1 Var2 Var3 Var4 Var5
1     +    +    +    +    +
2     -    +    +    +    +
3     +    -    +    +    +
4     -    -    +    +    +
 ....


apply(test,1,function(x){paste0(markers,x,collapse = "/")}) 


 [1] "A+/B+/C+/D+/E+" "A-/B+/C+/D+/E+" "A+/B-/C+/D+/E+" "A-/B-/C+/D+/E+" "A+/B+/C-/D+/E+" "A-/B+/C-/D+/E+" "A+/B-/C-/D+/E+"
 [8] "A-/B-/C-/D+/E+" "A+/B+/C+/D-/E+" "A-/B+/C+/D-/E+" "A+/B-/C+/D-/E+" "A-/B-/C+/D-/E+" "A+/B+/C-/D-/E+" "A-/B+/C-/D-/E+"
[15] "A+/B-/C-/D-/E+" "A-/B-/C-/D-/E+" "A+/B+/C+/D+/E-" "A-/B+/C+/D+/E-" "A+/B-/C+/D+/E-" "A-/B-/C+/D+/E-" "A+/B+/C-/D+/E-"
[22] "A-/B+/C-/D+/E-" "A+/B-/C-/D+/E-" "A-/B-/C-/D+/E-" "A+/B+/C+/D-/E-" "A-/B+/C+/D-/E-" "A+/B-/C+/D-/E-" "A-/B-/C+/D-/E-"
[29] "A+/B+/C-/D-/E-" "A-/B+/C-/D-/E-" "A+/B-/C-/D-/E-" "A-/B-/C-/D-/E-"

To add to the excellent base R answer by @denis, here is a one-liner using RcppAlgos*. It should be a bit more efficient than the proposed solution:

n <- 5

RcppAlgos::permuteGeneral(c("+", "-"), n, repetition = TRUE, FUN = function(x) {
    paste0(LETTERS[1:n], x, collapse = "/")
})

[[1]]
[1] "A+/B+/C+/D+/E+"

[[2]]
[1] "A+/B+/C+/D+/E-"

[[3]]
[1] "A+/B+/C+/D-/E+"

.
.
.

[[30]]
[1] "A-/B-/C-/D+/E-"

[[31]]
[1] "A-/B-/C-/D-/E+"

[[32]]
[1] "A-/B-/C-/D-/E-"

It should be noted that the majority of computation is in dealing with manipulating character vectors. Thus, it will be difficult to achieve any sort of huge efficiency gain no matter what tool you use.

* I am the author