0

My end goal is to have R evaluate my set of expressions. They look something like:

    b
1   5+5+5+55555
2   1+5+5+55555
3   5-5+5+55555
4   1-5+5+55555
5   5*5+5+55555
6   1*5+5+55555
7   5/5+5+55555
8   1/5+5+55555
9   5+1+5+55555
10  1+1+5+55555
11  5-1+5+55555

but there are 2 million of them. After much finagling, I got the following to work as a proof of concept.

q <- apply(b,1,function(x){eval(parse(text=x))})

and that works for a smaller subset where all the expressions make sense. But because I'm just being lazy and doing brute force, not all of the expressions evaluate properly.

Like

5+5+5+5(555

Error in parse(text = x) : <text>:2:0: unexpected end of input

Can I tell R to be ok with that, and just return NA or FALSE or something else, but not break the code. I suppose I can go back and grep out the ones that won't evaluate, but I'm curious if I can make R just go with it.

Thanks!

DSG
  • 487
  • 1
  • 5
  • 11
  • 2
    Use `tryCatch`. Also, [fortune 106](http://cran.r-project.org/web/packages/fortunes/vignettes/fortunes.pdf). – Roland Mar 13 '15 at 18:51
  • i cant figure out tryCatch :( there arent lots of examples out there. lots of explanations, but not examples to help out. – DSG Mar 13 '15 at 21:01
  • http://stackoverflow.com/a/12195574/1412059 – Roland Mar 14 '15 at 12:29

0 Answers0