Could able to load package TTR for SMA function - Parce Exception Error

Nov 16, 2012 at 9:42 AM

I am working on the following vb.net program, I getting ParceExcetion on the following line

            engine.EagerEvaluate("dssma <- SMA(ds,3)")

Complete program:

Imports SystemImports System.Collections.GenericImports System.ComponentModelImports System.DataImports System.DrawingImports System.LinqImports System.TextImports System.Windows.FormsImports RDotNet
Public Class Form1
    Public Sub main()        InitializeComponent()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        REngine.SetDllDirectory("C:\Rtool\R-2.15.1\bin\i386")
        Dim engine As REngine = REngine.CreateInstance("RDotNet")
        Try
            engine.EagerEvaluate("C:/Rtool/R-2.15.1/library")
            engine.EagerEvaluate("dataset<- read.csv(" & """D:/books/R/Wfjsales.txt""" & ")")
            Dim dataset As DataFrame = engine.GetSymbol("dataset").AsDataFrame()
            engine.EagerEvaluate(".libPaths(\" & """ C:\Rtool\R\R-2.15.1\library\""" & ")")
            engine.Evaluate("library(zoo)")
            engine.Evaluate("library(xts)")
            engine.Evaluate("library(TTR)")
            engine.EagerEvaluate("ds <- dataset[3]")
            Dim ds As DataFrame = engine.GetSymbol("dataset").AsDataFrame()
            engine.EagerEvaluate("dssma <- SMA(ds,3)")
            Dim dssma As DataFrame = engine.GetSymbol("dssma").AsDataFrame()
            engine.Close()
        Catch ex As Exception
            engine.Close()            MsgBox(ex.StackTrace)
        End Try
    End Sub
End Class

Nov 27, 2012 at 6:57 AM

Hello friends

I found the solution. there was some concatenation issue with VB and the Path issue was also a problem.

I have enclosed the correct code below.

 


Imports SystemImports System.Collections.GenericImports System.ComponentModelImports System.DataImports System.DrawingImports System.LinqImports System.TextImports System.Windows.FormsImports RDotNet
Public Class Form1
    Public Sub main()        InitializeComponent()        System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("R_HOME") & "\bin")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            REngine.SetDllDirectory("C:\R\R-2.15.1\bin\i386")
            Dim engine As REngine = REngine.CreateInstance("RDotNet")
            engine.EagerEvaluate("C:/R/R-2.15.1/library")
            engine.EagerEvaluate(".libPaths(\" & """ C:\R\R-2.15.1\library\""" & ")")
            engine.EagerEvaluate("library(RODBC)")
            engine.EagerEvaluate("cn <- odbcDriverConnect('driver={SQL Server};server=ARUNK\\SQLEXPRESS;database=Planvisage4_0_2;trusted_connection=true')")
            engine.EagerEvaluate("sql<-""Select Sales from ExpSales""")
            engine.EagerEvaluate("rs <- sqlQuery(cn,sql)")
            engine.EagerEvaluate("library(zoo)")
            engine.EagerEvaluate("library(xts)")
            engine.EagerEvaluate("library(TTR)")
            engine.EagerEvaluate("dsma <- SMA(rs,7)")
            engine.EagerEvaluate("df = data.frame(Value=dsma)")
            Dim dsma As DataFrame = engine.EagerEvaluate("dsma").AsDataFrame()
            engine.EagerEvaluate("sqlDrop(cn,""SmaSales"")")
            engine.EagerEvaluate("sqlSave(cn,df,""SmaSales"")")
            engine.EagerEvaluate("odbcClose(cn)")
            engine.Close()
        Catch ex As Exception
        End Try
            End Sub
End Class