How do I log an R session to a file?

2019-01-25 05:22发布

Other than through redirection, which captures an entire session, is there a way to start and stop logging during an R session? To clarify, I am looking for something similar to the log using command in Stata.

标签: r logging stata
4条回答
Lonely孤独者°
2楼-- · 2019-01-25 05:32

For the sake of completing the answer using sink

# copy the log to a text file
sink("./logofcode.txt")
Your R code(s) goes here
you can use a stored R code as well using source()
source("./XS_SPEC_CF.R",echo=T, max.deparse.length=1e3)
sink()
查看更多
男人必须洒脱
3楼-- · 2019-01-25 05:47

Do you know about sink() in base R ?

There are also some logging packages on CRAN: logging, log4r and possibly more.

Lastly, Emacs user have ESS and its transcript mode. You can save your session as a log, and in general, the 'work from file and execute from the file' approach builds a (partial, commands-only) log as you work.

查看更多
Lonely孤独者°
4楼-- · 2019-01-25 05:47

There's savehistory(file) which will write the entire history as plaintext, or, if you're trying to log output, use sink(file, split = TRUE).

查看更多
家丑人穷心不美
5楼-- · 2019-01-25 05:48

In addition to the sink function you might also look at the txtStart and related functions in the TeachingDemos package or the similar functionality in the R2HTML package (which came first).

查看更多
登录 后发表回答