Running Statements from Base R over sqlQuery()

I am working with the R programming language. I am trying to remove columns from my data frame which have the same names. For data frames within the global environment, I was able to do this successfully :

my_data = data.frame(var1 = c(1,2,3), var2 = c(1,2,9),  var1 = c(5,6,3),  check.names = FALSE)

head(my_data)

  var1 var2 var1
1    1    1    5
2    2    2    6
3    3    9    3

library(dplyr)

no_dup <-    my_data %>%    subset(., select = which(!duplicated(names(.))))

  var1 var2
1    1    1
2    2    2
3    3    9

My Question: I would like to run this code over RODBC/sqlQuery() . For instance, does anyone know if it is possible to run the following code?

library(RODBC)
library(sqldf)

con = odbcConnect("some name", uid = "some id", pwd = "abc")

#not sure if this is correct?
sample_query = sqlQuery(con, "my_data %>%    subset(., select = which(!duplicated(names(.))))
")

Can someone please tell me if this is correct?

Thanks!

The sqlQuery() function purpose is to send a sql query to an ODBC database, it doesn't translate any kind of R commands into sql language.

As I have told you before the dbplyrpackage performs language translations under the hood for some dplyr functions but not all of them, so for the more complex transformations you would need to come up with a translation yourself.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.