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

Commented Unassigned: R.NET Dataframe not handling POSIXlt properly [178]

$
0
0
Hi
One of my R dataframe column is of type "POSIXlt".
I am loading this R dataframe in R.NET's Dataframe object like following :

In R (instance created using R.NET):
----------------------------------------
mydataset = # some R dataframe that has, say fourth column of type POSIXlt. And there are more than 11 rows in the dataframe.

In C#
------
DataFrame DF = engine.GetSymbol("mydataset").AsDataFrame();

Now, when I try to access value of the row index greater than 11 and col index (that is of type POSIXlt), I get ArgumentOutOfRangeException ( as if that particular index doesn't exists ).

//now if I try to access 4th column of row index greater than 11, I get exeception
object data = DF[12,4];


Thanks,

Comments: Hi Skyguy94, Please find attached C# project example. The sample is self explanatory. There are comments in source code too. In 'bin\Debug' folder of this project there is a 'testdate.csv' file that I am trying to read. This file should be automatically picked but in case there is an issue then modify the path in source code to locate this CSV file. I am using R.NET version 1.5.16.30632 Hope, I am not missing anything here. Regards, adabral

New Post: Different results while running a script in R and in C# with R.NET

$
0
0
You'll have to reformulate a bit your question to get readers to assess they can help. These guidelines may help.

If you can craft a small, reproducible example (code and data) displaying the behavior, you can post it here, or open an issue if there is indeed a reasonable diagnosis of a bug.

Commented Unassigned: REngine.GetInstance fails [177]

$
0
0
Hi, I'm new to R but really would love to use it in my C# programs via RDotNet. I've added R.net via Manage NuGet Packages in VS2013 (RDotNet runtime Version v4.0.30319).

Within Windows 7 I'm running R-3.2.2 and both 32bit and 64bit reside within my C:\Program Files\R\R-3.2.2\bin folder.

Here's the beginning of my code.

using System.IO;
using System.Linq;
using RDotNet;
using RDotNet.NativeLibrary;

namespace RNetTest
{
class Program
{
static void Main(string[] args)
{
// Set the R_HOME environment variable in which R.dll is located.
Environment.SetEnvironmentVariable("R_HOME", @"C:\Program Files\R\R-3.2.2\bin\i386");

REngine engine = REngine.GetInstance("RDotNet");

It fails on the GetInstance with the error:

An unhandled exception of type 'System.ArgumentException' occurred in DynamicInterop.dll

Additional information: Could not retrieve a pointer for the symbol 'R_CStackLimit' in file 'RDotNet'

If I run REngine.GetInstance(); like is suggested I get the following error:

An unhandled exception of type 'System.Exception' occurred in DynamicInterop.dll

Additional information: This 32-bit process failed to load the library R.dll. Native error message is 'The system cannot find the file specified'

I've been wrestling with this for many hours now and finally asking for some help on what a solution might be. It should be noted the error is the same for 32bit or 64bit R.dll versions.


Comments: R_HOME, if set programmatically or as an environment variable, should not point to where R.dll is, but to (for instance) C:\Program Files\R\R-3.2.2, which contains the sub folders bin, library, etc. You can look at [this page](http://jmp75.github.io/rdotnet/ts_paths_on_windows/) in the new location for the R.NET documentation to help diagnose path issues. If you can report what the utility program reports, this would greatly help us help you.

Commented Unassigned: R.NET Dataframe not handling POSIXlt properly [178]

$
0
0
Hi
One of my R dataframe column is of type "POSIXlt".
I am loading this R dataframe in R.NET's Dataframe object like following :

In R (instance created using R.NET):
----------------------------------------
mydataset = # some R dataframe that has, say fourth column of type POSIXlt. And there are more than 11 rows in the dataframe.

In C#
------
DataFrame DF = engine.GetSymbol("mydataset").AsDataFrame();

Now, when I try to access value of the row index greater than 11 and col index (that is of type POSIXlt), I get ArgumentOutOfRangeException ( as if that particular index doesn't exists ).

//now if I try to access 4th column of row index greater than 11, I get exeception
object data = DF[12,4];


Thanks,

Comments: I recommend you work around this by converting your POSIXlt to POSIXct in R before you access it from R.NET. Nothing wrong with using POSIXlt, but indeed R.NET _probably_ does not handle this yet out of the box. This is indeed a valid feature request.

Commented Unassigned: R.NET Dataframe not handling POSIXlt properly [178]

$
0
0
Hi
One of my R dataframe column is of type "POSIXlt".
I am loading this R dataframe in R.NET's Dataframe object like following :

In R (instance created using R.NET):
----------------------------------------
mydataset = # some R dataframe that has, say fourth column of type POSIXlt. And there are more than 11 rows in the dataframe.

In C#
------
DataFrame DF = engine.GetSymbol("mydataset").AsDataFrame();

Now, when I try to access value of the row index greater than 11 and col index (that is of type POSIXlt), I get ArgumentOutOfRangeException ( as if that particular index doesn't exists ).

//now if I try to access 4th column of row index greater than 11, I get exeception
object data = DF[12,4];


Thanks,

Comments: Side note; you should preferably upgrade to the latest R.NET (R.NET.Community) on nuget.

Commented Unassigned: R.NET Dataframe not handling POSIXlt properly [178]

$
0
0
Hi
One of my R dataframe column is of type "POSIXlt".
I am loading this R dataframe in R.NET's Dataframe object like following :

In R (instance created using R.NET):
----------------------------------------
mydataset = # some R dataframe that has, say fourth column of type POSIXlt. And there are more than 11 rows in the dataframe.

In C#
------
DataFrame DF = engine.GetSymbol("mydataset").AsDataFrame();

Now, when I try to access value of the row index greater than 11 and col index (that is of type POSIXlt), I get ArgumentOutOfRangeException ( as if that particular index doesn't exists ).

//now if I try to access 4th column of row index greater than 11, I get exeception
object data = DF[12,4];


Thanks,

Comments: Hi jperraud, Thanks for the workaround. I tried POSIXct in the past and found it working. So, workaround should also work. My requirement was to directly deal with POSIXlt but for now I think I have to handle this differently. By the way, I tried one version higher than the version I am using (R.NET version 1.5.16.30632 ) and found some performance issue while loading the dataset. I am not 100% sure, it was long time back. So decided to stick to the older version. I will give it a one more try when I have enough time. Thanks & Regards, adabral

Commented Unassigned: REngine.GetInstance fails [177]

$
0
0
Hi, I'm new to R but really would love to use it in my C# programs via RDotNet. I've added R.net via Manage NuGet Packages in VS2013 (RDotNet runtime Version v4.0.30319).

Within Windows 7 I'm running R-3.2.2 and both 32bit and 64bit reside within my C:\Program Files\R\R-3.2.2\bin folder.

Here's the beginning of my code.

using System.IO;
using System.Linq;
using RDotNet;
using RDotNet.NativeLibrary;

namespace RNetTest
{
class Program
{
static void Main(string[] args)
{
// Set the R_HOME environment variable in which R.dll is located.
Environment.SetEnvironmentVariable("R_HOME", @"C:\Program Files\R\R-3.2.2\bin\i386");

REngine engine = REngine.GetInstance("RDotNet");

It fails on the GetInstance with the error:

An unhandled exception of type 'System.ArgumentException' occurred in DynamicInterop.dll

Additional information: Could not retrieve a pointer for the symbol 'R_CStackLimit' in file 'RDotNet'

If I run REngine.GetInstance(); like is suggested I get the following error:

An unhandled exception of type 'System.Exception' occurred in DynamicInterop.dll

Additional information: This 32-bit process failed to load the library R.dll. Native error message is 'The system cannot find the file specified'

I've been wrestling with this for many hours now and finally asking for some help on what a solution might be. It should be noted the error is the same for 32bit or 64bit R.dll versions.


Comments: Alright, I dropped the utility code into the top of my project and here are the results. Is this process 64 bits? False Info: caller provided rPath=null, rHome=null Info: R.NET looked for preset R_HOME env. var. Found c:\Progra~1\R\R-3.2.2 I then get the following error when call GetInstance() System.Exception: This 32-bit process failed to load the library R.dll. Native error message is 'The specified module could not be found' at DynamicInterop.UnmanagedDll.ThrowFailedLibraryLoad(String dllFullName, String nativeError) at DynamicInterop.UnmanagedDll.ReportLoadLibError(String dllName, String nativeError) at DynamicInterop.UnmanagedDll..ctor(String dllName) at RDotNet.REngine..ctor(String id, String dll) at RDotNet.REngine.CreateInstance(String id, String dll) at RDotNet.REngine.GetInstance(String dll, Boolean initialize, StartupParameter parameter, ICharacterDevice device) at RNetTest.Program.Main(String[] args) in c:\Users\cmenright\Documents\Visual Studio 2013\Projects\RNetTest\RNetTest\Program.cs:line 35 Here is the code that I'm trying to run: // Call R from .NET. Advantage is that everything is in process. // Tested on VS2012, will probably work on VS2010. using System; using System.IO; using System.Linq; using RDotNet; using RDotNet.NativeLibrary; namespace RNetTest { class Program { static void Main(string[] args) { try { string rHome = null; string rPath = null; if (args.Length > 0) rPath = args[0]; if (args.Length > 1) rHome = args[1]; var logInfo = NativeUtility.FindRPaths(ref rPath, ref rHome); Console.WriteLine("Is this process 64 bits? {0}", System.Environment.Is64BitProcess); Console.WriteLine(logInfo); REngine.SetEnvironmentVariables(); REngine engine = REngine.GetInstance(); // Initializes settings. //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(); Console.WriteLine("Group1: [{0}]", string.Join(", ", group1)); Console.WriteLine("Group2: [{0}]", string.Join(", ", group2)); Console.WriteLine("P-value = {0:0.000}", p); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } } } I'm not sure what's going on but I've tried everything on this site as well as a few others on Google but I can't seem to get this working. Any other ideas?

Commented Unassigned: REngine.GetInstance fails [177]

$
0
0
Hi, I'm new to R but really would love to use it in my C# programs via RDotNet. I've added R.net via Manage NuGet Packages in VS2013 (RDotNet runtime Version v4.0.30319).

Within Windows 7 I'm running R-3.2.2 and both 32bit and 64bit reside within my C:\Program Files\R\R-3.2.2\bin folder.

Here's the beginning of my code.

using System.IO;
using System.Linq;
using RDotNet;
using RDotNet.NativeLibrary;

namespace RNetTest
{
class Program
{
static void Main(string[] args)
{
// Set the R_HOME environment variable in which R.dll is located.
Environment.SetEnvironmentVariable("R_HOME", @"C:\Program Files\R\R-3.2.2\bin\i386");

REngine engine = REngine.GetInstance("RDotNet");

It fails on the GetInstance with the error:

An unhandled exception of type 'System.ArgumentException' occurred in DynamicInterop.dll

Additional information: Could not retrieve a pointer for the symbol 'R_CStackLimit' in file 'RDotNet'

If I run REngine.GetInstance(); like is suggested I get the following error:

An unhandled exception of type 'System.Exception' occurred in DynamicInterop.dll

Additional information: This 32-bit process failed to load the library R.dll. Native error message is 'The system cannot find the file specified'

I've been wrestling with this for many hours now and finally asking for some help on what a solution might be. It should be noted the error is the same for 32bit or 64bit R.dll versions.


Comments: Thank you for that. I now think I know what is happening. Actually, this can be considered a bug, but there is a workaround. I'd advise you remove the R_HOME environment variable, if you can. This seems to be rather unusual to have is set system-wide anyway. Do not use `Environment.SetEnvironmentVariable` either. Just use `REngine.SetEnvironmentVariables()` and your setup should be found. Given your (our) programs run as 32 bits exes, provided your R keys in your Windows registry (regedit.exe, but be extra careful with accessing it) looks like the following (my setup, deliberately to default to 3.2.1 for previous tests, but yours can point to 3.2.2): ``` HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\R-core\R CurrentVersion 3.2.1 InstallPath c:\Program Files\R\R-3.2.1 subkeys of HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\R-core\R: ----> 3.2.1 ----> 3.2.2 ``` Then R.NET FindRPaths should report the following: ``` Is this process 64 bits? False Info: caller provided rPath=null, rHome=null Info: R.NET looked for preset R_HOME env. var. Found null Info: Found Windows registry key HKEY_LOCAL_MACHINE\SOFTWARE\R-core Info: Found Windows registry key HKEY_LOCAL_MACHINE\SOFTWARE\R-core Info: Found sub-key InstallPath under HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R Info: InstallPath value of key HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R: C:\ProgramFiles\R\R-3.2.1 Info: R.NET looked for platform-specific way (e.g. win registry). Found C:\Program Files\R\R-3.2.1 Info: R.NET trying to find rPath based on rHome; Deduced C:\Program Files\R\R-3.2.1\bin\i386 ``` Hope this helps - let us know either way. Thank you for helping to spot the issue.

Commented Unassigned: REngine.GetInstance fails [177]

$
0
0
Hi, I'm new to R but really would love to use it in my C# programs via RDotNet. I've added R.net via Manage NuGet Packages in VS2013 (RDotNet runtime Version v4.0.30319).

Within Windows 7 I'm running R-3.2.2 and both 32bit and 64bit reside within my C:\Program Files\R\R-3.2.2\bin folder.

Here's the beginning of my code.

using System.IO;
using System.Linq;
using RDotNet;
using RDotNet.NativeLibrary;

namespace RNetTest
{
class Program
{
static void Main(string[] args)
{
// Set the R_HOME environment variable in which R.dll is located.
Environment.SetEnvironmentVariable("R_HOME", @"C:\Program Files\R\R-3.2.2\bin\i386");

REngine engine = REngine.GetInstance("RDotNet");

It fails on the GetInstance with the error:

An unhandled exception of type 'System.ArgumentException' occurred in DynamicInterop.dll

Additional information: Could not retrieve a pointer for the symbol 'R_CStackLimit' in file 'RDotNet'

If I run REngine.GetInstance(); like is suggested I get the following error:

An unhandled exception of type 'System.Exception' occurred in DynamicInterop.dll

Additional information: This 32-bit process failed to load the library R.dll. Native error message is 'The system cannot find the file specified'

I've been wrestling with this for many hours now and finally asking for some help on what a solution might be. It should be noted the error is the same for 32bit or 64bit R.dll versions.


Comments: Thank you so much for all of your help. Removing the environment variable R_HOME resolved my issue completely! All registry keys were already setup so I just had to remove the R_HOME and it now works! Thanks again for all of your help.

Commented Unassigned: R.NET Dataframe not handling POSIXlt properly [178]

$
0
0
Hi
One of my R dataframe column is of type "POSIXlt".
I am loading this R dataframe in R.NET's Dataframe object like following :

In R (instance created using R.NET):
----------------------------------------
mydataset = # some R dataframe that has, say fourth column of type POSIXlt. And there are more than 11 rows in the dataframe.

In C#
------
DataFrame DF = engine.GetSymbol("mydataset").AsDataFrame();

Now, when I try to access value of the row index greater than 11 and col index (that is of type POSIXlt), I get ArgumentOutOfRangeException ( as if that particular index doesn't exists ).

//now if I try to access 4th column of row index greater than 11, I get exeception
object data = DF[12,4];


Thanks,

Comments: Thank you for these precisions; Regarding R.NET 1.6.5, the performance issues are very likely to be because `rEngine.AutoPrint` is set to true by default. This is so as to match the default behavior of R, and in particular to keep expected behavior for showing graphs. That said, I do not like the downside. Try to set AutoPrint to false and there is a strong chance the performance issues will go away.

Created Unassigned: I register R.NET relevant dll in GAC, program compile error [179]

$
0
0

Hi, I register R.NET relevant dll in GAC.
R.NET relevant dll includes RDotNet.dll, RDotNet.NativeLibrary.dll, and DynamicInterop.dll.

But c# program compile error.
"The type 'DynamicInterop.UnmanagedDll' is defined in an assembly that is not referenced. You must add a reference to assembly 'DynamicInterop, Version=0.7.4.0, Culture=neutral, PublicKeyToken=null'"

I sure the version of DynamicInterop.dll is correct

Thanks for your help.




Commented Unassigned: R.net Code not working [173]

$
0
0
Hi,

I get the from this site but not working, im new in R.Net please help me what is my mistake.

i am using MVC.

Code

```
REngine.SetEnvironmentVariables();
// There are several options to initialize the engine, but by default the following suffice:
REngine engine = REngine.GetInstance();

// .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();
```

ERROR

```
Error: could not find function "t.test"
```



Give me the suggestion.


Thanks.
Comments: I have same problem. Account for execute IIS is IIS_IUSRS. The privilege of R folder for IIS_ISRS is "full control" I tried D:\R\R-3.1.1\bin\i386 and D:\R\R-3.1.1\bin\x64. Web service always response time-out. I'm sad...

New Post: Restarting R in a server application

$
0
0
I am developing a C# solution to run R.net (version 1.6.5) on a Windows server 2008 R2. The R functionality runs pretty stable and performs well. My Problem is that the server is running constantly, but R won't be needed all the time so in order to keep the maintenance simple I’d like to implement a Routine that starts the REngine , runs the R code and then shuts the REngine down again, so it can later be restarted. To shut down/idle the REngine temporarily the function Dispose() seems not to be appropriate as is prevents the REngine from restarting again. However the Rdotnet documentation also recommends to always shutdown an engine after using it. I tried using Dispose() but got different exeptions, in different usage cases one of them is:
The single REngine instance has already been disposed of (i.e. shut down). Multiple engine restart is not possible.
My R initialization in C# currently looks like this:
  class RDotNetAdaptor {
  protected REngine REngine;
  protected RDotNetAdaptor() {
     REngine = REngine.GetInstance();
     REngine.Initialize();
   }
  ~RDotNetAdaptor() {
     REngine.Dispose();
  }
 //…
 }
How can I shut down/ idle the REngine so I can restart it again later?

New Post: Create multiple R instances on separate threads

$
0
0
Hi,

Is it possible to either create multiple instances of the REngine or create multiple workspaces? I have several tasks which I want to run in parallel which call R to do some computation. They need to be sand boxed from each other as the use the same R variable names. When I try and call REngine.GetInstance() on multiple background threads it hangs i.e.
        static void Main(string[] args) {
            var tasks = new List<Task>();
            tasks.Add(Task.Run(() => { REngine.GetInstance(); Console.WriteLine("Instance 1 Created"); }));
            tasks.Add(Task.Run(() => { REngine.GetInstance(); Console.WriteLine("Instance 2 Created"); }));
            Task.WaitAll(tasks.ToArray());
            Console.WriteLine("Finished...");
            Console.ReadKey();
        }
Fails, seems to be some sort of deadlock in GetInstance as the Console.WriteLine is never reached. I'd appreciate any help on whether async is possible and if so what's the recomended approach?

Regards
Dave

Reviewed: R.NET 1.5.19 (NuGet) (10 06, 2015)

$
0
0
Rated 4 Stars (out of 5) - Good Good !!!

New Post: alternative to str() in source() to get full variable's output

$
0
0
Hi all,

I'm able to start REngine in a .Net 4.5 Console Application in C#. Then I let a script running using source(). This works fine and I get some output on my console, e.g. when a package is loaded but I'd like to get some more output.

In the examples I only found str() to get some output on my console (not the R console and also not the R Studio console but the application console coming from Visual Studio). Using str() only gives me a short overview which is great at times but right now I'd like to see every entry of my variable. I want to get the full output of a variable, e.g. in R I would type the variable's name. However when I type just the variable's name in my R-file and source() this file from C# I don't get any output on my console application.

I can get the variables output with REnginge by
engine.Evaluate("with(" + env + ", variableName)");
Is there any simple way I get the variable's output from a R file that's being source()ed? I read about writing your own console (https://rdotnet.codeplex.com/discussions/261917) but I think there might be an other way to just to display a variable, right?

Thanks
Toby

Commented Unassigned: I register R.NET relevant dll in GAC, program compile error [179]

$
0
0

Hi, I register R.NET relevant dll in GAC.
R.NET relevant dll includes RDotNet.dll, RDotNet.NativeLibrary.dll, and DynamicInterop.dll.

But c# program compile error.
"The type 'DynamicInterop.UnmanagedDll' is defined in an assembly that is not referenced. You must add a reference to assembly 'DynamicInterop, Version=0.7.4.0, Culture=neutral, PublicKeyToken=null'"

I sure the version of DynamicInterop.dll is correct

Thanks for your help.




Comments: Your project (assuming you use Visual Studio or Xamarin) must reference DynamicInterop, whether it is in the GAC or not.

New Post: Restarting R in a server application

$
0
0
R.NET embeds R in the same process as the main program, and R cannot be restarted twice in the same process. This is a limit of R, not R.NET.

A solution to this has been developed on a branch of the codebase, but I have not had the resources to bring it to a testing/release phase yet (not aligned with my day work needs)

New Post: Create multiple R instances on separate threads

$
0
0
No, it is not. R itself is overwhelmingly not thread safe (at least the R project release one - I don't know about other new/commercial offerings), and in all but very specific cases will crash/deadlock/whatever. Nothing R.NET can do about.

New Post: alternative to str() in source() to get full variable's output

$
0
0
Interesting observation.

R.NET engine has AutoPrint set to true by default (matches R behavior). Testing something:
# c:/tmp/blah.r
danca <- 'kizomba'
featuring <- 'Saaphy'
danca # does not print if source-d , even if R.NET engine.AutoPrint == true
print(featuring)
indeed print to the console only:
[1] "Saaphy"
Incidentaly it matches the behavior of an R terminal:
> source("c:/tmp/blah.r")
[1] "Saaphy"
So whether from R or R.NET you need to use print to get output. Or, in C#:
engine.Evaluate("print(danca)")
# you can query variable names in the global environment with:
engine.Evaluate("ls()")
The following test program may be of use: https://github.com/jmp75/rdotnet-onboarding/tree/master/SourceRCode
Viewing all 1634 articles
Browse latest View live