[R] How to write the output of a function into a file?

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed Mar 26 10:19:21 CET 2003


does sink()

do what you want?

see ?sink for more

> #divert printed results to file
> sink(file = output.txt)
> #commands here
> chisq.test(x,p=probs)
> #turn off sink
> sink(file = NULL)

If you are not typing the commands at the prompt but are using an external
editor or text file for your commands via source() then you need to wrap
chisq.test(x,p=probs) in print() eg:

print(chisq.test(x,p=probs))

Hope this helps

Gavin

%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson                     [T] +44 (0)20 7679 5522
ENSIS Research Fellow             [F] +44 (0)20 7679 7565
ENSIS Ltd. & ECRC                 [E] gavin.simpson at ucl.ac.uk
UCL Department of Geography       [W] http://www.ucl.ac.uk/~ucfagls/cv/
26 Bedford Way                    [W] http://www.ucl.ac.uk/~ucfagls/
London.  WC1H 0AP.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of yanni at cec
Sent: 25 March 2003 23:59
To: r-help
Subject: [R] How to write the output of a function into a file?


I cannot find the solutions in the mannual about "import and export of
data".
For example, I run 
>chisq.test(x,p=probs)
    chi-squared.....

.........

How can I write the output into a file? Is there some file operations in R?
Actually, I only want to save the P-value. But I don't know how I can
extract the P-value field only from the output
of chisq.test. So, I think I would better save all the output. I tried
cat/write....They cannot do this.

Thanks in advance.

	[[alternate HTML version deleted]]

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help



More information about the R-help mailing list