コード例 #1
0
        public async Task List()
        {
            await _session.ExecuteAsync("x <- c(1:10)");

            var ol = await _session.GetListAsync <int>("x");

            ol.Count.Should().Be(10);
            ol.Should().ContainInOrder(new int[] { 1, 2, 3, 4, 5, 6, 7, 9, 10 });
        }
コード例 #2
0
ファイル: RHostApiTestForm.cs プロジェクト: dlastor/RTVS-cs
        private async void getListButton_Click(object sender, EventArgs e)
        {
            try {
                await _sessionStartTask;
                var   list = await _session.GetListAsync(codeBox.Text);

                DisplayResult(list);
            } catch (Exception ex) {
                DisplayResult(ex.Message);
            }
        }
コード例 #3
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();
        }
コード例 #4
0
ファイル: ROperations.cs プロジェクト: gbull122/vscode-r
 public async Task <List <object> > GetListAsync(string command)
 {
     return(await rHostSession.GetListAsync(command));
 }