Quantcast
Channel: R.NET
Viewing all 1634 articles
Browse latest View live

New Post: How to release a standalone R.net exe

$
0
0
No, the problem is R is platform/version specific, while R.NET (and all C# code) are compiled when they run on the machine. Because C# is compiled to machine code only when run, c# exe/dll files can be copied anywhere and run (provided .NET is installed to run it wherever it lands).

R however is already compiled to machine code, If you are only deploying on the same OS and architecture, you might get away with copying a single file, but this will likely not work after some time and generally be a headache.

The R install process is pretty clean for any machine. I would just change your program to prompt the user to install R and direct them to the website.

Again, it is theoretically possible to link R/.NET/RDOTNET into one file, but exceptionally hard. I would just prompt for an R install.

New Post: Problem doing Linear Regression

$
0
0
Hello, I'm new to this library. I'm having problem making a very simple linear regression and getting its coefficients. My code is this:
        double[] subidas = { 3.2, 6.4, 5.1 };
        double[] bajadas = { 1.5, 3.1, 2.5 };
        REngine.SetEnvironmentVariables();
        REngine engine = REngine.GetInstance();
        NumericVector ups = engine.CreateNumericVector(subidas);
        NumericVector downs = engine.CreateNumericVector(bajadas);
        NumericVector coeff = engine.Evaluate("coefficients(lm(ups ~ downs))").AsNumeric(); 
And is throwing me the following error:

"Error in eval(expr, envir, enclos) : object 'ups' not found"

Please help, thanks in advance!

New Post: Problem doing Linear Regression

$
0
0
'ups` as created is a C# variable but is not a named variable in R. To set it in R, try this:
     engine.SetSymbol("ups", ups);
 engine.SetSymbol("downs", downs);
That should set the variable in R to have the symbol "ups" point to the data in ups.

New Post: Problem doing Linear Regression

$
0
0
I tried it and now it's working, thanks!

New Post: Error: could not find function "t.test"

$
0
0
Hi, I was trying to implement R.NET for the first time, followed every step as instructed, and tested the code below:

"
        REngine.SetEnvironmentVariables();
        REngine engine = REngine.GetInstance();
        // REngine requires explicit initialization.
        // You can set some parameters.
        engine.Initialize();

        // .NET Framework array to R vector.
        NumericVector group1 = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 });
        engine.SetSymbol("group1", group1);
        // Direct parsing from R script.
        NumericVector group2 = engine.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric();

        // Test difference of mean and get the P-value.
        GenericVector testResult = engine.Evaluate("t.test(group1, group2)").AsList();
        double p = testResult["p.value"].AsNumeric().First();

        Textbox1.Text = "Group1: [{0}]" + string.Join(", ", group1);
        Textbox2.Text = "Group2: [{0}]" + string.Join(", ", group2);
        Textbox3.Text = "P-value = {0:0.000}"+  p;

        // you should always dispose of the REngine properly.
        // After disposing of the engine, you cannot reinitialize nor reuse it
        engine.Dispose();
"

The system threw me an "Error: could not find function "t.test""

Anyone might know how to resolve this?

Thanks!

New Post: Error: could not find function "t.test"

$
0
0
Hmm strange, could you do me a favor and add this to the top?
engine.Evalutate("library(stats)")
you also likely need to add:
engine.SetSymbol("group2", group2);
In there as well.

New Post: Error: could not find function "t.test"

$
0
0
Thanks for your reply!

I tried your suggestion and here's what it returned
Error: package or namespace load failed for 'stats'
For reference, here's my namespace setup:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RDotNet;

I was using R 3.2.1 and Visual Studio 2012

Thanks so much!

New Post: Error: could not find function "t.test"

$
0
0
Hmm.... this to me suggests something is wrong with your R package loading. Before checking how it is loaded by .NET, best to check it works out in R okay.

Try the following, on the computer just open R normally and try the same set of commands:
group1 <- c(30.02, 29.99, 30.11, 29.97, 30.01, 29.99)
group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)
t.test(group1, group2)
Also, I just realized the SetSymbol command I mentioned earlier was actually unneccesary.

New Post: Error: could not find function "t.test"

$
0
0
Hi, thanks for the prompt reply!

I've tried the test in R and it showed no problem.

Could it be problems related to PATH and R_HOME?

I also tried omitting the t.test and directly displaying both group1 and group2 in textboxes, and it seems to be working fine, so it shouldn't be a connection problem I assume?

New Post: Error: could not find function "t.test"

