main.go 526 B

1234567891011121314151617181920212223242526272829303132333435
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/nchern/go-R/R"
  5. )
  6. func eval(expression string) *R.Result {
  7. r := R.EvalOrDie(expression)
  8. fmt.Println(expression, "=", r.AsNumeric().Get(0))
  9. return r
  10. }
  11. func test() {
  12. eval("1+3*4")
  13. R.EvalOrDie("library(stats)")
  14. x := R.NewNumericVector([]float64{11.0, 2.0, 31.0, 14.0, 51.0, 16.0, 7.0, 28.0})
  15. fmt.Println("x: ", x.ToArray())
  16. p := R.Protect(x.ToSexp())
  17. defer p.Unprotect()
  18. R.SetSymbol("x", x)
  19. eval("sum(x)")
  20. }
  21. func main() {
  22. fmt.Println("R.init: ", R.Init())
  23. test()
  24. }