I have a condition list with values of '1349','1350','1351','1352' which derived from data frame df dynamically. How can I make in_list as one string and comma between numbers, like '1349','1350','1351','1352'. So, I can pass in_list to sqlQuery where statement with dynamical values?
df <- data.frame(
run_id = c(1349L,1349L,1349L,1350L,1350L,1351L,
1351L,1349L,1350L,1351L,1349L,1350L,1351L,1349L,1350L,
1351L,1349L,1350L,1351L,1349L,1350L,1351L,1349L,1350L,
1351L,1349L,1350L,1351L,1349L,1350L,1351L,1349L,1350L,
1351L,1349L,1350L,1351L,1349L,1350L,1351L,1349L,1350L,
1351L,1349L,1350L,1351L,1349L,1350L,1351L,1349L,1349L,
1350L,1349L,1350L,1349L,1350L,1349L,1350L,1349L,1350L,
1349L,1350L,1349L,1350L,1349L,1350L,1349L,1350L,1349L,
1350L,1349L,1350L,1349L,1350L,1349L,1350L,1349L,1350L,
1349L,1350L,1349L,1350L,1351L,1352L,1349L,1350L,1351L,
1352L,1349L,1350L,1351L,1352L,1349L,1350L,1351L,1352L,
1349L,1350L,1351L,1352L,1349L,1350L,1351L,1349L,1350L,
1351L,1349L,1352L,1349L,1350L,1351L,1352L,1349L,1352L,
1349L,1349L,1350L,1351L,1349L,1349L,1350L,1351L,1352L,
1349L,1350L,1351L,1352L,1349L,1350L,1351L,1352L,1349L,
1350L,1351L,1352L,1349L,1351L,1352L,1349L,1350L,1351L,
1352L,1349L,1350L,1351L,1352L,1349L,1350L,1351L,1352L,
1349L,1350L,1351L,1350L,1351L,1349L,1350L,1351L,1349L,
1350L,1351L,1349L,1350L,1351L,1349L,1350L,1351L,1349L,
1350L,1351L,1349L,1350L,1351L,1349L,1350L,1351L,1349L,
1350L,1351L,1349L)
)
id <- df %>% select(run_id) %>% unique()
in_list <- as.character(as.character(id$run_id))
I've been blocked here. Does anyone have better way to do this? I think something like:
sql_stmt <- glue("select * from df2 where run_id in({in_list})")
sql_tab <- sqlQuery(odbcChannel2, sql_stmt, as.is = TRUE)
Instead of hard-coded
sql_tab <- sqlQuery(odbcChannel2, "select * from df2 where
run_id in ('1349','1350','1351','1352')", as.is = TRUE)