Access 2016命令按钮执行R脚本的问题 [英] issue with R script execution from Access 2016 command button

查看:156
本文介绍了Access 2016命令按钮执行R脚本的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Access 2016命令按钮执行R脚本。该脚本读取文件并根据文件内部的值生成图。
当我从Windows 10命令行按如下所示运行它时,效果很好:

I’m trying to execute R script from Access 2016 command button. The script reads in a file and generates a plot from values inside the file. It works well when I run it from Windows 10 command line as follows:

C:\Program Files\R\R-3.3.2\bin>Rscript --vanilla H:\R\analyze.R H:\R\LCH_22.vcf

我想从Access 2016中的一个按钮执行R脚本。

I would like to execute the R script from a button in Access 2016.

这里是vba脚本我正在使用的是:

Here is a vba script that I'm using:

Dim file_path As String

file_path = "H:\R\LCH_22.vcf"

Dim RetVal
RetVal = shell("""C:\Program Files\R\R-3.3.2\bin\Rscript.exe"" --vanilla ""H:\R\analyze.R"" ""H:\R\LCH_22.vcf""", vbHide)

MsgBox RetVal

脚本执行但生成空白图。它具有所有轴和标签,但缺少所有数据。我不确定为什么会这样。

The script executes but generates a blank plot. It has all axis and labels but all data is missing. I'm not sure why this is happening.

跟进我已经替换了 vbHide vbNormalFocus 并能够生成包含数据的图...是的!但是,我不明白为什么将变量替换为Shell命令不起作用。有人可以解释如何正确完成此操作吗?我将从Access中的表单读取文件名,这部分代码必须是动态的(请参见下面的示例)。

Follow up I've replaced vbHide with vbNormalFocus and was able to generate a plot with data... yeah! However, I don't understand why substituting a variable into Shell command doesn't work. Could someone please explain how to accomplish this correctly? I will read the file name from a form in Access and this part of the code has to be dynamic (See example of my attempt below).

Dim file_path
file_path = "C:\R\DNA.vcf"
Dim RetVal
RetVal = shell("""C:\Program Files\R\R-3.3.2\bin\Rscript.exe"" --vanilla ""C:\R\analyze.R"" "" & file_path & """, vbNormalFocus)

非常感谢您的提前帮助。

Thank you very much for your help in advance.

推荐答案

只需在 file_path 周围加上一对引号:

Simply add one more pair of quotes around file_path:

Dim file_path As String
Dim RetVal As Integer

file_path = "C:\R\DNA.vcf"

RetVal = shell("""C:\Program Files\R\R-3.3.2\bin\Rscript.exe"" --vanilla "_
               & """C:\R\analyze.R"" """ & file_path & """", vbNormalFocus)

这篇关于Access 2016命令按钮执行R脚本的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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