Re: [R] Regular Expressions in Column Headings

From: Gabor Grothendieck <>
Date: Wed, 09 Mar 2011 09:24:33 -0500

On Wed, Mar 9, 2011 at 8:52 AM, Matthew DeAngelis <> wrote:
> Hi all,
> I am hoping that someone can help me with a problem I am having with column
> headings.  I have read a table into R using read.table: the rows are
> documents, and the columns are counts of regular expression matches (so that
> the column heading is the given regular expression).  My problem is that
> read.table seems to be trying to interpret the regular expressions, or has
> trouble with the special characters, so that the column headings are not
> coming out correctly.  For example, a column headed with: \bV\.?A\.?T\.?
> will come out as X.bV...A...T...  This would not be a problem, since the
> regular expressions are still readable, except that I have a number of other
> tables that I will need to intersect with these column headings.  In some of
> those tables, the regular expressions are data, and they are coming in
> correctly (although R seems to be doubling "\"s, which is fine so long as it
> does this consistently).
> I have also tried importing the column names as a vector and specifying that
> vector explicitly using col.names, but R still transforms the provided names
> as above.  Is it possible to force R to read in regular expressions
> completely literally, with no interpretation?  Alternately, can I force R to
> interpret the column headings in the same way that it interprets data (i.e.
> adding the extra slash), so that I can match on these values?

See the read.table check.names argument.

Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 09 Mar 2011 - 14:27:10 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 Wed 09 Mar 2011 - 14:30:20 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive