コード例 #1
0
        /// <summary>
        /// 设置R语言的工作目录
        /// </summary>
        public static void SetWd(this REngine engine, Func <string> wdPath = null)
        {
            var path     = wdPath != null ? (wdPath() ?? string.Empty) : AppDomain.CurrentDomain.BaseDirectory;
            var pathchar = engine.CreateCharacter(path);

            engine.ExecFunction(pathchar, "setwd");
        }
コード例 #2
0
        static void Main(string[] args)
        {
            REngine.SetEnvironmentVariables();
            // There are several options to initialize the engine, but by default the following suffice:
            REngine engine = REngine.GetInstance();

            //engine.Birth_of_age();

            //engine.Age_title_colours();

            //engine.Barchart();
            //engine.barchart_months_revenue();
            //engine.Barchart_stacked();

            engine.SetWd();
            engine.GetWd();
            //engine.Print("开始安装exec组件");
            //engine.Evaluate("install.packages('xlsx')");
            //engine.Print("结束安装exec组件");


            engine.Print("读取文件开始");

            //var csvName = engine.ReadCsv("InputName.csv");

            //var param = new SymbolicExpressionParamList() { IsUseParamName = false };
            //param.Add(new SymbolicExpressionParam(csvName));
            //param.Add(new SymbolicExpressionParam(where: " as.Date(start_date) > as.Date('2014-01-01') "));
            ////param.Add(new SymbolicExpressionParam(where: "salary>600&dept=='IT'"));
            //var subset = engine.ExecFunction(param, "subset");

            //var paramA = new SymbolicExpressionParamList() { IsUseParamName = false };
            //paramA.Add(new SymbolicExpressionParam(subset.AsDataFrame()));
            //paramA.Add(new SymbolicExpressionParam(where: "'output1.csv'"));
            //paramA.Add(new SymbolicExpressionParam(where: "row.names = FALSE"));
            //engine.ExecFunction(paramA, "write.csv");
            //engine.ReadCsv("output1.csv");

            engine.Evaluate("library(xlsx) ");
            var paramA = new SymbolicExpressionParamList()
            {
                IsUseParamName = false
            };

            paramA.Add(new SymbolicExpressionParam(where : "'input.xlsx'"));
            paramA.Add(new SymbolicExpressionParam(engine.CreateNumeric(1), paramName: "sheetIndex"));
            engine.ExecFunction(paramA, "read.xlsx");
            //engine.ReadCsv("output1.csv");

            engine.Print("读取文件结束");

            engine.Dispose();

            Console.ReadKey();
        }
コード例 #3
0
        /// <summary>
        /// 传入函数名称就可以执行函数
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="symbolicExpression"></param>
        /// <param name="functionName"></param>
        /// <returns></returns>
        public static SymbolicExpression ExecFunction(this REngine engine, SymbolicExpression symbolicExpression, string functionName)
        {
            var expressionPar = new SymbolicExpressionParamList()
            {
                IsUseParamName = false,
            };
            var param = new SymbolicExpressionParam(symbolicExpression, "");

            expressionPar.Add(param);
            return(engine.ExecFunction(expressionPar, functionName));
        }
コード例 #4
0
 public static void NRow(this REngine engine, SymbolicExpression symbolicExpression)
 {
     engine.ExecFunction(symbolicExpression, "nrow");
 }
コード例 #5
0
 public static void NCol(this REngine engine, SymbolicExpression symbolicExpression)
 {
     engine.ExecFunction(symbolicExpression, "ncol");
 }
コード例 #6
0
 /// <summary>
 /// 打印结果信息
 /// </summary>
 public static void Print(this REngine engine, SymbolicExpression symbolicExpression)
 {
     engine.ExecFunction(symbolicExpression, "print");
 }
コード例 #7
0
        /// <summary>
        /// 读取Csv文件
        /// </summary>
        public static SymbolicExpression ReadCsv(this REngine engine, string csvFileName)
        {
            var csvName = engine.CreateCharacter(csvFileName);

            return(engine.ExecFunction(csvName, "read.csv"));
        }