Bioequivalence and Bioavailability Forum

Main page Policy/Terms of Use Abbreviations Latest Posts

 Log-in |  Register |  Search

Back to the forum  Query: 2017-09-26 02:17 CEST (UTC+2h)

2017-09-01 23:23

Posting: # 17760
Views: 347

 Beyond sink() - capturing messages to file and stdout [R for BE/BA]

Hi all,

I would like to capture all messages from R (optionally all R input and output) to a file while at the same time having them on stdout as usual.
The sink() function can do either, but apparently (??) not both simultaneously which is what I'd like to use. I have no idea where to start, actually. Note: This involves shelling R under windows so stdout is stdout whether or not it is captured via a pipe into a GUI.
Alternatively, if there were a method assiciated with q() or quit() which would upon termination save all stdout info (messages+input+output; what you see on a console when you interact in e.g. R GUI or R Studio) to a txt-file post hoc then that would be equally good.

Tried google and TFM :PCchaos: Any idea how to do this?

Many thanks and a good weekend to all.

I could be wrong, but…

Best regards,

- since June 2017 having an affair with the bootstrap.
Kaohsiung, Taiwan,
2017-09-02 05:20

@ ElMaestro
Posting: # 17761
Views: 293

 Beyond sink() - capturing messages to file and stdout

Hi ElMaestro,

the meaning of 'stdout'? outputs on the console? If yes, you can try

zz<- file("output.txt",open="wt")
sink(zz,split=TRUE)  ### this will send output to the file and on the console simultaneously
sink(zz,split=FALSE)  ### this will send all outputs to the file only, but will not be on the console;default for sink(), same as sink(zz).
sink() ### this will temporarily stop sending output to the file; console output is still on.
sink(zz,split=TRUE) ### re-activate sink() again;
close(zz) ### close the output; use it before q(); otherwise, the output text file may not be complete.

I am not quite sure if I answer your question correctly or not.

All the best,
---Yung-jin Lee
[image]bear v2.8.3:- created by Hsin-ya Lee & Yung-jin Lee
Kaohsiung, Taiwan
Download link (updated) -> here

2017-09-02 08:10

@ yjlee168
Posting: # 17762
Views: 290

 Beyond sink()

Thanks yjlee168,

for trying to help.:-)

I looked at this code already, I believe it is from StackOverflow. It is an example on how to send stdout to a file, and then how to stop doing that so that messages end up on the console again. What I need is both simultaneously and that's how I am of the impression that sink() might not be the solution.
"stdout" is where dos (console) applications, for lack of better terminology, output their stuff. When we open the R GUI or other interface and type a command we are in effect only talking to R's console via a layer of handy windowing which uses stdout and stdin to communicate with R and display to us in a nice windowsy manner what is going on.
If I could save an entire session (with all R's messages) to a file then that would also be great.:confused:

I could be wrong, but…

Best regards,

- since June 2017 having an affair with the bootstrap.

2017-09-02 12:51

@ ElMaestro
Posting: # 17763
Views: 276


Hi ElMaestro,


Is that what you want (from here)?
another solution with sourcing is here

Kind regards,
Back to the forum Activity
 Thread view
Bioequivalence and Bioavailability Forum | Admin contact
17,323 Posts in 3,705 Threads, 1,068 registered users;
28 users online (0 registered, 28 guests).

It has yet to be proven
that intelligence has any survival value.    Arthur C. Clarke

BEBAC Ing. Helmut Schütz