4 回答
TA贡献1827条经验 获得超8个赞
您必须分别接收“输出”和“消息”(该sink功能仅查看的第一个元素type)
现在,如果您也想记录输入内容,则将其放在脚本中:
脚本
1:5 + 1:3 # prints and gives a warning
stop("foo") # an error
并在提示符下:
con <- file("test.log")
sink(con, append=TRUE)
sink(con, append=TRUE, type="message")
# This will echo all input and not truncate 150+ character lines...
source("script.R", echo=TRUE, max.deparse.length=10000)
# Restore output to console
sink()
sink(type="message")
# And look at the log...
cat(readLines("test.log"), sep="\n")
TA贡献1829条经验 获得超13个赞
如果可以访问命令行,则可能更喜欢使用R CMD BATCH从命令行运行脚本。
==脚本内容的开始R ==
a <- "a"
a
How come I do not see this in log
==脚本的最终内容R ==
在命令提示符下(许多un * x变量中为“ $”,Windows中为“ C:>”),运行
$ R CMD BATCH script.R &
尾随的“&”是可选的,并在后台运行命令。日志文件的默认名称在扩展名后附加了“ out”,即script.Rout
==开始脚本内容.Rout ==
R version 3.1.0 (2014-04-10) -- "Spring Dance"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: i686-pc-linux-gnu (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.
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]
> a <- "a"
> a
[1] "a"
> How come I do not see this in log
Error: unexpected symbol in "How come"
Execution halted
==脚本的最终内容。Rout==
- 4 回答
- 0 关注
- 1619 浏览
添加回答
举报