Reputation: 565
I will try to explain as clearly as possible my issue.
My company has a Ruby on Rails 3 environment. Guys in charge of the RoR environment spent a lot of time on it and made a great job at building a complex information system.
I am an R user, and I would like to take advantage of the Rails layer they developped.
Is there an easy way for a local R instance to connect to the remote Rails server and use its set of functions to retrieve data ? The development team has total control over the Rails environment/server and I can easily interact with them, but they do not know much about R.
I have been looking at RSRuby, Rserve (Rserve-Ruby-client), Resque, RinRuby... but to my limited understanding, it always seems to be Ruby being an R client.
For R using Ruby, apart from local call to the Ruby console (not Rails) such as
x=system('ruby calc.rb', intern=TRUE)
. I could not find much.
Would stackoverflow community has some suggestion there ?
Upvotes: 1
Views: 592
Reputation: 64363
I am assuming R can invoke REST based services. Your rails team can expose the RAILS server functions using the REST interface. In Rails 3, it is easy to convert a HTML service to a REST(XML/JSON) service.
Additional Notes based on user comment
Let us assume that you have a Users
controller with an index
action to return a list of users in a HTML document.
class UsersController
def index
@users = User.all
respond_with(@users)
end
end
To enable the index
service to return the user list in XML/JSON format:
class UsersController
respond_to :html, :xml, :json
def index
@users = User.all
respond_with(@users)
end
end
Now
http://host/users.xml
returns a XML document
http://host/users.json
returns a JSON structure
The XML/JSON wire format is fixed by rails. You don't need to create a template for this. You should work with your rails team to get the XML/JSON document structure. A typical XML document might look like this:
http://host/orders/1
<?xml version="1.0" encoding="UTF-8"?>
<order>
<client-id type="integer">1</client-id>
<created-at type="datetime">2011-04-03</created-at>
<id type="integer">1</id>
<updated-at type="datetime">2011-04-03</updated-at>
...
</order>
Upvotes: 4
Reputation: 21502
The advice from other blogs, e.g. http://www.r-bloggers.com/calling-ruby-perl-or-python-from-r/ , seems to be to go ahead and use system calls. What you're hoping for is basically an interpreter, which is a big job (and usually doesn't work well :-( ). I'd recommend you collect the basic system calls you'll be using regularly and put them into an R-function. that way, you only need to type
> My.new.data <- tellRuby(data_to_get)
and your "tellRuby" function can call the dbase and return the desired data.
Upvotes: 0
Reputation: 4113
I don't really know anything about R either, but it seems like you're likely to have the ability to load a remote URL and process XML, which means you could use activeresource to get data out of their system, and that's really all it takes. A rails system isn't any different from any other web-based system at the application boundary (web server). You could also get data back from Rails in JSON or any other format that's friendly to R if your Rails developers are willing to add those outputs (most of which you can get for free with one gem or another.)
Upvotes: 3