Bioequivalence and Bioavailability Forum

Main page Policy/Terms of Use Abbreviations Latest Posts

 Log-in |  Register |  Search

Back to the forum  Query: 2017-09-23 22:05 CEST (UTC+2h)
 
ElMaestro
Hero

Denmark,
2017-09-01 23:23

Posting: # 17760
Views: 334
 

 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,
ElMaestro

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

@ ElMaestro
Posting: # 17761
Views: 280
 

 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 http://pkpd.kmu.edu.tw/bear
Download link (updated) -> here
ElMaestro
Hero

Denmark,
2017-09-02 08:10

@ yjlee168
Posting: # 17762
Views: 278
 

 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,
ElMaestro

- since June 2017 having an affair with the bootstrap.
mittyri
Senior

Russia,
2017-09-02 12:51

@ ElMaestro
Posting: # 17763
Views: 263
 

 TeachingDemos?

Hi ElMaestro,

library(TeachingDemos)
txtStart("temp.txt")
1:10
txtStop()

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

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

It’s easy to lie with statistics;
it is easier to lie without them.    Frederick Mosteller

The BIOEQUIVALENCE / BIOAVAILABILITY FORUM is hosted by
BEBAC Ing. Helmut Schütz
XHTML/CSS RSS Feed