sexp

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package sexp provides an API for interacting with R SEXP values. Except where noted, values are allocated by the R runtime.

Here be dragons

The API provided by the sexp package only minimally interacts with the R runtime, so deviations from behavior expected by the R runtime are possible. This package should be used with caution and client packages should ensure correct behavior with adequate testing from the R side.

Building the sexp package requires having CGO_LDFLAGS_ALLOW="-Wl,-Bsymbolic-functions" and installations of R and pkg-config.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComplexNA

func ComplexNA() complex128

ComplexNA returns the R complex NA value. The value returned is NA+0i.

func IntegerNA

func IntegerNA() int32

IntegerNA returns the R integer NA value.

func IsComplexNA

func IsComplexNA(c complex128) bool

IsComplexNA returns whether c is an NA value. This is true if either of the parts of c is NA.

func IsIntegerNA

func IsIntegerNA(i int32) bool

IsIntegerNA returns whether i is an NA value.

func IsLogicalNA

func IsLogicalNA(b int32) bool

IsLogicalNA returns whether b is an NA value.

func IsRealNA

func IsRealNA(f float64) bool

IsRealNA returns whether f is an NA value.

func LogicalNA

func LogicalNA() int32

LogicalNA returns the R logical NA value.

func RealNA

func RealNA() float64

RealNA returns the R real NA value.

Types

type Builtin

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

Builtin is an R language built-in function.

func (*Builtin) Offset

func (v *Builtin) Offset() int32

Offset returns the offset into the table of language primitives.

func (*Builtin) Value

func (v *Builtin) Value() *Value

Value returns the generic state of the SEXP value.

type Character

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

Character is the R representation of a string.

func NewCharacter

func NewCharacter(s string) *Character

NewCharacter returns a scalar string corresponding to s.

The allocation is made by the R runtime. The returned value may need to call its Protect method.

func NewCharacterFromBytes

func NewCharacterFromBytes(b []byte) *Character

NewCharacterFromBytes returns a scalar string corresponding to b.

The allocation is made by the R runtime. The returned value may need to call its Protect method.

func (*Character) Bytes

func (v *Character) Bytes() []byte

Bytes returns the bytes held by the R SEXP value.

func (*Character) Len

func (v *Character) Len() int

Len returns the number of elements in the vector.

func (*Character) Protect

func (v *Character) Protect() *Character

Protect protects the SEXP value and returns it.

func (*Character) String

func (v *Character) String() string

String returns a Go string corresponding the the R characters. The returned string is allocated by the Go runtime.

func (*Character) Unprotect

func (v *Character) Unprotect()

Unprotect unprotects the SEXP. It is equivalent to UNPROTECT(1).

func (*Character) Value

func (v *Character) Value() *Value

Value returns the generic state of the SEXP value.

type Closure

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

Closure is an R closure.

func (*Closure) Body

func (v *Closure) Body() *Value

Body returns the body of the function.

func (*Closure) Environment

func (v *Closure) Environment() *Value

Environment returns the environment in which to evaluate the function.

func (*Closure) Formals

func (v *Closure) Formals() *Value

Formals returns the formal arguments of the function.

func (*Closure) Value

func (v *Closure) Value() *Value

Value returns the generic state of the SEXP value.

type Complex

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

Complex is an R complex vector.

func NewComplex

func NewComplex(n int) *Complex

NewComplex returns a complex vector with length n.

The allocation is made by the R runtime. The returned value may need to call its Protect method.

func (*Complex) Len

func (v *Complex) Len() int

Len returns the number of elements in the vector.

func (*Complex) Protect

func (v *Complex) Protect() *Complex

Protect protects the SEXP value and returns it.

func (*Complex) Unprotect

func (v *Complex) Unprotect()

Unprotect unprotects the SEXP. It is equivalent to UNPROTECT(1).

func (*Complex) Value

func (v *Complex) Value() *Value

Value returns the generic state of the SEXP value.

func (*Complex) Vector

func (v *Complex) Vector() []complex128

Vector returns a slice corresponding to the R vector.

type Dot

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

Dot is an R pairlist of promises.

func (*Dot) Head

func (v *Dot) Head() *Value

Head returns the first element of the list (CAR/lisp in R terminology).

func (*Dot) Tag

func (v *Dot) Tag() *Symbol

Tag returns the object's tag value.

func (*Dot) Tail

func (v *Dot) Tail() *Value

Tail returns the remaining elements of the list (CDR/lisp in R terminology).

func (*Dot) Value

func (v *Dot) Value() *Value

Value returns the generic state of the SEXP value.

type Environment

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

Environment is a current execution environment.

func (*Environment) Enclosing

func (v *Environment) Enclosing() *Value

Enclosing returns the enclosing environment.

func (*Environment) Frame

func (v *Environment) Frame() *Value

Frame returns the current frame.

func (*Environment) HashTable

func (v *Environment) HashTable() *Value

HashTable returns the environment's hash table.

func (*Environment) Value

func (v *Environment) Value() *Value

Value returns the generic state of the SEXP value.

type Expression

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

Expression is an R expression.

func (*Expression) Len

func (v *Expression) Len() int

Len returns the number of elements in the vector.

func (*Expression) Value

func (v *Expression) Value() *Value

Value returns the generic state of the SEXP value.

func (*Expression) Vector

func (v *Expression) Vector() []*Value

Vector returns a slice corresponding to the R expression.

type Info

type Info uint64

Info corresponds to the sxpinfo_struct type defined in Rinternals.h.

func (Info) Debug

func (i Info) Debug() bool

func (Info) Extra

func (i Info) Extra() uint16

func (Info) GCClass

func (i Info) GCClass() int

func (Info) GCGen

func (i Info) GCGen() int

func (Info) GP

func (i Info) GP() uint16

func (Info) IsAltRep

func (i Info) IsAltRep() bool

func (Info) IsInUse

func (i Info) IsInUse() bool

func (Info) IsObject

func (i Info) IsObject() bool

func (Info) IsScalar

func (i Info) IsScalar() bool

func (Info) Named

func (i Info) Named() uint16

func (Info) Space

func (i Info) Space() bool

func (Info) String

func (i Info) String() string

func (Info) Trace

func (i Info) Trace() bool

func (Info) Type

func (i Info) Type() Type

type Integer

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

Integer is an R integer vector.

func NewInteger

func NewInteger(n int) *Integer

NewInteger returns an integer vector with length n.

The allocation is made by the R runtime. The returned value may need to call its Protect method.

func (*Integer) Len

func (v *Integer) Len() int

Len returns the number of elements in the vector.

func (*Integer) Protect

func (v *Integer) Protect() *Integer

Protect protects the SEXP value and returns it.

func (*Integer) Unprotect

func (v *Integer) Unprotect()

Unprotect unprotects the SEXP. It is equivalent to UNPROTECT(1).

func (*Integer) Value

func (v *Integer) Value() *Value

Value returns the generic state of the SEXP value.

func (*Integer) Vector

func (v *Integer) Vector() []int32

Vector returns a slice corresponding to the R vector.

type Lang

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

Lang is an R language object.

func (*Lang) Head

func (v *Lang) Head() *Value

Head returns the first element of the list (CAR/lisp in R terminology).

func (*Lang) Tag

func (v *Lang) Tag() *Symbol

Tag returns the object's tag value.

func (*Lang) Tail

func (v *Lang) Tail() *Value

Tail returns the remaining elements of the list (CDR/lisp in R terminology).

func (*Lang) Value

func (v *Lang) Value() *Value

Value returns the generic state of the SEXP value.

type List

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

List is an R linked list.

func NewList

func NewList(n int) *List

NewList returns a list with length n.

func (*List) Get

func (v *List) Get(tag []byte) *Value

Get returns the the Value associated with the given tag in the list.

func (*List) Head

func (v *List) Head() *Value

Head returns the first element of the list (CAR/lisp in R terminology).

func (*List) Protect

func (v *List) Protect() *List

Protect protects the SEXP value and returns it.

func (*List) Tag

func (v *List) Tag() *Symbol

Tag returns the list's tag value.

func (*List) Tail

func (v *List) Tail() *Value

Tail returns the remaining elements of the list (CDR/lisp in R terminology).

func (*List) Unprotect

func (v *List) Unprotect()

Unprotect unprotects the SEXP. It is equivalent to UNPROTECT(1).

func (*List) Value

func (v *List) Value() *Value

Value returns the generic state of the SEXP value.

type Logical

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

Logical is an R logical vector.

func NewLogical

func NewLogical(n int) *Logical

NewLogical returns a logical vector with length n.

