将参数从VBS传递给R.

时间:2017-06-19 20:58:52

标签: r vbscript

我有一个运行VBS的R脚本。

VB-Script应该将参数传递回R。

我创建了代码,但传递的参数仍然是NA。

R:

path <- "C:\\Users\\PD\\Desktop\\Dashboard Citi R\\test\\scripcik.vbs"

shell(shQuote(normalizePath(path)), "cscript", flag = "//nologo")

args<-commandArgs(TRUE)
myvar<-args[1]
print(myvar)

VBS:

dim myArr
Dim shell
Set shell = CreateObject("WScript.Shell")
chartpath6 = "C:\Users\PD\Desktop\Dashboard Citi R\test\bazy\" & myDate(now) & ".accdb"
chartpath5 = "C:\Users\PD\Desktop\Dashboard Citi R\test\bazy\" & myDate(now)-1 & ".accdb"

myArr = Array(chartpath6,chartpath5) 

for i = 0 to 1
    ReportFileStatus(myArr(i))
next

sub ReportFileStatus(filespec)
   Dim fso, msg
   Set fso = CreateObject("Scripting.FileSystemObject")
   If (fso.FileExists(filespec)) Then
      msg = filespec & " exists."
   Else
      msg = filespec & " doesn't exist."
   End If
   msgbox msg
End sub

Function myDate(dt)
    dim m,y
    m = right("0" & datePart("m",dt),2)
    y = datePart("yyyy",dt)
    myDate=  y & m
End Function

Dim path

path = "Rscript C:\Users\PD\Desktop\Dashboard Citi R\test\runR.R " & msg

shell.Run(path)

1 个答案:

答案 0 :(得分:0)

如果您尝试发送的变量是文本消息,您可以将其写入txt文件并从R循环,直到文本文件的值不为null或为空(我的nerver尝试用R编码)然后使用文本文件的值。

(我也试过wscript.echo“MYTEXT”并从命令行运行它,但是它加了一个msgbox)。