How to prevent dbReadTable from changing column names

Clash Royale CLAN TAG#URR8PPP
How to prevent dbReadTable from changing column names
I am using the DBI package to read data from a SQL Server database. The function dbReadTable automatically changes the columns names to replace spaces with dots.
DBI
dbReadTable
Is there a way to control what get replace by what and or to not change anything?
The reason for this is, earlier I was using RODBC package with sqlQuery function which does not change the column names and there is a lot of code already written with old column names.
RODBC
sqlQuery
1 Answer
1
This really depends on the DBI backend you're using. You could try:
dbReadTable(..., check.names = FALSE)
If you need a custom renaming strategy (e.g. replacing spaces by underscores) you need to read in with names unchanged and implement the renaming yourself:
clean_names <- function(x)
gsub(" ", "_", x)
data <- dbReadTable(.......)
names(data) <- clean_names(names(data))
Can you please rephrase "replacement for space"? See r-dbi.org for a very brief overview.
– krlmlr
Aug 13 at 18:26
"replacement for space": by default dbReadTable replaces a space in the column name with a dot. I want to replace the space in column name by an underscore "_" instead.
– Ashish Singhal
Aug 13 at 20:58
@AshishSinghal: Edited answer.
– krlmlr
Aug 13 at 21:53
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thanks! This works for keeping the column names intact but can I control the replacement for space? Also what does DBI backend mean?
– Ashish Singhal
Aug 13 at 14:41