Benjamin Tyner
2017-Oct-23 21:53 UTC
[R] read.table(..., header == FALSE, colClasses = <vector with names attribute>)
Hello I noticed that starting with R version 3.3.0 onward, this generates a warning: ?? > txt <- c("a", "3.14") ?? > read.table(file = textConnection(txt), header = FALSE, colClasses = c(x = "character", y = "numeric")) the warning is "not all columns named in 'colClasses' exist" and I guess the change was made in response to this? ?? https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=16478 Regardless, I am wondering whether this is desirable, that as a result of the change, the code has become stricter about the presence of a (formerly) harmless names attribute. Or am I missing something? Regards Ben
Jeff Newmiller
2017-Oct-24 00:51 UTC
[R] read.table(..., header == FALSE, colClasses = <vector with names attribute>)
You are constructing the equivalent of a two-line data file, and complaining that it is not treating it like it was one line. If it did used to accept this silently [skeptical] then I for one am glad it produces a warning now. -- Sent from my phone. Please excuse my brevity. On October 23, 2017 2:53:21 PM PDT, Benjamin Tyner <btyner at gmail.com> wrote:>Hello > >I noticed that starting with R version 3.3.0 onward, this generates a >warning: > > ?? > txt <- c("a", "3.14") >?? > read.table(file = textConnection(txt), header = FALSE, colClasses >= c(x = "character", y = "numeric")) > >the warning is "not all columns named in 'colClasses' exist" and I >guess >the change was made in response to this? > > ?? https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=16478 > >Regardless, I am wondering whether this is desirable, that as a result >of the change, the code has become stricter about the presence of a >(formerly) harmless names attribute. Or am I missing something? > >Regards > >Ben > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.
Benjamin Tyner
2017-Oct-24 11:21 UTC
[R] read.table(..., header == FALSE, colClasses = <vector with names attribute>)
Jeff, Thank you for your reply. The intent was to construct a minimum reproducible example. The same warning occurs when the 'file' argument points to a file on disk with a million lines. But you are correct, my example was slightly malformed and in fact gives an error under R version 3.2.2. Please allow me to try again; in older versions of R, ?? > read.table(file = textConnection("a\t3.14"), header = FALSE, colClasses = c(x = "character", y = "numeric"), sep="\t") ? ?? V1?? V2 ?? 1? a 3.14 (with no warning). As of version 3.3.0, ?? > read.table(file = textConnection("a\t3.14"), header = FALSE, colClasses = c(x = "character", y = "numeric"), sep="\t") ? ?? V1?? V2 ?? 1? a 3.14 ?? Warning message: ?? In read.table(file = textConnection("a\t3.14"), header = FALSE,? : ? ?? not all columns named in 'colClasses' exist My intent was not to complain but rather to learn more about best practices regarding the names attribute. Regards Ben On 10/23/2017 08:51 PM, Jeff Newmiller wrote:> You are constructing the equivalent of a two-line data file, and complaining that it is not treating it like it was one line. If it did used to accept this silently [skeptical] then I for one am glad it produces a warning now.
Apparently Analagous Threads
- read.table(..., header == FALSE, colClasses = <vector with names attribute>)
- read.table(..., header == FALSE, colClasses = <vector with names attribute>)
- read.table(..., header == FALSE, colClasses = <vector with names attribute>)
- extending the colClasses argument in read.table
- excluding factor levels with read.table() and colClasses=