Issue described in the following StackOverflow question: http://stackoverflow.com/questions/21809092/extremely-slow-r-code-and-hanging 