本文介绍了在unix中为带解释器的r脚本或命令运行unix-layman的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是unix和unix的外行,我在Windows中使用R.例如,我在我的R会话中输入了following(在R gui中).

I am layman to unix and sofar I using R in windows. For example I type following in my R session (in R gui).

# this is a my funny example script 
X <- 1:10
Y <- 21:30
plot(X, Y)
myfun <- function (x){
              x1 <- x^0.2
              return (x1)
             }
myfun(X)

在两种情况下,如何在unix shell中实现这一目标-

How can I achieve this in unix shell, in two situations -

(1)直接通过命令行在命令行中(2)创建脚本并运行脚本.

(1) directly in command line via an interpeter(2) creating a script and running script.

考虑到我是unix的非专业人士,请提供步骤.

Please provide step considering I am layman to unix.

推荐答案

假定将脚本保存在名称为so.R的简单文本文件中,则可以在Linux/Unix下通过在提示符下键入R来运行该脚本. .在R中输入

Assuming you save your script in a simple text file with the name so.R, you can run it under Linux/Unix by typing R at the prompt. Once in R enter

  source('so.R')

在R环境中执行脚本(假定so.R文件与发出此命令时所在的目录位于同一目录中.)

to execute the script inside the R environment (this assumes the so.R file is in the same directory as you are when you issue this command).

要从Linux/Unix命令行运行脚本,请使用以下命令:

To run the script from the Linux/Unix command line use the following command:

  R CMD BATCH so.R

请注意,当我在R中运行脚本时,可以显示该图,但是从Linux命令行不显示该图.我怀疑它会迅速显示然后消失,因此,在显示绘图后,您必须查找一个R命令以使其暂停.

Note that I got the plot to show when I ran the script inside of R, but from the Linux command line it doesn't show. I suspect it gets quickly displayed and then goes away, so there will be a R command that you have to look up to make it pause after it displays the plot.

这篇关于在unix中为带解释器的r脚本或命令运行unix-layman的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 00:04