2

The database I am querying does not respect case when it comes to column names. for example the following columns exist in different tables:

PERSONID PERSONiD PersonID Personid PersonId

Using standard d(b)plyr verbs is getting very frustrating. Is it possible to turn off the case sensitivity for dbplyr verbs?

kmace
  • 1,994
  • 3
  • 23
  • 39
  • 1
    what database platform are you using? – hrbrmstr Sep 01 '18 at 02:11
  • PostgreSQL for example returns column names in all lower case, while Oracle returns them in all upper case. If you want to write code that will run on either platform, you have this problem. – Andrew Schulman May 13 '19 at 22:49

3 Answers3

2

You can change all of the column names of your result to a consistent case with rename_all. For example to make them all lower case:

rename_all(df, tolower)
Andrew Schulman
  • 3,395
  • 1
  • 21
  • 23
1

I think this can be done by using regular expression when selecing data columns.

A very much similar question with answer can be found at select-columns-of-data-table-based-on-regex.

In your case, regular expression might be written as [Pp][Ee][Rr][Ss][Ii][Dd].

Phoenix Mu
  • 648
  • 7
  • 12
0

Or you can change the column names of your dataframe (df) to lowercase using:

 names(df) <- tolower(names(df))
Shirin Yavari
  • 626
  • 4
  • 6