The allocation is made by the R runtime. The returned value may need to call its Protect method.

func (*Logical) Len

func (v *Logical) Len() int

Len returns the number of elements in the vector.

func (*Logical) Protect

func (v *Logical) Protect() *Logical

Protect protects the SEXP value and returns it.

func (*Logical) Unprotect

func (v *Logical) Unprotect()

Unprotect unprotects the SEXP. It is equivalent to UNPROTECT(1).

func (*Logical) Value

func (v *Logical) Value() *Value

Value returns the generic state of the SEXP value.

func (*Logical) Vector

func (v *Logical) Vector() []int32

Vector returns a slice corresponding to the R vector.

type Promise

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

Promise is an R promise.

func (*Promise) Environment

func (v *Promise) Environment() *Value

Environment returns the environment in which to evaluate the expression.

func (*Promise) Expression

func (v *Promise) Expression() *Value

Expression returns the expression to be evaluated.

func (*Promise) PromiseValue

func (v *Promise) PromiseValue() *Value

PromiseValue returns the value of the promise.

func (*Promise) Value

func (v *Promise) Value() *Value

Value returns the generic state of the SEXP value.

type Raw

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

Raw is an R raw vector.

func NewRaw

func NewRaw(n int) *Raw

NewRaw returns a raw vector with length n.

The allocation is made by the R runtime. The returned value may need to call its Protect method.

func (*Raw) Bytes

func (v *Raw) Bytes() []byte

Bytes returns the bytes held by the R SEXP value.

func (*Raw) Len

func (v *Raw) Len() int

Len returns the number of elements in the vector.

func (*Raw) Protect

func (v *Raw) Protect() *Raw

Protect protects the SEXP value and returns it.

func (*Raw) Unprotect

func (v *Raw) Unprotect()

Unprotect unprotects the SEXP. It is equivalent to UNPROTECT(1).

func (*Raw) Value

func (v *Raw) Value() *Value

Value returns the generic state of the SEXP value.

type Real

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

Real is an R real vector.

func NewReal

func NewReal(n int) *Real

NewReal returns a real vector with length n.

The allocation is made by the R runtime. The returned value may need to call its Protect method.

func (*Real) Len

func (v *Real) Len() int

Len returns the number of elements in the vector.

func (*Real) Protect

func (v *Real) Protect() *Real

Protect protects the SEXP value and returns it.

func (*Real) Unprotect

func (v *Real) Unprotect()

Unprotect unprotects the SEXP. It is equivalent to UNPROTECT(1).

func (*Real) Value

func (v *Real) Value() *Value

Value returns the generic state of the SEXP value.

func (*Real) Vector

func (v *Real) Vector() []float64

Vector returns a slice corresponding to the R vector.

type Special

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

Special is an R language built-in function.

func (*Special) Offset

func (v *Special) Offset() int32

Offset returns the offset into the table of language primitives.

func (*Special) Value

func (v *Special) Value() *Value

Value returns the generic state of the SEXP value.

type String

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

String is an R character vector.

func NewString

func NewString(n int) *String

NewString returns a character vector with length n.

The allocation is made by the R runtime. The returned value may need to call its Protect method.

func (*String) Len

func (v *String) Len() int

Len returns the number of elements in the vector.

func (*String) Protect

func (v *String) Protect() *String

Protect protects the SEXP value and returns it.

func (*String) Unprotect

func (v *String) Unprotect()

Unprotect unprotects the SEXP. It is equivalent to UNPROTECT(1).

func (*String) Value

func (v *String) Value() *Value

Value returns the generic state of the SEXP value.

func (*String) Vector

func (v *String) Vector() []*Character

Vector returns a slice corresponding to the R vector.

type Symbol

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

Symbol is an R name value.

func (*Symbol) Internal

func (v *Symbol) Internal() *Value

Internal returns a pointer if the symbol is a .Internal function.

func (*Symbol) Name

func (v *Symbol) Name() *Character

Name returns the name of the symbol

func (*Symbol) String

func (v *Symbol) String() string

String returns a Go string of the symbol name. The returned string is allocated by the Go runtime.

func (*Symbol) SymbolValue

func (v *Symbol) SymbolValue() *Value

Value returns the value of the symbol.

func (*Symbol) Value

func (v *Symbol) Value() *Value

Value returns the generic state of the SEXP value.

type Type

type Type byte

Type is the SEXPTYPE enum defined in Rinternals.h.

const (
	NILSXP     Type = 0x0
	SYMSXP     Type = 0x1
	LISTSXP    Type = 0x2
	CLOSXP     Type = 0x3
	ENVSXP     Type = 0x4
	PROMSXP    Type = 0x5
	LANGSXP    Type = 0x6
	SPECIALSXP Type = 0x7
	BUILTINSXP Type = 0x8
	CHARSXP    Type = 0x9
	LGLSXP     Type = 0xa
	INTSXP     Type = 0xd
	REALSXP    Type = 0xe
	CPLXSXP    Type = 0xf
	STRSXP     Type = 0x10
	DOTSXP     Type = 0x11
	ANYSXP     Type = 0x12
	VECSXP     Type = 0x13
	EXPRSXP    Type = 0x14
	BCODESXP   Type = 0x15
	EXTPTRSXP  Type = 0x16
	WEAKREFSXP Type = 0x17
	RAWSXP     Type = 0x18
	S4SXP      Type = 0x19
	NEWSXP     Type = 0x1e
	FREESXP    Type = 0x1f
	FUNSXP     Type = 0x63
)

func (Type) String

func (i Type) String() string

type Value

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

Value is an SEXP value.

var (
	// NilValue is the R_NilValue as a *Value type. It must not be altered.
	NilValue *Value = asValue(C.R_NilValue)

	// UnboundValue is the R_UnboundValue as a *Value type. It must not be altered.
	UnboundValue *Value = asValue(C.R_UnboundValue)
)

func (*Value) Attributes

func (v *Value) Attributes() *List

Attributes returns the attributes of the SEXP value.

func (*Value) Export

func (v *Value) Export() unsafe.Pointer

Export returns an unsafe pointer to the SEXP value first converting a nil value to the R NilValue.

func (*Value) Info

func (v *Value) Info() Info

Info returns the information field of the SEXP value.

func (*Value) IsNull

func (v *Value) IsNull() bool

IsNull returned whether the Value is the R NULL value.

func (*Value) Names

func (v *Value) Names() *String

Names returns the names of the Value.

func (*Value) Pointer

func (v *Value) Pointer() unsafe.Pointer

Pointer returns an unsafe pointer to the SEXP value.

func (*Value) SetAttribute

func (v *Value) SetAttribute(name []byte, attr *Value)

SetAttribute sets the given attribute of the SEXP value to attr.

func (*Value) SetNames

func (v *Value) SetNames(names *String)

SetAttribute sets the names attribute of the SEXP value to names.

func (*Value) Value

func (v *Value) Value() *Value

Value returns the generic state of the SEXP value.

func (*Value) Valuer

func (v *Value) Valuer() Valuer

Valuer returns a Go value corresponding to the SEXP type specified in the SEXP info field. If the receiver is nil, the R NilValue will be returned.

type Valuer

type Valuer interface {
	Value() *Value
}

Valuer is the general data type interchange interface. All SEXP types satisfy the Valuer interface.

type Vector

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

Vector is a generic R vector.

func NewVector

func NewVector(n int) *Vector

NewVector returns a generic vector with length n.

The allocation is made by the R runtime. The returned value may need to call its Protect method.

func (*Vector) Len

func (v *Vector) Len() int

Len returns the number of elements in the vector.

func (*Vector) Protect

func (v *Vector) Protect() *Vector

Protect protects the SEXP value and returns it.

func (*Vector) Unprotect

func (v *Vector) Unprotect()

Unprotect unprotects the SEXP. It is equivalent to UNPROTECT(1).

func (*Vector) Value

func (v *Vector) Value() *Value

Value returns the generic state of the SEXP value.

func (*Vector) Vector

func (v *Vector) Vector() []*Value

Vector returns a slice corresponding to the R vector.

type WeakReference

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

WeakReference is an R weak reference.

func (*WeakReference) Len

func (v *WeakReference) Len() int

Len returns the number of elements in the vector.

func (*WeakReference) Value

func (v *WeakReference) Value() *Value

Value returns the generic state of the SEXP value.

func (*WeakReference) Vector

func (v *WeakReference) Vector() []*Value

Vector returns the four elements of an R weak reference.

Notes

Bugs

  • Currently the API does not provide the capacity to create all SEXP types.

Jump to

Keyboard shortcuts

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