Is there an R client for Couchbase?

Hey,
We are looking for ways to load data from Couchbase into R.
I haven’t seen any signs of an existing R client for Couchbase. I have only found the below question on CRAN: http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2014-March/007361.html

Any info about an existing library or other ways loading data from Couchbase to R?

Thanks

@zfedor to my knowledge there is no community contributed SDK for R and also no officially supported one.

But we do support a variety of others, maybe it is possible to call from R into one of the support languages? I know that there is some compatbility between R and C#/F#, so maybe you are able to hook it up with the .NET SDK?

Thanks.
I’m not good at .NET, so I might rather hook it up to the Python API

Hello. I don’t think there is need for a binary SDK. You can talk from R to couchbase using json format over the http…

http://blog.couchbase.com/incremental-mapreduce-analytics-r

Thanks, but I already implemented my R module which is using the - Python Couchbase API via the rpython package.

Hello, zfedor.

I am really struggling here with the REST. Can you please show how to make the interface through the R.

Do you have some code to share? Basically, I need to be able to INSERT Json documents and query them from within R.

thanks a bunch
Servet

Hi Servet,
Sure, actually it is pretty easy, just write up a Python module to communicate with Couchbase and then use the RPython R package to talk to your Python module.

Below is a pseudo-example for reading data from Couchbase. Writing would be about the same.

The R code:
library(“rPython”)
python.load(‘couchbase-R.py’, get.exception = TRUE)

key <- '10801’
python.assign(“key”, key) # set the key variable in Python to the key of the document I will want to get from Couchbase
doc <- tryCatch({
python.exec(“doc=get_by_key(key)”) # call the Python function loading data out of Couchbase
python.get(“doc”) # get the doc variable back from Python with the stringified JSON document
}, warning = function(w) {
# warning-handler-code
}, error = function(e) {
# error-handler-code
doc <- NULL
}, finally = {
# cleanup-code
})
doc

The Python module (sorry, indentations lost due to the forum editor not keeping them, so you will need to add those back to make it run):
# couchbase
from couchbase.bucket import Bucket
from couchbase.exceptions import CouchbaseError

bucket = Bucket(‘couchbase://x.x.x.x/default’)

# get the content of a doc from couchbase by using the docid
def get_by_key(key):
try:
doc = bucket.get(key)

except CoucbbaseError as e:
print(“Couldn’t retrieve value for key”, e)
# Rethrow the exception, making the application exit
raise

return str(doc.value)

3 Likes

thanks a lot zfedor. I will look at it very soon.

Hi,
sorry for pick this topic to up,

do you have any plan to make R SDK or not?
as you know R is most powerful Statistic language and many of bigdata-users use language like R to make decision of big data.

@vhp1360 right now we don’t have plans for an R SDK but you can make use of Couchbase through the Spark Connector. We have first class spark integration and spark integrates well with R - is that a path you could pursue?