RMongo: Accessing MongoDB in R

I recently created RMongo, a database access layer to MongoDB in R as an R package.

To install RMongo:

install.packages(“RMongo”)

If that does not work, try downloading it from https://github.com/tc/RMongo/downloads and run:

install.packages("~/Downloads/RMongo_0.0.21.tar.gz", repos=NULL, type="source")

I tried to mimic the RMySQL commands in RMongo. Below are some example commands.

library(RMongo)

#ask for help
?RMongo

#connect to a database
mongo results names(results)
[1] “X_id” “name” “nutrient_definition_id” “description”
> results
X_id name nutrient_definition_id
1 4cd0f8e31e627d4e6600000e Adjusted Protein 257
2 4cd0f9061e627d4e6600001a Sodium 307

> results results
X_id name nutrient_definition_id
1 4cd0f9061e627d4e6600001a Sodium 307

> dbDisconnect(mongo)

 

RMongo is very alpha at this point. I built it as a quick way to prototype algorithms with data from mongoDB in R. Most of RMongo uses the mongo-java-driver to perform json-formatted queries. The R code in the package uses rJava to communicate with the mongo-java-driver.

Please report any bugs or necessary improvements. Or better yet, send in pull requests via the RMongo github project page!

About tommychheng
I write a tech blog at http://tommy.chheng.com

9 Responses to RMongo: Accessing MongoDB in R

  1. meghangill says:

    Very cool, I added the driver to the MongoDB Drivers page:http://www.mongodb.org/display/DOCS/DriversEmail me (meghan@10gen.com) – would love to send you some swag as a thank you for your contribution!

  2. Sami says:

    There seems to be some bug or odd behaviour when trying to use mongodb with RMongo version 0.0.18.Connection goes normally:mongo.con<-mongoDbConnect(“tickets”,host=”localhost”,port=27017)But any attempt to use the connection results in Java IO exception:dbShowCollections(mongo.con)Feb 4, 2011 6:17:10 PM com.mongodb.DBTCPConnector$MyPort errorSEVERE: MyPort.error calledjava.io.IOException: couldn't connect to [machine.name/127.0.1.1:27017] bc:java.net.ConnectException: Connection refused at com.mongodb.DBPort._open(DBPort.java:172) at com.mongodb.DBPort.go(DBPort.java:79) at com.mongodb.DBPort.call(DBPort.java:55) at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:201) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:256) at com.mongodb.DB.getCollectionNames(DB.java:200) at com.quid.RMongo.dbShowCollections(RMongo.scala:24)Any help is appreciated.

  3. tommychheng says:

    see https://github.com/quid/RMongo… for resolution

  4. Carlos Rodriguez says:

    0.18 installs but with the latest ver. 0.20 I get the errors below…. what am I doing wrong?

    ———————————————–
    c:>R CMD INSTALL RMongo_0.0.20.tar.gz
    R CMD INSTALL RMongo_0.0.20.tar.gz
    * installing to library ‘C:/Program Files/R/R-2.13.0/library’
    * installing *source* package ‘RMongo’ …
    ** libs
    C:/PROGRA~1/R/R-213~1.0/etc/i386/Makeconf:180: warning: overriding commands for target `.m.o’
    C:/PROGRA~1/R/R-213~1.0/etc/i386/Makeconf:173: warning: ignoring old commands for target `.m.o’
    ERROR: compilation failed for package ‘RMongo’
    * removing ‘C:/Program Files/R/R-2.13.0/library/RMongo’

    c:\>R CMD INSTALL RMongo_0.0.18.tar.gz
    R CMD INSTALL RMongo_0.0.18.tar.gz
    * installing to library ‘C:/Program Files/R/R-2.13.0/library’
    * installing *source* package ‘RMongo’ …
    ** R
    ** inst
    ** preparing package for lazy loading
    ** help
    *** installing help indices
    ** building package indices …
    ** testing if installed package can be loaded

    * DONE (RMongo)

    ——————————————————————————————

  5. Pingback: #Rstats for Business Intelligence « DECISION STATS

  6. Many says:

    Hi,

    I want to try your RMongo (Just learning :-) but when I try:
    R CMD install RMongo*.tar.gz
    I get this error:
    install: missing destination file operand after `RMongo_0.0.21.tar.gz’
    Try `install –help’ for more information.

    I’m not sure what destination file should I point RMongo to

    Hope you can help me with this.

    Thanks in advance

  7. hi Tom, this great!, familiar with this…:) thank for sharing, perte de poids

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.