简体   繁体   English

将参数从VBS传递给R.

[英]Pass Arguments from VBS to R

I have an R-script, which runs a VBS. 我有一个运行VBS的R脚本。

VB-Script should pass arguments back to R. VB脚本应该将参数传递回R.

I created the codes, but passed argument is still NA. 我创建了代码,但传递的参数仍然是NA。

R: 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: 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)

If the variable you try to send is a text message, you can write it to a txt file and loop from R until value of the text file not null or empty (I nerver tried to code with R) and then use the value of the text file. 如果您尝试发送的变量是文本消息,您可以将其写入txt文件并从R循环,直到文本文件的值不为null或为空(I nerver尝试用R编码)然后使用该值文本文件。

(I also tried wscript.echo "MYTEXT" and run it from command line but it poped a msgbox). (我也尝试了wscript.echo“MYTEXT”并从命令行运行它,但它加了一个msgbox)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM