Skip to content

Instantly share code, notes, and snippets.

@ClintWeathers
Last active November 4, 2015 21:51
Show Gist options
  • Save ClintWeathers/7335eea73a047caf7a0f to your computer and use it in GitHub Desktop.
Save ClintWeathers/7335eea73a047caf7a0f to your computer and use it in GitHub Desktop.
paramaterized query using ldply.R
library(RODBC)
library(RODBCext)
dbconn <- odbcConnect(dsn = "dbname", uid = "me", pwd = "password")
query <- "select * from table where blah = 'blahblahblah' and blah2 = ?"
results <- function(x){
sqlExecute(dbconn, query, x)
sqlGetResults(dbconn)
}
output <- plyr::ldply(dataframe$thingy, results, .progress = 'time')
@hadley
Copy link

hadley commented Nov 4, 2015

Rough dplyr equiv:

df <- data.frame(blah = "blahblahblah", blah2 = dataframe$thingy)
src() %>% tbl(tbl) %>% semi_join(df, copy = TRUE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment