将R脚本变量传递到批处理脚本中

时间:2015-08-25 20:23:32

标签: r batch-file

在R脚本中,我正在for循环中执行批处理文件。

for (i in 1:2){
    shell(shQuote("\\\\NETWORK\\PATH\\TO\\THE\\FILE.BAT", "cmd"))
}

批处理脚本创建数据并将其移动到如下所示的SQL表:

|  Name | Version | Category | Value | Number | Replication |
|:-----:|:-------:|:--------:|:-----:|:------:|:-----------:|
| File1 | 1.0     | Time     |   123 |      1 |           1 |
| File1 | 1.0     | Size     |   456 |      1 |           1 |
| File2 | 1.0     | Time     |   312 |      1 |           1 |
| File2 | 1.0     | Size     |   645 |      1 |           1 |
| File1 | 1.0     | Time     |   369 |      1 |           2 |
| File1 | 1.0     | Size     |   258 |      1 |           2 |
| File2 | 1.0     | Time     |   741 |      1 |           2 |
| File2 | 1.0     | Size     |   734 |      1 |           2 |
| File1 | 1.1     | Time     |   997 |      2 |           1 |
| File1 | 1.1     | Size     |   997 |      2 |           1 |
| File2 | 1.1     | Time     |   438 |      2 |           1 |
| File2 | 1.1     | Size     |   735 |      2 |           1 |
| File1 | 1.1     | Time     |   786 |      2 |           2 |
| File1 | 1.1     | Size     |   486 |      2 |           2 |
| File2 | 1.1     | Time     |   379 |      2 |           2 |
| File2 | 1.1     | Size     |   943 |      2 |           2 |
| File1 | 1.2     | Time     |   123 |      3 |           1 |
| File1 | 1.2     | Size     |   456 |      3 |           1 |
| File2 | 1.2     | Time     |   312 |      3 |           1 |
| File2 | 1.2     | Size     |   645 |      3 |           1 |
| File1 | 1.2     | Time     |   369 |      3 |           2 |
| File1 | 1.2     | Size     |   258 |      3 |           2 |
| File2 | 1.2     | Time     |   741 |      3 |           2 |
| File2 | 1.2     | Size     |   734 |      3 |           2 |
| File1 | 1.3     | Time     |   997 |      4 |           1 |
| File1 | 1.3     | Size     |   997 |      4 |           1 |
| File2 | 1.3     | Time     |   438 |      4 |           1 |
| File2 | 1.3     | Size     |   735 |      4 |           1 |

但是,我希望在R脚本中声明NumberReplication列,而不是批处理文件。

我知道我可以这样做:

Replication <- i
Number <- as.integer(sqlQuery(dbhandle, "select max(Number) from Table"))
Number<-ifelse(is.na(Number), 1, Number + 1)

我的问题是如何将这些变量传递给批处理脚本?我可以将参数传递给批处理脚本吗?

所以在我的批处理脚本中,我可以有类似的东西:

set Rep=[Replication variable from R]
set Num=[Number variable from R]

0 个答案:

没有答案