从没有RExcel的Excel VBA运行R [英] Running R from Excel VBA without RExcel

查看:370
本文介绍了从没有RExcel的Excel VBA运行R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以简化这个过程吗?

首先,我在R中手动打开此文件:
C:\R \ExampleModel\ModelScript.R

First, I manually open this file in R: C:\R\ExampleModel\ModelScript.R

从R-Editor开始,当下面的代码从打开的ModelScript.R文件运行时,它会处理模型。 R脚本正确。

source("C:\\R\\ExampleModel\\Model.R", echo=T)

在Excel中,我想运行以上源代码,无需首先从R手动打开ModelScript.R。有没有什么我可以修改在下面的VBA代码从Excel / VBA自动处理source()命令?如果批处理过程是唯一的选项,则不能使用Rexcel,请使用提供的示例扩展。

Excel 2007 VBA代码:

Excel 2007 VBA code:

Sub RRUN()

    Dim rCommand As String
    rCommand = "C:\\Program Files\\R\\R-3.0.0\\bin\\Rscript.exe --verbose C:\\R\\ExampleModel\\ModelScript.R"

    'Timer Set to run full Model.R script
    Application.Wait Now + TimeValue("00:00:05")

    'Runs R Script and Arguements into process
    Shell rCommand, vbNormalFocus

    'Timer Set to run full Model.R Script
    Application.Wait Now + TimeValue("00:00:05")

End Sub

注意:我尝试使用R.exe代替上面的Rscript.exe,没有结果。

Note: I tried using R.exe in place of Rscript.exe above, with no results.

推荐答案

您可能需要查看 Visual Studio Tools for Office 。对于Excel 2007,VSTO链接是这里

You might want to look into Visual Studio Tools for Office. For Excel 2007, the VSTO link is here.

以下是 R中的Excel示例(使用VTSO代码编写)。看看标题为其他应用程序的部分。这是来自同一人的另一个示例。我不知道他们是否销售这些应用程序,或者一切都是定制的。

Here's an example of R within Excel (written using VTSO code). Look at the section titled "Other Applications". Here's another example from the same people. I have no idea if they sell those applications, or if everything is custom made.

这是另一个可能的解决方案。我没有追求这种方法,因为我的应用程序有非常具体的要求。

Here's another possible solution. I haven't pursued this method because my application has very specific requirements.

我的观点是,即使你可以把东西放在一起使用VBA,它看起来更好方案。

My point is, even though you can put something together using VBA, it looks like there are better schemes.

这篇关于从没有RExcel的Excel VBA运行R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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