Quantcast
Viewing all articles
Browse latest Browse all 3

How to capture install.packages output in R with sink()?

I'd like to capture all output and errors when installing a packages. The steps when installing a package, however, do not seem to be captured by the sink() command. Here's an example:

A main.R file:

fp <- file("test.log", open = 'wt')sink(fp, type = 'output')sink(fp, type = 'message')install.packages("stringr")sink(type = 'message')sink()

Using R -q -f main.R to run the file, I see the following in my console:

-> % R -q -f main.R> fp <- file("test.log", open = 'wt')> sink(fp, type = 'output')> sink(fp, type = 'message')> install.packages("stringr")* installing *source* package ‘stringr’ ...** package ‘stringr’ successfully unpacked and MD5 sums checked** using staged installation** R** data*** moving datasets to lazyload DB** inst** byte-compile and prepare package for lazy loading** help*** installing help indices*** copying figures** building package indices** installing vignettes** testing if installed package can be loaded from temporary location** testing if installed package can be loaded from final location** testing if installed package keeps a record of temporary installation path* DONE (stringr)> sink(type = 'message')> sink()>

The contents of test.log:

Installing package into ‘/home/bam/.local/share/R/R_library/library’(as ‘lib’ is unspecified)trying URL 'https://cloud.r-project.org/src/contrib/stringr_1.5.1.tar.gz'Content type 'application/x-gzip' length 176599 bytes (172 KB)==================================================downloaded 172 KBThe downloaded source packages are in‘/tmp/Rtmpp0Vylj/downloaded_packages’

Why aren't the console lines prepended with a star (*) included in the log file?


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>