Re: [Rd] (PR#9796) write.dcf/read.dcf cycle converts missing entry

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Thu, 19 Jul 2007 11:37:59 +0100 (BST)

On Wed, 18 Jul 2007, Bill Dunlap wrote:

> On Wed, 18 Jul 2007 ripley@stats.ox.ac.uk wrote:
>
>> I am seeing some problems here, for example when all the fields are
>> missing, or all the fields in a row are missing. I've fixes for those,
>> and will commit to R-devel shortly.
>
> write.dcf() is also used by print.packageDesription() so
> this change affects how missing fields are printed there.
> In 2.5 we got
> > packageDescription("base", fields=c("Version","NoSuchField"))
> Version: 2.5.0
> NoSuchField: NA
>
> -- File: /dept/devel/sw/R/R.linux.2.5.0/lib/R/library/base/DESCRIPTION
> -- Fields read: Version, NoSuchField
> and now it doesn't print anything about the non-existant field
> > packageDescription("base", fields=c("Version","NoSuchField"))
> Version: 2.6.0
> -- File: /homes/bill/R-svn/r-devel/R/library/base/DESCRIPTION
> -- Fields read: Version, NoSuchField
> If this isn't acceptable then write.dcf will need a new argument
> to control the printing of missing lines.
>
> The missing trailing blank line is an inadvertant change (although
> it makes appending fields to a single record dcf file possible).

I've put in patches to address both of those issues.

Brian

>>> If you read a dcf file with read.dcf(file,fields=c("Field",...))
>>> and the file does not contain the desired field "Field",
>>> read.dcf puts a character NA for that entry in its output
>>> matrix. If you then call write.dcf, passing it the output
>>> of read.dcf(), it will write the entry "Field: NA". A subsequent
>>> read.dcf() on write.dcf's output file will then have a "NA",
>>> not a character NA, in the entry for "Field". I think that
>>> write.dcf() should not write lines in the output file where
>>> the input matrix contains a character NA.
>>> ...
>>> The diff would be
>>> 19,22c19,24
>>> < eor <- character(nr * nc)
>>> < eor[seq.int(1, nr - 1) * nc] <- "\n"
>>> < writeLines(paste(formatDL(rep.int(colnames(x), nr), c(t(x)),
>>> < style = "list", width = width, indent = indent), eor,
>>> ---
>>>> tx <- t(x)
>>>> not.na <- c(!is.na(tx))
>>>> eor <- character(sum(not.na))
>>>> eor[ c(diff(c(col(tx))[not.na]),0)==1 ] <- "\n"
>>>> writeLines(paste(formatDL(rep.int(colnames(x), nr), c(tx),
>>>> style = "list", width = width, indent = indent)[not.na], eor,
>
> [ The ==1 should be >=1 ]
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu 19 Jul 2007 - 10:48:44 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 Thu 19 Jul 2007 - 14:36:49 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.