如何使用 RdotNet 创建 S4 对象

How to create an S4 Object using RdotNet

同时使用 R.NET 创建一个 S4 object (来自 mirt 包的函数的输出。

engine.Evaluate("library(mirt); data(LSAT6); x=mirt(LSAT6,1)");
S4Object Convertedinput = inputtoCsharp.AsS4();

我需要将 x(x 的所有槽)的输出显示到消息框中。

我该怎么做?

因为没有方法可以做这样的事情:

int[] resp_c = new int  [] {1,1,1,1};
**IntegerVector resp_cR = engine.CreateIntegerVector(resp_c);**
engine.SetSymbol("resp_c", resp_cR);
engine.Evaluate("ff=fscores(x, response.pattern=resp_c)");

以上是针对整数向量完成的。我需要为 R.

中的 S4 object 模拟相同的内容

我怎样才能做到这一点?

不完全确定我理解您的请求,但下面的示例代码应该有所帮助。它也可以从 An R.NET support github repo, method ReproWhosebug_34355201 in file /ReproUsers/Program.cs . For future reference, written at commit 43a8ec3

engine.AutoPrint = true;
//samples taken from ?fscores man page in package mirt
engine.Evaluate("library(mirt)");
// 'Science' is a prepackage sample data in mirt; you can use 'engine.CreateDataFrame' in C# to create your own if need be.
engine.Evaluate("mod <- mirt(Science, 1)");
engine.Evaluate("class(mod)");
S4Object modcs = engine.GetSymbol("mod").AsS4();
IDictionary<string, string> slotTypes = modcs.GetSlotTypes();
if (slotTypes.Keys.Contains("Fit"))
{
    GenericVector fit = modcs["Fit"].AsList();
    // should check logLik in fit.Names;
    double logLik = fit["logLik"].AsNumeric()[0];
}
engine.Evaluate("tabscores <- fscores(mod, full.scores = FALSE)");
engine.Evaluate("head(tabscores)");
engine.Evaluate("class(tabscores)");
NumericMatrix tabscorescs = engine.GetSymbol("tabscores").AsNumericMatrix();