我在看《R语言实战》进行学习,看到了“输入和输出”这一部分。
script2.R中的代码为:
x <- runif(20)
summary(x)
hist(x)
GUI中命令为:
sink("myoutput", append=TRUE, split=TRUE)
pdf("mygraphs.pdf")
source("script2.R")
然后生成的pdf文件显示不能打开或损坏,此时pdf文件还不能删除(显示的是原因好像是已经在Rstudio Rsession中打开),然后我就保存之后把Rstudio关闭了。(关闭的时候就有一段报错信息)
再次重新打开Rstudio(未打开原来保存的Rhistory文件),再次输入如上GUI中的命令又出现一段报错信息如下:
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file 'script2.R': No such file or directory
请问这是为什么?
在source("script2.R")中添加文件路径试试,如果script2.R在C盘的R文件目录下,则写成:source("C:/R/script2.R"),