Giter Club home page Giter Club logo

go-r's Introduction

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.

go-r's People

Contributors

nchern avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.