I was wondering if anyone possibly had any experience integrating R into Rails, specifically, on heroku. I am familiar with the rsruby gem, which is the de facto (perhaps only)
I explored R/Rails integration a couple of years ago, so my posts will be out of date by now. However, they're still available and might be useful if you want to read them:
RSRuby and Rails revisited.
One issue I encountered was a "stack smashing error" on terminating the development server, which made me nervous as to whether the project was worth pursuing.
I have not tried deployment to Heroku. In principle, I like your idea of putting R in the Rails lib/, but I'm not sure if it would work.
In general, I find that bridging other languages with R is troublesome. It might be better to keep the two separate, by running R on a server (using e.g. RApache) and passing data back/forth between that and the Rails app (e.g. as JSON). Another post that I wrote on that idea:
Getting your web application and R(Apache) to talk to each other