从命令行运行R代码(Windows) [英] Running R Code from Command Line (Windows)

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

问题描述

我有一个R代码在一个名为analyse.r的文件中。我想从命令行(CMD),运行该文件中的代码,而不必通过R终端,我也希望能够传递参数和使用这些参数在我的代码,东西像以下伪代码:

I have some R code inside a file called analyse.r. I would like to be able to, from the command line (CMD), run the code in that file without having to pass through the R terminal and I would also like to be able to pass parameters and use those parameters in my code, something like the following pseudocode:

C:\>(execute r script) analyse.r C:\file.txt

这将执行脚本并传递C:\file.txt作为参数

and this would execute the script and pass "C:\file.txt" as a parameter to the script and then it could use it to do some further processing on it.

如何实现这一目标?

非常感谢,

ExtremeCoder

ExtremeCoder

虽然不相关我也想知道如何绘制一条线的最佳拟合在一个特定的数据表?

Although unrelated I would also like to know how do I plot a line of best fit in R for a certain table of data?

推荐答案


  1. 您要 Rscript.exe

您可以在脚本中控制输出 - 参见 sink()

You can control the output from within the script -- see sink() and its documentation.

您可以通过 commandArgs()访问命令参数。

You can access command-arguments via commandArgs().

您可以通过 getopt optparse 包。

如果一切都失败,请考虑阅读手册提供的文档

If everything else fails, consider reading the manuals or contributed documentation

这篇关于从命令行运行R代码(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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