Outline
目的:希望能透過 cmd 的方式執行 ./script.r
的檔案,並且讀進 Arguments
。
Install R on Ubuntu
|
|
Run R script from command line
方法一:use Rscipt
方法二:第一行加入 #!/usr/bin/Rscript
如下範例程式:
- Sample code
test.r
:
|
|
- Reminding: You can use
$ which Rscript
to search your path to Rscript.
|
|
- Run sample code
test.r
from command line:
|
|
If you get ^M Problem
|
|
This is an encoding problem at the end of line, your can use Line endings
setting of Sublime: View > Line Endings > Unix
Read Command line Argument
- Sample code
test.r
:
|
|
- Run sample code
test.r
from command line:
|
|
- Reminding: Arguments list start from index
1
.