Golang RServe client. Use R from Go
Switch branches/tags
Clone or download
dareid Merge pull request #41 from joescharf/master
Missing for loops in sexp.parseSymName() and sexp.parseString() causing vector attributes to be parsed incorrectly
Latest commit 5a944f2 Sep 4, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assign use a signed int64 instead of uint64 as large header Nov 17, 2017
constants Added support for int and double assignment Jul 20, 2017
sexp fixing bug - for instead of if -in xt-string and xt-sym-name where en… Sep 2, 2018
test Updated r-base version for dockerfiles as prior version giving error … Sep 2, 2018
.gitignore Initial commit Aug 10, 2015
.travis.yml Trying to fix travis build Jul 9, 2016
CHANGELOG.md Bumping version to 0.3.1 Jul 13, 2017
LICENSE Updating license Jun 21, 2016
README.md Added support for int and double assignment Jul 20, 2017
assignment_test.go Added support for int and double assignment Jul 20, 2017
client.go Adding support for sessions closing #14. Cleanup of client API. Impro… Sep 3, 2015
client_test.go Fixed handshake failure detection. Closes #32 Mar 5, 2016
crypt.go Supporting authentication. Closes #2 Aug 21, 2015
doc.go Adding godoc badge. Improving documentation formatting. Aug 23, 2015
list-processing_test.go Correcting offset returned by parseBoolArray. Partly fixes #26 (still… Jan 18, 2016
packet.go Added public GetError method to the packet. Dec 1, 2017
packet_test.go Added two tests to the new packet.GetError method. Dec 1, 2017
session.go Fixing large assignments. Closes #36 Jul 13, 2017
session_test.go Reorganisation and cleanup. Added a few tests. Feb 8, 2016
sexp_parsing_test.go added a test for testing the return of a class - specifically this cl… Sep 4, 2018

README.md

Roger

GoDoc Build Status Join the chat at https://gitter.im/senseyeio/roger

Roger is a Go RServe client, allowing the capabilities of R to be used from Go applications.

The communication between Go and R is via TCP. It is thread safe and supports long running R operations synchronously or asynchronously (using channels).

package main

import (
	"fmt"

	"github.com/senseyeio/roger"
)

func main() {
	rClient, err := roger.NewRClient("127.0.0.1", 6311)
	if err != nil {
		fmt.Println("Failed to connect")
		return
	}

	value, err := rClient.Eval("pi")
	if err != nil {
		fmt.Println("Command failed: " + err.Error())
	} else {
		fmt.Println(value) // 3.141592653589793
	}

	helloWorld, _ := rClient.Eval("as.character('Hello World')")
	fmt.Println(helloWorld) // Hello World

	arrChan := rClient.Evaluate("Sys.sleep(5); c(1,1)")
	arrResponse := <-arrChan
	arr, _ := arrResponse.GetResultObject()
	fmt.Println(arr) // [1, 1]
}

Response Type Support

Roger currently supports the following response types from R:

  • string and string arrays
  • booleans and boolean arrays
  • doubles and double arrays
  • ints and int arrays
  • complex and complex arrays
  • lists
  • raw byte arrays

With the use of JSON, this capability can be used to transfer any serializable object. For examples see sexp_parsing_test.go.

Assignment Support

Roger allows variables to be defined within an R session from Go. Currently the following types are supported for variable assignment:

  • string and string arrays
  • byte arrays
  • doubles and double arrays
  • ints and int arrays

For examples see assignment_test.go.

Setup

Rserve should be installed and started from R:

install.packages("Rserve")
require('Rserve')
Rserve()

More information is available on RServe's website.

If you would like to exploit the current R environment from go, start RServe using the following command:

install.packages("Rserve")
require('Rserve')
run.Rserve()

Install Roger using:

go get github.com/senseyeio/roger

Testing

To ensure the library functions correctly, the end to end functionality must be tested. This is achieved using Docker and Docker Compose. To run tests, ensure you have both Docker and Docker Compose installed, then run docker-compose build && docker-compose up -d from within the test directory. This command will build and start a docker container containing multiple RServe servers. These servers will be utilized when running go test from the project's base directory. To stop the docker container call docker-compose stop from the test directory.

Contributing

Issues, pull requests and questions are welcomed. If required, assistance can be found in the project's gitter chat room.

Pull Requests

  • Fork the repository
  • Make changes
  • Ensure tests pass
  • Raise pull request