Work around R parse bug

R's parse function produces (rarely) bad results on first execution, see
https://bugs.r-project.org/bugzilla/show_bug.cgi?id=16041 for a
reproducible example.

Also the previous code would fail if the function name was part of an
expression i.e. `pkg::fun`.  I made the test for function inclusion
independent of order and added more tests.