$
0
0
Can you try posting the output from this command when executed directly in R and from .NET?


".libPaths()"

New Post: Error: could not find function "t.test"

$
0
0
Both were displaying
"C:/Program Files/R/R-3.2.1/library"


New Post: Error: could not find function "t.test"

$
0
0
Hi, evolvedmicrobe and everyone,

I think I've solved the problem (at least for now). I copied everything under "C:\Program Files\R\R-3.2.1\bin\i386" to "C:\Program Files\R\R-3.2.1\library\stats\libs\i386". Right now I can retrieve the p value from the t.test and I'll test it further. If there are no updates from me then everything is good!

Thanks for being so patient, evolvedmicrobe!

Hopefully this will help others, I do see a couple people have the same problem but remained unanswered

New Post: Import Data from a file or MySql

$
0
0
Hi all,

I am trying to develop an application which will forecast prices of agricultural products.

I have made the connection between C# and MySql. (Actually i can load data from MySql and save them in a listbox)
I also have made the connection between C# and R through R.NET

but now, in order to perform some statistical analysis and charts i need your help to create a Chart by loading the two values from the listbox OR direct from my database.
The two values are Date,AnnualPrice in my db table.
string constring = "datasource=localhost;port=3306;username=root;password=;";//connect to server
            MySqlConnection conDataBase = new MySqlConnection(constring);
            MySqlCommand cmdDataBase = new MySqlCommand("Select Date,AnnualPrice from db_og.historicprices;", conDataBase);

try
            {
                conDataBase.Open();
                MySqlDataReader myReader = cmdDataBase.ExecuteReader();
                while (myReader.Read())
                {
                   
                    DataPrices DataPrice = new DataPrices();

                   

                    ListViewItem item = new ListViewItem(myReader["Date"].ToString());
                    item.SubItems.Add(myReader["AnnualPrice"].ToString());

                    listView1.Items.Add(item);
                    engine.SetSymbol("plot1", listView1);
                    engine.Evaluate("plot(item$Date, item$AnnualPrice)");
                }//end while   

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);

            }
            

New Post: How to plot a listbox or an arrylist?

$
0
0
Hi R.NET community,

i have been straggling for days in this part and you are my last chance

i have the following listbox which is loading from MySql. Date is DateTime value and Price is double

Date Price
12/9/1990 15.30
12/9/1990 15.30
12/9/1990 15.30
12/9/1990 15.30
 var date = String.Format("{0,20}", myReader["Date"].ToString());
 var AnnualPrice = String.Format("{0,20}", myReader["AnnualPrice"].ToString());

                ListViewItem item = new ListViewItem(date + "," + AnnualPrice);
i have created my own Plot method RPlot
     public void RPlot(string var1, string Var2)
        {
            REngine.SetEnvironmentVariables();
            REngine engine = REngine.GetInstance();
            // REngine requires explicit initialization.
            // You can set some parameters.
            engine.Initialize();
            
            String RCommand = "plot(" + var1 + "," + Var2 + ")";
            engine.Evaluate(RCommand.ToString());
        }
but every time that i use it returns me this message 'R_ParseErrorMsg' in the file 'R.dll'

