ElMaestro
★★★

Denmark,
2017-09-02 01:23
(2399 d 09:17 ago)

Posting: # 17760
Views: 5,359
 

 Beyond sink() - capturing messages to file and stdout [🇷 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.

Pass or fail!
ElMaestro
yjlee168
★★★
avatar
Homepage
Kaohsiung, Taiwan,
2017-09-02 07:20
(2399 d 03:20 ago)

@ ElMaestro
Posting: # 17761
Views: 4,647
 

 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
bear v2.9.1:- created by Hsin-ya Lee & Yung-jin Lee
Kaohsiung, Taiwan https://www.pkpd168.com/bear
Download link (updated) -> here
ElMaestro
★★★

Denmark,
2017-09-02 10:10
(2399 d 00:29 ago)

@ yjlee168
Posting: # 17762
Views: 4,571
 

 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:

Pass or fail!
ElMaestro
mittyri
★★  

Russia,
2017-09-02 14:51
(2398 d 19:48 ago)

@ ElMaestro
Posting: # 17763
Views: 4,600
 

 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
UA Flag
Activity
 Admin contact
22,957 posts in 4,819 threads, 1,640 registered users;
64 visitors (0 registered, 64 guests [including 4 identified bots]).
Forum time: 09:40 CET (Europe/Vienna)

Nothing shows a lack of mathematical education more
than an overly precise calculation.    Carl Friedrich Gauß

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5