[Rd] Change in write.dcf() that breaks existing code

Herve Pages hpages at fhcrc.org
Mon Nov 26 23:59:49 CET 2007


Hi,

When writing a DCF file one record at a time, the records used
to be separated by an empty line in R-2.5, but not in R-2.6:

  x <- data.frame(aa=letters[1:3], ii=1:3)

With R-2.5:

  > x <- data.frame(aa=letters[1:3], ii=1:3)
  > for (i in seq_len(nrow(x))) write.dcf(x[i, ,drop=FALSE])
  aa: a
  ii: 1

  aa: b
  ii: 2

  aa: c
  ii: 3

With R-2.6:

  > for (i in seq_len(nrow(x))) write.dcf(x[i, ,drop=FALSE])
  aa: a
  ii: 1
  aa: b
  ii: 2
  aa: c
  ii: 3

Unfortunately, because of this change, code that used to be OK
now produces broken DCF files.
To add to the frustration, nothing is mentioned in the man page
or in the NEWS file:

  CHANGES IN R VERSION 2.6.0

    o	write.dcf() no longer writes NA fields (PR#9796), and works
	correctly on empty descriptions.

Although it seems that it was a deliberate choice. Found in base/R/dcf.R:
    ...
    if(length(eor)) {
        ## Newline for end of record.
        ## Note that we do not write a trailing blank line.
        eor[ diff(c(col(out))[is_not_empty]) >= 1 ] <- "\n"
    }
    ...

What's the benefit of this change?

Cheers,
H.



More information about the R-devel mailing list