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

From: Herve Pages <hpages_at_fhcrc.org>
Date: Mon, 26 Nov 2007 14:59:49 -0800


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.



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 26 Nov 2007 - 23:01:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 27 Nov 2007 - 20:30:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.