From plummerm at iarc.fr  Thu Mar  1 18:23:04 2018
From: plummerm at iarc.fr (Martyn Plummer)
Date: Thu, 1 Mar 2018 17:23:04 +0000
Subject: [Rd] Bug report - duplicate row names with as.data.frame()
In-Reply-To: <CA+Dgj-7g35bUpULcrqKiyM8daHWOEY-MzU=7Snee6SUjQWrF6w@mail.gmail.com>
References: <CA+Dgj-7g35bUpULcrqKiyM8daHWOEY-MzU=7Snee6SUjQWrF6w@mail.gmail.com>
Message-ID: <1519924984.4751.69.camel@iarc.fr>

On Thu, 2018-03-01 at 09:36 -0500, Ron wrote:
> Hello,
> 
> I'd like to report what I think is a bug: using as.data.frame() we can
> create duplicate row names in a data frame. R version 3.4.3 (current stable
> release).
> 
> Rather than paste code in an email, please see the example formatted code
> here:
> https://stackoverflow.com/questions/49031523/duplicate-row-names-in-r-using-as-data-frame
> 
> I posted to StackOverflow, and consensus was that we should proceed with
> this as a bug report.

Yes that is definitely a bug. 

The end of the as.data.frame.matrix method has:

    attr(value, "row.names") <- row.names
    class(value) <- "data.frame"
    value

Changing this to:

    class(value) <- "data.frame"
    row.names(value) <- row.names
    value

ensures that the row.names<-.data.frame method is called with its built
-in check for duplicate names.

There are quite a few as.data.frame methods so this could be a
recurring problem. I will check.

Martyn


> Thanks,
> Ron
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Bug report - duplicate row names with as.data.frame()
Martyn Plummer