running R from windows command prompt

喜你入骨 提交于 2019-11-27 18:23:39

Bart's post is correct, but this can be done simpler. If the code

f1 <- function() {
  print("A")
}

f2 <- function() {
  print("B")
}

f1()
f2()

is in a file 'myRcode.R'; then

Rscript myRcode.R

will load and execute it, including the two function calls.

Rscript.exe is in the same directory as R.exe -- which one may have to add to the $PATH.

The following "works on my machine" (not Windows though, but it should...):

If your functions.txt looks like:

f1 <- function()
{
  print("A")
}

f2 <- function()
{
  print("B")
}

the command:

Rscript -e "source('functions.txt');f1();f2()" > out.txt

should create the file out.txt containing:

[1] "A"
[1] "B"
Bill Yarberry

Here's a command line script, based on code above:

d:\misc2\bin\Rscript.exe    d:\r_code\mycode.r

Using Windows 7, I ran it as a .bat file. Works fine. Thanks for the tip. (of course, these are just my particular subdirectories)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!