暂无描述

nchern bae9c3fe85 Updated readme 10 年之前
R a6a9c7d97e Added ToArrary() methods. Cleanup examples. 10 年之前
c 6bd6c79c6c modified examples 11 年之前
example a6a9c7d97e Added ToArrary() methods. Cleanup examples. 10 年之前
.gitignore d932295e64 ignore *.out 11 年之前
README.md bae9c3fe85 Updated readme 10 年之前

README.md

go-R

Go(golang) bindings for R language

This is simple binding to eval R expressions and pass results to/from Go code.

WARNING!

Project in the early stage, memory leaks and even SIGFAULTs are possible. Use it on your own risk.

Known issues

  • You should call R.Init() exactly in main goroutine of the app(i.e. not in goroutine created by your app). This was found by experiments. Possible reason is clashing between process thread stack and goroutine stack. As a result, its impossible to run R-related code in tests as go test run its testing function in custom goroutine per test.

Getting started

  1. Install https://github.com/stretchrcom/testify testing package.
  2. Install R environment: http://cran.r-project.org/
  3. Check if you have R header files under correct path(check #cgo CFLAGS: directive in sources.
  4. Make sure libR.so is avaliable. Set $LD_LIBRARY_PATH if R istallation is not system-wide.
  5. Make sure $R_HOME is set and pointed to your R location before you run any R-related code.
  6. Run go run main.go under go-R/example directory.

Basic usage

package main

import (
    "fmt"

    "github.com/nchern/go-R/R"
)

func main() {
    R.Init()

    x := R.NewNumericVector([]float64{1, 2, 3})
    R.SetSymbol("x", x)
    r := R.EvalOrDie("sum(x)").AsNumeric()
    fmt.Println(r.Get(0))
}

More examples are in test code.