bab*_*abu 22 windows platform r
我在一个txt文件中有一个R程序说"functions.txt"
.
我加载"functions.txt"
使用文件将R source("function.txt")
,然后调用函数f1()
,f2()
等,其被声明和内定义
"function.txt"
文件.在
使用library()
之前我还需要加载几个R库f1()
,f2()
等等.
我的问题是,如果不打开R环境,我可以从Windows提示符中实现所有这些(即调用函数f1()
和f2()
)吗?
所以基本上我想
f1()
,f2()
等等.function.txt
文件所有来自windows的命令promt c:\>
我在我的电脑上安装了Windows版本的R.
由于我不是非常精通计算机,所以任何人都可以给出详细的答案.
问候
Dir*_*tel 22
Bart的帖子是正确的,但这可以更简单.如果是代码
f1 <- function() {
print("A")
}
f2 <- function() {
print("B")
}
f1()
f2()
Run Code Online (Sandbox Code Playgroud)
在文件'myRcode.R'中; 然后
Rscript myRcode.R
Run Code Online (Sandbox Code Playgroud)
将加载并执行它,包括两个函数调用.
Rscript.exe
与...相同的目录R.exe
- 可能必须添加到目录中$PATH
.
以下"适用于我的机器"(虽然不是Windows,但应该......):
如果你functions.txt
看起来像:
f1 <- function()
{
print("A")
}
f2 <- function()
{
print("B")
}
Run Code Online (Sandbox Code Playgroud)
命令:
Rscript -e "source('functions.txt');f1();f2()" > out.txt
Run Code Online (Sandbox Code Playgroud)
应创建out.txt
包含以下内容的文件
[1] "A"
[1] "B"
Run Code Online (Sandbox Code Playgroud)
小智 6
这是一个命令行脚本,基于以上代码:
d:\misc2\bin\Rscript.exe d:\r_code\mycode.r
Run Code Online (Sandbox Code Playgroud)
使用Windows 7,我将其作为.bat文件运行.工作良好.谢谢你的提示.(当然,这些只是我特定的子目录)
归档时间: |
|
查看次数: |
63058 次 |
最近记录: |