Example #1
0
        /// <summary>
        /// executes R script - returns result
        /// </summary>
        /// <param name="strRScript"></param>
        /// <returns></returns>
        public Object ExecuteRScript(string strRScript)
        {
            try
            {
                m_strError = null;

                if (m_rServer == null)
                {
                    throw new Exception("R-Client is not initialized.");
                }

                Object result = null;

                try
                {
                    result = m_rServer.Evaluate(strRScript);
                }
                catch
                {
                    throw new Exception(this.Error);
                }

                return(result);
            }
            catch (Exception exception)
            {
                throw new Exception("Exception in CRClient::ExecuteRScriptNoResult()", exception);
            }
        }
Example #2
0
        private void btcargarObjeto_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Text file (*.txt)|*.txt";
            if ((openFileDialog1.ShowDialog() == DialogResult.Cancel))
            {
                return;
            }

            string fileName   = openFileDialog1.FileName.Replace(@"\", "/");
            string objectName = System.IO.Path.GetFileNameWithoutExtension(openFileDialog1.FileName);

            //añade el nuevo objeto a la TOC o si ya existía, lo sobreescribe
            if (TOC.ContainsKey(objectName))
            {
                TOC.Remove(objectName);
            }
            else
            {
                TOC.Add(objectName, fileName);
            }


            //creamos un nuevo dataframe en R
            string leerFichero = objectName + "<-read.table('" + fileName + "',header=T)";

            sc1.Evaluate(leerFichero);

            //listamos todos los objetos menos los creados para consultar información en R.
            sc1.Evaluate("dir <-ls()");
            string[] dir = (string[])sc1.GetSymbol("dir");

            lstObjetos.Items.Clear();

            for (int i = 0; i < dir.Length; i++)
            {
                if (dir[i] != "wd" & dir[i] != "dir" & dir[i] != "campos" & dir[i] != "filasNombre" & dir[i] != "camposNombre" & dir[i] != "campoValores")
                {
                    lstObjetos.Items.Add(dir[i]);
                }
            }
        }
        public void essai()
        {
            object        o1;
            int           n   = 20;
            StatConnector sc1 = new StatConnector();

            sc1.Init("R");
            sc1.SetSymbol("n1", n);
            sc1.Evaluate("x1<-rnorm(n1)");
            o1 = sc1.GetSymbol("x1");
            double Xrnd = (double)o1;

            MessageBox.Show(Xrnd.ToString());
        }