r

package
v0.0.0-...-77310ea Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2017 License: MIT Imports: 15 Imported by: 1

README

R

R interface from Go.

"A program calling command line tools is the moral equivalent of web scraping #lca2016"

Documentation

Overview

Package r provides an interface to the R statistical programming language. Users can interface with R through three methods: Call, Get or Rpc. Call executes a function call and returns a unique key that can be used in subseqent calls to Get to retrieve the results. Get can return results in json, csv, png or pdf. Rpc can be used to bundle Call and Get in a single function call.

As a single R session:

session, err := r.NewSession()
...
key, err := session.Call("stats","rnorm","n=100")
...
res, err := session.Get(key, "json")
...
res, err = session.Rpc("stats", "rnorm", "n=100", "json")
...

standalone server that accepts HTTP requests (e.g. from the Client or curl)

s, err := r.Server(4, "/tmp/kvik")
...
s.Start(":8181")

or a client if there is a server running somewhere:

client := r.Client{"http://localhost.com:8181", "username","password"}
key, err := client.Call("stats","rnorm","n=100")
...
res, err := client.Get(key, "json")
...
res, err := client.Rpc("stats","rnorm","n=100","json")
...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call struct {
	Package   string
	Function  string
	Arguments string
}

type Client

type Client struct {
	Addr     string
	Username string
	Password string
}

func (*Client) Call

func (c *Client) Call(pkg, fun, args string) (string, error)

func (*Client) Get

func (c *Client) Get(key, format string) ([]byte, error)

func (*Client) Rpc

func (c *Client) Rpc(pkg, fun, args, format string) ([]byte, error)

Call and get in one call

type Server

type Server struct {
	// contains filtered or unexported fields
}

func InitServer

func InitServer(numWorkers int, dir string) (Server, error)

func (*Server) Call

func (s *Server) Call(pkg, fun, args string) (string, error)

func (*Server) CallHandler

func (s *Server) CallHandler(w http.ResponseWriter, r *http.Request)

func (*Server) EnableCaching

func (s *Server) EnableCaching()

func (Server) Get

func (s Server) Get(key, format string) ([]byte, error)

func (*Server) GetHandler

func (s *Server) GetHandler(w http.ResponseWriter, r *http.Request)

func (*Server) RpcHandler

func (s *Server) RpcHandler(w http.ResponseWriter, r *http.Request)

func (*Server) Start

func (s *Server) Start(port string) error

type Session

type Session struct {
	// contains filtered or unexported fields
}

func NewSession

func NewSession(id int) (*Session, error)

func (*Session) Call

func (rs *Session) Call(pkg, fun, args string) (string, error)

func (*Session) Get

func (rs *Session) Get(key, format string) ([]byte, error)

func (*Session) InstalledPackages

func (rs *Session) InstalledPackages() ([]byte, error)

func (*Session) Rpc

func (s *Session) Rpc(pkg, fun, args, format string) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL