与start.process在.NET运行R​​.脚本 [英] Run R script with start.process in .net

查看:206
本文介绍了与start.process在.NET运行R​​.脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行在vb.net中的R脚本,从而节省数据.csv文件。到现在我发现了以下的方法:

 暗淡strCmd为String
strCmd =R CMD一批+C:\ test.R
的Process.Start(的CMD.exe,strCmd
 

显然这应该工作,但在我的情况下,CMD弹出(在我的debug文件夹lokated),并没有任何反应。

另一种方式我想是

 的Process.Start(Rgui.exe,C:\ test.R)
 

错误消息:参数C:\ test.R忽略

这是不工作要么。

我的ř剧本我只是用一个例子

 汇()
setwd(C:/)
X  -  LT;  -  data.frame(A = I(一个\报价),B =圆周率)
沉(test.csv)
 

解决方案

这是怎么对我的作品:

 昏暗myprocess随着新工艺
        myprocess.StartInfo =新的ProcessStartInfo(C:\ Program Files文件(x86)的\ r \ R-2.6.2 \ BIN \里面运行R.exe,CMD料C:/Users/test/test3.RC:/用户/测试/testout.csv)
        myprocess.Start()
 

第二个方法(第一个应用程序犯规给了我一个很好的CSV输出,所以在这里,这是一个解决办法。):

 昏暗的PROC =新工艺
    proc.StartInfo.FileName =C:\ Program Files文件(x86)的\ r \ R-2.6.2 \ BIN \ Rscript.exe
    proc.StartInfo.WorkingDirectory =C:\ Program Files文件(x86)的\ r \ R-2.6.2 \ BIN
    proc.StartInfo.Arguments =C:/Users/Desktop/RtoVB/test4.r
    proc.StartInfo.UseShellExecute = TRUE
    proc.StartInfo.RedirectStandardOutput = FALSE
    proc.Start()
 

I want to run an r script in vb.net which saves data in a .csv file. Till now i found the following approaches:

dim strCmd as String
strCmd = "R CMD BATCH" + "C:\test.R"
process.start("CMD.exe", strCmd

apparently this should work but in my case the cmd pops up (lokated in my debug folder) and nothing happens.

Another way i tried was

process.start("Rgui.exe", "C:\test.R")

Error Message: Argument "C:\test.R" ignored

this is not working either.

for my r script i just used an example

sink()
setwd("C:/")
x <- data.frame(a = I("a \" quote"), b = pi)
sink(test.csv)

解决方案

this is how it works for me:

        Dim myprocess As New Process
        myprocess.StartInfo = New ProcessStartInfo("C:\Program Files (x86)\R\R-2.6.2\bin\R.exe", "CMD BATCH C:/Users/test/test3.R C:/Users/test/testout.csv")
        myprocess.Start()

second approach (first app. doesnt give me a good csv output so here this is a workaround):

    Dim proc = New Process
    proc.StartInfo.FileName = "C:\Program Files (x86)\R\R-2.6.2\bin\Rscript.exe"
    proc.StartInfo.WorkingDirectory = "C:\Program Files (x86)\R\R-2.6.2\bin"
    proc.StartInfo.Arguments = "C:/Users/Desktop/RtoVB/test4.r"
    proc.StartInfo.UseShellExecute = True
    proc.StartInfo.RedirectStandardOutput = False
    proc.Start()

这篇关于与start.process在.NET运行R​​.脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