Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch a dplyr query in a string

Tags:

r

dplyr

When using the dplyr package to manipulate tables in a database, it creates a sql statement that can be viewed by the show_query function. This sql statement is not executed except if you call head, compute, collect or collapse. In some cases, the sql statement generated by dplyr is more important than its execution (for example: to create functions for operations not yet implemented in some database packages, like copy (subquery) into file_name;)

I want to know: how do I get the sql created by dplyr and put it in a string?

like image 522
Fabio Vaz Avatar asked Sep 01 '17 14:09

Fabio Vaz


1 Answers

Ok. Looking into dbplyr source, I found that dbplyr::sql_render return the table sql statement, which can be used to compound another sql:

sql_query = dbplyr::sql_render(tbl_table)
like image 127
Fabio Vaz Avatar answered Oct 01 '22 19:10

Fabio Vaz