[R] Output to connections

Adelchi Azzalini azzalini at stat.unipd.it
Tue May 20 12:43:31 CEST 2003


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 at stat.unipd.it>
Dipart.Scienze Statistiche, Università di Padova, Italia
http://azzalini.stat.unipd.it/




More information about the R-help mailing list