This project is read-only.

Character Limit

May 11, 2014 at 1:34 PM
Hi everyone

I would like to evaluate a large segment of R code, which is all part of the function. I cannot send the whole string in one "engine.Evaluate" command, as the string surpasses the character limit (I assume?). For example, my current code looks something like this (Using VB.Net):

Engine.Evaluate("x <- function(parameter){blah <- parameter + 1; blah + 6;.....[rest of code]}")

The [rest of code] segment is very long, approximately 400 lines of code. This cannot be interpreted by R in a single line. However, I cannot use

engine.Evaluate("x <- function(parameter){blah <- parameter + 1;")
engine.Evaluate("blah2 <- blah + 6;")

as this is breaks the function in R, so that it is not interpreted together.

Is there an alternative to send such a large function to R using R.NET?

May 11, 2014 at 1:50 PM
I've recently seen a string with ~100 lines of code being send to the Evaluate statement. There is no arbitrary length limits that I know of for it, though it may become unwieldy to debug incorrect lines.

If you have something with hundreds lines of code of functions, and this is static (not needing to be generated on the fly from your program) you may be better off loading an offline file with the R source function, or consider writing a package.
May 11, 2014 at 7:20 PM
Thanks for the quick reply!

I prefer to have all the code within the .NET application. Would my only alternative then be to write a package?
May 11, 2014 at 7:40 PM
You don't need to make an R package, has jperraud said, you can load it as a text file directly, or just type it in as a C# class. Lots of options, mostly just depends on how you debug.
May 14, 2014 at 9:08 AM
Can you please give me a short example of how I would do this in a class structure, or refer me to some reading?