[英]How to call a user defined function (in a .rdata file) from c# R.net?
I have, in one hand, a plateform I developped in R, composed of many user-defined functions used to produce a report, using as inputs matrices and arguments. 一方面,我有一个用R开发的平台,由许多用户定义的函数组成,这些函数用于生成报告,并使用矩阵和自变量作为输入。
In an other I manage my data flow through a c#
Platform. 另外,我通过c#
平台管理数据流。
What I want to do is calling my R
Platform from c#
: calling a function defined in an Rdata
file into my c#
code (which handle all my data matrices). 我想做的是从c#
调用R
平台:将Rdata
文件中定义的函数调用到我的c#
代码中(该代码可以处理所有数据矩阵)。
I am familiar with RdotNet
and use it to call user defined functions, but these are functions defined in my c#
code itself, while I need to call functions in a Rdata
file. 我熟悉RdotNet
并使用它来调用用户定义的函数,但是这些是在c#
代码本身中定义的函数,而我需要在Rdata
文件中调用函数。
Thanks in advance. 提前致谢。
R functions called from R.NET are not restricted to ones created from strings in .NET. 从R.NET调用的R函数不限于从.NET中的字符串创建的函数。 If you define and save the function definition in R: 如果在R中定义并保存函数定义:
f <- function() {"Hello World"}
save(f, file='f.RData')
Then in C# you simply do something like 然后在C#中,您只需执行类似
static void stackoverflow_27924923_2752565 (REngine engine)
{
engine.Evaluate ("load('~/f.RData')");
var s = engine.Evaluate ("f()").AsCharacter()[0];
Console.WriteLine(s);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.