我是R的工程師新手,並得到了一個腳本,我必須在Linux上運行,我搜索了很多,但無法找到一個簡單的命令來在Linux上運行腳本。我必須將我的工程軟件與R結合,因此我需要在Linux上運行它。如何在linux上提交R作業?
My script name is myscipt.R and I want to use 2 cpus to run that script.
請幫我啓動。
此致敬意。
我是R的工程師新手,並得到了一個腳本,我必須在Linux上運行,我搜索了很多,但無法找到一個簡單的命令來在Linux上運行腳本。我必須將我的工程軟件與R結合,因此我需要在Linux上運行它。如何在linux上提交R作業?
My script name is myscipt.R and I want to use 2 cpus to run that script.
請幫我啓動。
此致敬意。
這個工作對我來說:
R CMD BATCH myscript.R
作爲一個例子,以下應該產生一個隨機生成矩陣的.csv文件。我一直使用「.R」擴展名來命名這些腳本,但我不確定這是否必要。
腳本調用(名爲「testscript.R」)包含以下幾行代碼:
set.seed(1)
M<-matrix(runif(20),5,4)
write.csv(M, file="M.csv")
然後調用在控制檯這個腳本如上圖所示:
R CMD BATCH testscript.R
在我機器,這產生了「M.csv」文件,它看起來像這樣:
"","V1","V2","V3","V4"
"1",0.2655086631421,0.898389684967697,0.205974574899301,0.497699242085218
"2",0.37212389963679,0.944675268605351,0.176556752528995,0.717618508264422
"3",0.572853363351896,0.660797792486846,0.687022846657783,0.991906094830483
"4",0.908207789994776,0.62911404389888,0.384103718213737,0.380035179434344
"5",0.201681931037456,0.0617862704675645,0.769841419998556,0.777445221319795
此外,「testscript.Rout」文件生成給R控制檯輸出:
R version 2.14.0 (2011-10-31)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-pc-solaris2.10 (32-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
[Previously saved workspace restored]
> set.seed(1)
> M<-matrix(runif(20),5,4)
> write.csv(M, file="M.csv")
>
> proc.time()
user system elapsed
9.075 0.257 9.362
希望解釋它更好。
或者簡單地說:'Rscript myscript.R'。 –
不幸的是,這兩個命令不起作用,服務器不識別命令R或Rscript。可能是什麼問題呢? –
@hamad khan - 你可以通過在控制檯命令行中輸入「R」來打開R嗎? –
http://cran.r-project.org/doc/contrib/Lemon-kickstart/kr_scrpt.html –
據我所知,您無法控制從腳本外部使用的並行/ CPU數量(內核) :它需要在腳本中進行編碼('help(package =「parallel」))') –