svarcheg / rincanter

Use Rserve to call R from Clojure and Incanter

Home Page:https://github.com/svarcheg/rincanter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Welcome to Rincanter!

About

Main difference from original rincanter is that this version does not require playing with native libraries as it uses a socket connection to the R interpreter. As the original version, it also offers translation between Clojure and Incanter datatypes and R datatypes such as R dataframe to Incanter dataset.

Installation

Install R for your platform

The directions for installing R are outside the scope of this document, but R is well supported on most platforms, and has great documentation: R Project Page

Install and launch Rserve

From R execute following lines:

install.packages("Rserve")
library(Rserve)
Rserve()

Add rincanter dependency to project.clj

[svarcheg/rincanter "0.0.1-SNAPSHOT"]

Example Usage

The main entry points are the functions:

r-eval

You can play around with Clojure/Incanter and R in the same REPL session:

(use '(rincanter core))

(r-eval "data(iris)")

;;eval's the iris dataframe object, converts into
;;incanter dataset
(r-eval "iris")
 
;;create vector on R side
(r-eval "vec_in_r = c(1,2,3)")

;;now retrieve it, converting to Clojure vector
(r-get "vec_in_r")

plotting:

(use '(rincanter core))

(r-eval "data(iris)")

;;initialize the R graphics device for your system:
;;For Mac OS X
(r-eval "quartz()")
;;windows: 
(r-eval "windows()")
;;unix/linux
(r-eval "x11()")

;;create the plot using values from the iris dataset
(r-eval "plot(Sepal.Length ~ Sepal.Width, data = iris)")
;;alter this existing plot
(r-eval "title(main = \"Iris Sepal Measurements\")")

with-r-eval

Using with-r-eval, it is even easier. Within this form, all forms enclosed in parenthesis are evaluated as normal Clojure forms, strings are evaluated in R using r-eval:

(use '(rincanter core))

(with-r-eval 
  "data(iris)"

  ;;eval's the iris dataframe object, converts into
  ;;incanter dataset
  "iris"
 
  ;;create vector on R side
  "vec_in_r = c(1,2,3)"

  ;;now retrieve it, converting to Clojure vector
  (r-get "vec_in_r"))

Documentation

API Documentation

API Documentation for rincanter is located at: Rincanter API

About

Use Rserve to call R from Clojure and Incanter

https://github.com/svarcheg/rincanter


Languages

Language:Clojure 60.0%Language:HTML 40.0%