示例#1
0
        static void Main(string[] args)
        {
            // Init R session
            IRHostSession session          = RHostSession.Create("Test");
            Task          sessionStartTask = session.StartHostAsync(new RHostSessionCallback());

            sessionStartTask.Wait();

            // Simple output from console
            Console.WriteLine("Arbitrary R code:");
            var result = session.ExecuteAndOutputAsync("Sys.info()");

            result.Wait();
            Console.WriteLine(result.Result.Output);

            // Create R DataFrame
            List <string> colNames = new List <string>(new string[] { "c1", "c2" });
            List <string> rowNames = new List <string>(new string[] { "1", "2", "3", "10" });

            var xx   = new object[] { new object[] { 1, 3, 43, 54 }, new object[] { "a", "c", "a", "d" } };
            var list = new List <IReadOnlyCollection <object> >();

            foreach (object o in xx)
            {
                list.Add(o as object[]);
            }

            DataFrame df  = new DataFrame(rowNames, colNames, list.AsReadOnly());
            var       dtc = session.CreateDataFrameAsync("data", df);

            dtc.Wait();

            // Print data frame in R session
            result = session.ExecuteAndOutputAsync("print(data)");
            result.Wait();
            Console.WriteLine("\nR data frame:");
            Console.WriteLine(result.Result.Output);

            var resultList = session.GetListAsync("list(mean(data$c1), 111)");

            Console.WriteLine("\nList elements returned from R to C#:");
            Console.WriteLine(Convert.ToDouble(resultList.Result[0]) * 100);
            Console.WriteLine(resultList.Result[1]);

            session.StopHostAsync();
            Console.ReadLine();
        }
示例#2
0
 public async Task StartHostAsync(IRHostSessionCallback rHostSessionCallback)
 {
     await rHostSession.StartHostAsync(rHostSessionCallback);
 }
示例#3
0
 public async Task InitializeAsync()
 {
     await _session.StartHostAsync(_callback);
 }
示例#4
0
 private void CreateHostSession()
 {
     _session          = RHostSession.Create("Test");
     _sessionStartTask = _session.StartHostAsync(new RHostSessionCallback());
 }
 public RHostClientCaller(string scriptPath)
 {
     this.scriptPath = scriptPath;
     session         = RHostSession.Create("Test");
     task            = session.StartHostAsync(new RHostSessionCallback());
 }