ropensci / sofa

Easy R interface to CouchDB
https://docs.ropensci.org/sofa/
33 stars 17 forks source link

Add ability to parse R like queries to javascript Couch Views #3

Closed sckott closed 4 years ago

sckott commented 11 years ago

Important for R users that don't know javascript, which is likely many

wactbprot commented 11 years ago

Maybe Duncan has a starting point:

https://github.com/omegahat/RJavaScript

sckott commented 11 years ago

Ah, thanks very much!

andrewcstewart commented 9 years ago

Hey @sckott , would this be the same thing as writing a CouchDB query server in R (similar to the python server) ?

sckott commented 9 years ago

@andrewcstewart not familiar with the couch query server? link?

sckott commented 9 years ago

@andrewcstewart views refers to these http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views

andrewcstewart commented 9 years ago

http://docs.couchdb.org/en/latest/query-server/protocol.html

CouchDB's Views can be written in any language that a query server has been implemented for. For example you can write your view functions in python using http://couchdb-python.googlecode.com/svn/trunk/couchdb/view.py

I've started working out how to write a query server in R. Not sure if that's within the scope of what you're trying to do with this issue item, but might be of interest?

sckott commented 9 years ago

Possibly. What is the use case for query server in R?

andrewcstewart commented 9 years ago

The general use case would be for anyone who wants to write their View functions in R instead of javascript/erland/python, etc.  

A more specific example:  I and my team do data analysis in R and are starting to use CouchDB as a database for our data and results.  Not everyone in our team is bilingual in R and javascript, so I’ve been investigating whether we could write our view functions in R instead.

I have the meat of the query server written (I/O, function handler, and implementations of the add_fun and map_doc functions).  I just need to write a couple more function handlers and work out some kinks with how Couch runs an R script.

— Sent from Mailbox

On Fri, Jan 16, 2015 at 10:50 AM, Scott Chamberlain notifications@github.com wrote:

Possibly. What is the use case for query server in R?

Reply to this email directly or view it on GitHub: https://github.com/sckott/sofa/issues/3#issuecomment-70302160

sckott commented 9 years ago

@andrewcstewart That sounds great. That is the goal of this issue to figure out how to let users write views in R instead of javascript, so this is perfect.

Would you be interested in contributing code to this pkg? You'd definitely be an author

andrewcstewart commented 9 years ago

Absolutely.  We’ve been actively using your library to talk to couch from R, so it’s a perfect fit for this.  The only question I would have is how a standalone Rscript is handled with the R package format.  Installing the Rscript would take place on CouchDB’s side of things by adding the path to the script to Couch’s config file.  That can actually be done through REST call I believe, so perhaps it could be done directly from the R package?

library(sofa)
sofa.install_server(“http://127.0.0.1:5984”,user,pass)

etc..

— Sent from Mailbox

On Fri, Jan 16, 2015 at 3:10 PM, Scott Chamberlain notifications@github.com wrote:

@andrewcstewart That sounds great. That is the goal of this issue to figure out how to let users write views in R instead of javascript, so this is perfect.

Would you be interested in contributing code to this pkg? You'd definitely be an author

Reply to this email directly or view it on GitHub: https://github.com/sckott/sofa/issues/3#issuecomment-70337711

sckott commented 9 years ago

Hmmm, I think that would work fine. Just pass a file path to a function that get ingested by Couch.

andrewcstewart commented 9 years ago

Great. I can do a pull request as this gets closer to being functional. My only question would be where to place the Rscript file. Any suggestion?

sckott commented 9 years ago

Is the script something that changes/needs use input based before using, or is it not meant to be edited? If the latter, it can be stored in the package itself. If former, we could store a template maybe, then user has to edit it, then pass that in. Sorry if I'm not making sense, trying to make sense of how this is used

andrewcstewart commented 9 years ago

The script is a static I/O pass-through.  It listens for JSON from couchdb and return JSON back to it.   It’s basically just an R implementation of the following python script: http://couchdb-python.googlecode.com/svn/trunk/couchdb/view.py

— Sent from Mailbox

On Mon, Jan 19, 2015 at 12:04 PM, Scott Chamberlain notifications@github.com wrote:

Is the script something that changes/needs use input based before using, or is it not meant to be edited? If the latter, it can be stored in the package itself. If former, we could store a template maybe, then user has to edit it, then pass that in. Sorry if I'm not making sense, trying to make sense of how this is used

Reply to this email directly or view it on GitHub: https://github.com/sckott/sofa/issues/3#issuecomment-70552254

sckott commented 9 years ago

Okay, when you send PR, put the file in inst/extdata/ https://github.com/sckott/sofa/tree/master/inst/extdata I'm not sure that's the final place it should be, but once it's in the pkg, we can play around with the best spot for it.

andrewcstewart commented 9 years ago

hey @sckott I'm adding the script to my fork now. Do you have any preference for what to name the function that loads the R script into CouchDB?

andrewcstewart commented 9 years ago

More on that note: It looks like the API call to couch's config would be something like

curl -X PUT http://[localhost]/_config/query_servers/R "/sofa/inst/extdata/view.R"

The drawback here though is that I think this will only work on the same host as CouchDB. (http://stackoverflow.com/questions/15456989/setting-up-a-python-viewserver-for-couchdb)

sckott commented 9 years ago

@andrewcstewart no, no preference on the fxn name.

Hmm, is that a huge problem if it only work son the same host as couch?

andrewcstewart commented 9 years ago

I’ve got to imagine that there’s some way to do it, even if it involves something like uploading the script to CouchDB as an attachment and referencing the destination path in the config.

On the other hand, since the CouchDB host will need to be running R anyway in order to use a query server written in R, maybe it’s not that unreasonable of a requirement to have the sofa package installed on the CouchDB host?

— Sent from Mailbox

On Mon, Jan 26, 2015 at 10:02 AM, Scott Chamberlain notifications@github.com wrote:

@andrewcstewart no, no preference on the fxn name.

Hmm, is that a huge problem if it only work son the same host as couch?

Reply to this email directly or view it on GitHub: https://github.com/sckott/sofa/issues/3#issuecomment-71506426

sckott commented 9 years ago

Sounds good

andrewcstewart commented 9 years ago

Just to update:

So I've got the basics down for this, though I need to still add the exception handling and the reduce function handlers. It should work in theory, though it's not passing my tests yet. I need to troubleshoot it a bit, but I can pull request prematurely if you're interested in seeing how it works so far.

sckott commented 6 years ago

@andrewcstewart don't know if you're still interested, sorry i missed this many years ago 😢