[R] how to write text into a file

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Fri May 9 01:32:41 CEST 2003


On 08-May-03 Xirui Yang wrote:
> Hello,
> 
> Would somebody tell me how to write the text result into a postscript
> file?  The command postscript() sents only the graphics output into
> PostScript files.

Thinking I might have an answer to Xirui's problem, I tried the
following.

Using R in Linux, which has the program 'enscript' for converting
a text file as it would appear on screen into PostScript:
based on examples given in "?pipe" and "?cat", I can make the
following work for making a postscript file which will display R
output as it normally appears on screen:

Ex 1:
  zz<-pipe("enscript -o tempout.ps","w")
  cat(format(round(rnorm(100),4)),sep="\n",file=zz)
  close(zz)

[ 2 pages * 1 copy ] left in tempout.ps

However, when I try the same idea for something more complicated:
Ex 2:
  ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
  trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
  group <- gl(2,10,20, labels=c("Ctl","Trt"))
  weight <- c(ctl, trt)
  zz<-pipe("enscript -o tempout.ps","w")
  cat(anova(lm.D9 <- lm(weight ~ group)),sep="\n",file=zz)

I get the error message:

Error in cat(list(...), file, sep, fill, labels, append) : 
        argument 1 not yet handled by cat

Am I doing something wrong, or is there a gap in this area?

Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 09-May-03                                       Time: 00:32:41
------------------------------ XFMail ------------------------------




More information about the R-help mailing list