2014-05-01 28 views
0

我已经在一个文件下面的脚本(称之为“temp.R”):差运行RSCRIPT VS猿与库源

library(ape) 
tree <- rbdtree(0.5, 0.05, 5) 
bd.time(tree, 0, 0) 

当我运行Rscript temp.R我得到的一些结果:

$par 
    birth  death 
0.5289875 0.0000000 

$SS 
[1] 9.21573 

$convergence 
[1] 0 

$iterations 
[1] 6 

$evaluations 
function gradient 
     8  16 

$message 
[1] "relative convergence (4)" 

然而,当我运行R和然后执行:

source('temp.R') 

我得到以下错误:

Error in integrate(Pi, 0, Tmax) : non-finite function value 

有没有人有任何想法为什么Rscriptsource之间的差异,使一个工作,另一个失败?如果有帮助,这里是由R中运行version输出:

   _       
platform  x86_64-apple-darwin10.8.0 
arch   x86_64      
os    darwin10.8.0     
system   x86_64, darwin10.8.0   
status          
major   3       
minor   0.1       
year   2013       
month   05       
day   16       
svn rev  62743      
language  R       
version.string R version 3.0.1 (2013-05-16) 
nickname  Good Sport 

UPDATE:当我运行Rscript temp.R几次我有时会收到类似的错误信息运行source时为:

Error in integrate(Pi, 0, Tmax) : non-finite function value 
Calls: bd.time ... objective -> CDF.birth.death -> .CDF.birth.death2 -> integrate 
Execution halted 

回答

1

这与Rscript和source()之间的区别没有关系,它只是您使用的函数依赖于随机过程,并取决于它起作用或不起作用。我没有仔细研究你想要达到的目标,但你可能需要更改你用于bd.time函数的值。

## works 
set.seed(123) 
library(ape) 
tree <- rbdtree(0.5, 0.05, 5) 
bd.time(tree, 0, 0) 

## doesn't work 
set.seed(12345) 
library(ape) 
tree <- rbdtree(0.5, 0.05, 5) 
bd.time(tree, 0, 0) 
+0

使用种子123,它与Rscript一起使用,但它不使用source()。 – redcurry