I also have tried the following
ArrayList DataAnnualPrice = new ArrayList();
            try
            {
                conDataBase.Open();
                MySqlDataReader myReader = cmdDataBase.ExecuteReader();
                while (myReader.Read())
                {
                    //MessageBox.Show(""+myReader.GetFieldType(0));
                    //MessageBox.Show("" + myReader.GetFieldType(1));
                    DataPrices DataPrice = new DataPrices();

                    DataPrice.Date = (DateTime)myReader["Date"];
                    DataPrice.AnnualPrice = (double)myReader["AnnualPrice"];
                    int date1 = Convert.ToInt32(DataPrice);
                    int price1 = Convert.ToInt32(DataPrice.AnnualPrice);
                    DataAnnualPrice.Add(DataPrice);

//i got the following code from stackoverflow and tried to modify 
                    var v1 = engine.CreateNumericVector(date1); //Initially compiler hits here
                    var v2 = engine.CreateNumericVector(price);
                    engine.SetSymbol("v1", v1);
                    engine.SetSymbol("v2", v2);
                    engine.Evaluate("require('ggplot2')");
                    engine.Evaluate("library('ggplot2')");
                    engine.Evaluate("my_data <- data.frame(v1)");
                    engine.Evaluate("myChart <- ggplot(my_data, aes(x=Price, y=Quantity)) + geom_line()");
                    engine.Evaluate("print(myChart)");
Could you please give me a help to go one step forward?

Thanks

New Post: Error Message : Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

$
0
0
Same here, when I call Rengine multiple times it will frequently throw this type of error “Attempted to read or write protected memory. This is often an indication that other memory is corrupt”, any here will be appreciated

New Post: Import Data from a file or MySql

$
0
0
You must convert your data in C# from arrays to simpler array formats; R.NET cannot magically figure out what a ListView of other very specific constructs. Even arrays of DateTime have pitfalls and ambiguities preventing reliable conversion all the time (calendars; time zones, daylight savings, and so on)

To give an example, based on what your data seems to be:
int[] daysSinceStart;
double[] values;
int startyear, startmonth, startday;


engine.SetSymbol("startyear" , engine.CreateIntegerVector(new[]{startyear } ));
engine.SetSymbol("startmonth", engine.CreateIntegerVector(new[]{startmonth} ));
engine.SetSymbol("startday"  , engine.CreateIntegerVector(new[]{startday  } ));
engine.SetSymbol("daysSinceOrigin", engine.CreateIntegerVector(daysSinceStart));
engine.SetSymbol("dvalues", engine.CreateNumericVector(values));

engine.Evaluate(@"origin <- ISOdate(startYear, startMonth, startDay, tz='UTC')
library(lubridate)
myDates <- origin + days(daysSinceOrigin)
# something that builds a time series, e.g. x <- xts(...)
");
engine.Evaluate("plot.zoo(x)");

New Post: Import Data from a file or MySql

$
0
0
Hi may i ask you a question

my data are type DateTime and double

Date Price
112/9/1990 15.30
12/9/1990 15.30
12/9/1990 15.30
12/9/1990 15.30

what if i save them in a 2D ArrayList
ArrayList DataAnnualPrice = new ArrayList();
then Create a Nummeric Matrix
var v = engine.CreateNumericMatrix(DataAnnualPrice );
ngine.SetSymbol("v",  v );
engine.Evaluate("require('ggplot2')");
    engine.Evaluate("library('ggplot2')");
    engine.Evaluate("my_data <- data.frame(v)");
engine.Evaluate("myChart <- ggplot(my_data, aes(x=Price, y=Date));
        engine.Evaluate("print(myChart)");

New Post: Saving and Loading a Model

$
0
0
Hi, I'm relatively new to R.Net, so any help would be greatly appreciated. I'm generating a Generalized Linear Regression (Poisson), with some data (from now on DataBase). What I want to do, is to store this model somewhere, then load it and use to predict an output for another data (from now on PredictBase). This is what I currently have:
            REngine.SetEnvironmentVariables();
            REngine engine = REngine.GetInstance();
            DataFrame testData = engine.Evaluate("testData<-read.table('C:/Users/Felipe/Desktop/rfile.txt',header=TRUE)").AsDataFrame(); ----> From there I'm loading the DataBase
            engine.SetSymbol("modelexpression",engine.CreateCharacter(modelstring)); ---> modelstring is a string containing the expression for the glm
            engine.SetSymbol("testData", testData);
            NumericVector coeff = engine.Evaluate("coefficients(glm(modelexpression,family=poisson(link=log)))").AsNumeric();
This is currently working, and coeff gives me the coefficients for each independent variable.

From there I'm stuck with how to store a model (maybe to a txt file?) and then load it for new data in order to predict its output. Thanks in advance,

Felipe moya

New Post: Error Message : Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

$
0
0
Ok, I may have found a solution to this. First I added in GC.Collect() in C# to force collect garbage. Then I set a timeout of about 1 second between each loop to let the system fully build up the connection between R and Asp.net. The error never appeared again. Now I'm not sure of the underlying mechanism, but this seems to work fine for me for now.

New Post: How can i load a package like forecast?

$
0
0
Hi there,

I am trying to use engine.Evaluate("install.packages('forecast', .Library)");
 engine.Evaluate("dataset = read.table(file.choose(),skip=1)");
engine.Evaluate("install.packages('forecast', .Library)");
engine.Evaluate("z1 <- ts(dataset,frequency = 15, start=c(2010,11))"); 
                    engine.Evaluate("forecastA <- HoltWinters(z1)");
                    engine.Evaluate("forecast2 <- forecast.HoltWinters(z1,h=6)");
                    engine.Evaluate("plot(forecastA)");
                    engine.Evaluate("plot.forecast(forecast2)");
but it says Error in install.packages("forecast", .Library) :
unable to install packages

How can i install ? Can anyone help me?
Viewing all 1634 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>