[R] Output to connections

About this list Date view Thread view Subject view Author view Attachment view

From: Adelchi Azzalini (azzalini@stat.unipd.it)
Date: Tue 20 May 2003 - 20:43:31 EST


Message-id: <20030520104331.7FFD27CA824@tango.stat.unipd.it>


In the document "R Data Import/Export", section "Output to connections",
there is the following portion of code:

  ## convert decimal point to comma in output, using a pipe (Unix)
  zz <- pipe(paste("sed s/\\./,/ >", "outfile"), "w")
  cat(format(round(rnorm(100), 4)), sep = "\n", file = zz)
  close(zz)
  ## now look at the output file:
  file.show(outfile, delete.file = TRUE)

Surely the last fine must be
  file.show("outfile", delete.file = TRUE)
However this is not the problem, but the fact that I get something like
,1.6861
,0.1934
,0.5640
,0.5741
,0.1920
,0.1898
,1.4788
,0.1706
,0.9953
<..snipped..>

If I run from R:
  zz <- file("outfile", "w")
  cat(format(round(rnorm(10), 4)), sep = "\n", file = zz)
  close(zz)
and then from outside R:
  sed s/\\./,/ outfile
then I get it right (of course), something like
-1,3612
-0,9772
 0,1524
 2,4046
 0,4741
 0,6659
-0,8277
 0,5071
 0,7190
 0,4088

This is fine, but it would be good to have it working in first form.
 
environment: R 1.7.0 on Debian linux.

regards,

Adelchi Azzalini

-- 
Adelchi Azzalini  <azzalini@stat.unipd.it>
Dipart.Scienze Statistiche, Università di Padova, Italia
http://azzalini.stat.unipd.it/

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


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Tue 01 Jul 2003 - 09:11:50 EST