gpt4 book ai didi

linux - 如何在 Linux 上提交 R 作业?

转载 作者:太空宇宙 更新时间:2023-11-04 09:51:16 25 4
gpt4 key购买 nike

我是 R 的工程师新手,有一个必须在 Linux 上运行的脚本,我搜索了很多但无法找到在 Linux 上运行该脚本的简单命令。我必须将我的工程软件与 R 相结合,因此我还需要在 Linux 上运行它。

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

希望能更好地解释它。

关于linux - 如何在 Linux 上提交 R 作业?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10910472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com