2

Rscript と R CMD BATCH の両方を試しました。

たとえば、この単純な R スクリプトを実行すると、次のようになります。

test <- function(){
  print("test")
}

を使用して

> R CMD BATCH test.R

次の test.Rout ファイルを取得します。

R version 3.0.1 (2013-05-16) -- "Good Sport"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-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.

Natural language support but running in an English locale

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]

> test <- function(){
+   print("test")
+ }
> 
> proc.time()
  user  system elapsed 
  0.176   0.016   0.186 

期待される出力が表示されませんでした:

>[1] "test"

どこでも - コマンドラインまたは test.Rout ファイルのいずれか。

Rscript を使用すると、コマンド ラインにも出力が表示されません。

RStudio 内で実行すると、特定のディレクトリにレポート ファイルを書き込む長い R スクリプトがあります。ただし、R CMD BATCH を使用してこのスクリプトを実行すると、ディレクトリに生成されたファイルが表示されません。対応する .Rout ファイルには、実行結果ではなく、コードの個々の行の同様の実行ステートメントが表示されます。

Ubuntu 12.04 LTS を使用しています。

私は何を間違っていますか?

ありがとう!

4

1 に答える 1

9

スクリプト内で関数を呼び出す必要があります。この時点では関数を定義しているだけで、決して呼び出してはいけません! 私にも起こります。したがって、次を追加します。

test <- function(){
  print("test")
}
test()
于 2014-07-03T03:40:43.450 に答える