我有一个带有XYZ-Data的PointCloud,并希望通过我的C#GUI中的.r脚本进行绘制。因此,我在R中使用“ rgl”库。R代码工作正常。我尝试使用此类:
/// <summary>
/// This class runs R code from a file using the console.
/// </summary>
public class RScriptRunner
{
/// <summary>
/// Runs an R script from a file using Rscript.exe.
/// Example:
/// RScriptRunner.RunFromCmd(curDirectory + @"\ImageClustering.r", "rscript.exe", curDirectory.Replace('\\','/'));
/// Getting args passed from C# using R:
/// args = commandArgs(trailingOnly = TRUE)
/// print(args[1]);
/// </summary>
/// <param name="rCodeFilePath">File where your R code is located.</param>
/// <param name="rScriptExecutablePath">Usually only requires "rscript.exe"</param>
/// <param name="args">Multiple R args can be seperated by spaces.</param>
/// <returns>Returns a string with the R responses.</returns>
public static string RunFromCmd(string rCodeFilePath, string rScriptExecutablePath, string args)
{
string file = rCodeFilePath;
string result = string.Empty;
try
{
var info = new ProcessStartInfo();
info.FileName = rScriptExecutablePath;
info.WorkingDirectory = Path.GetDirectoryName(rScriptExecutablePath);
info.Arguments = rCodeFilePath + " " + args;
info.RedirectStandardInput = false;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
info.CreateNoWindow = true;
using (var proc = new Process())
{
proc.StartInfo = info;
proc.Start();
result = proc.StandardOutput.ReadToEnd();
proc.Close();
}
return result;
}
catch (Exception ex)
{
throw new Exception("R Script failed: " + result, ex);
}
}
}
问题是当我从上方通过RScriptRunner-Class启动.r文件时,rgl-plot弹出并直接关闭。那么该怎么办才能使绘图窗口保持打开状态? 这是我的.R代码:
daten <- read.csv("file:///C:\\Users\\Quirin\\Dropbox\\KwiJuLa\\Testmessung Debugging 25.10\\test.csv")
library(rgl)
datenMatrix <- as.matrix(daten)
x1 <- datenMatrix[, 3]
y1 <- datenMatrix[, 4]
z1 <- datenMatrix[, 5]
rgl1 <- plot3d(x1, y1, z1)
亲切的问候