title: combinations of numbers to reach a given sum - recursive implementation in R
body: <p>All I want to do is to implement the solution given <a href="https://stackoverflow.com/questions/4632322/finding-all-possible-combinations-of-numbers-to-reach-a-given-sum">here</a> (the one in python)
  in R.
  I'm not very used to do debugging in R-Studio but even after I have tried that I still can't figure out why my code does not work. Basically (with the example input provided) I get the function to run over all the numbers and then it is stuck in a sort of infinite loop (or function). Can someone please point me in the right direction regarding this?</p>
  
  <pre><code>subset_sum &lt;- function(numbers, target, partial = numeric(0)){
    s &lt;-  sum(partial,na.rm = TRUE)
  
    # check if the partial sum equals to target
    if (s == target){
      cat("sum(",partial,")","=",target)
    }
    else if (s &gt;= target) {
      return() # if we reach the number why bother to continue
  
    }
    else {
  
      for(i in 1:length(numbers)){
        n &lt;-  numbers[i]
        remaining &lt;- numbers[i+1:length(numbers)]
        subset_sum(remaining, target, partial = append(partial,n))
      }
        }
  }
  
  subset_sum(c(3,9,8,4,5,7,10),15)
  </code></pre>
  
  <p>When not run in debug mode it gives me these errors:</p>
  
  <pre><code>Error: node stack overflow
  Error during wrapup: node stack overflow
  </code></pre>