How to catch dplyr request in string

When using the package dplyrto manage tables in the database, it creates a sql statement that can be viewed using the function show_query. This operator sql is not performed, except when you call head, compute, collector collapse. In some cases, the sql statement generated dplyris more important than its execution (for example: to create functions for operations that are not yet implemented in some database packages, for example copy (subquery) into file_name;)

I want to know: how to get sql created dplyrand put it in a string?

+4
source share
2 answers

Ok. dbplyr, , dbplyr::sql_render sql , sql:

sql_query = dbplyr::sql_render(tbl_table)
+4

show_query() SQL-, dplyr, . res SQL- dplyr, sql capture.output(). output, paste(tail(output, -1),collapse="") , . ( , "".)

## Capture 
output <- capture.output(res %>% show_query(), type="message")
## Concatenate character vector to a one length character vector
final_output <- paste(tail(output, -1), collapse="")
+2

Source: https://habr.com/ru/post/1684902/


All Articles