从.BAT运行R.脚本(批处理文件) [英] run R script from .bat (batch file)

查看:1003
本文介绍了从.BAT运行R.脚本(批处理文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用批处理文件来运行A R脚本。目前我使用
启动R的捷径打开R.但是,我想 - [R自动运行,我已经保存在计算机上A R脚本。

I am trying to run a r script using batch file. Currently I am using start"" "shortcut of R" to open R. However, I wanna R automatically run a r script that I have saved on the computer.

可能R将运行脚本和用户没有看到R运行从后关闭。

Possibly R will be closed after running the script and user do not see R running.

这可能吗?非常感谢!

推荐答案

RSCRIPT 是标准的R命令的非交互式变种,只是专为这种用途。

Rscript is a non-interactive variant of the standard R command, just designed for this kind of use.

例如,windows下你可以定义一个 launcher.bat 是这样的:

For example, under windows you can define a launcher.bat like this :

PATH PATH_TO_R/R-version/bin;%path%
cd PATH_TO_R_SCRIPT
Rscript myscript.R arg1 arg2

在myscript.R添加了code读取参数:

In myscript.R you add the code to read the arguments:

args <- commandArgs(trailingOnly = TRUE)
arg1 <- as.character(args[1])  
arg2 <- as.numeric(args[2])  

这篇关于从.BAT运行R.脚本(批处理文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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