show_dplyr {tidyquery} | R Documentation |
Show dplyr code equivalent to a SQL query
Description
show_dplyr
takes a SQL SELECT
statement and prints
equivalent dplyr code
Usage
show_dplyr(data, sql)
Arguments
data |
a data frame or data frame-like object (optional) |
sql |
a character string containing a SQL |
Details
For more details, see query
. Instead of running the
dplyr code like query
does, show_dplyr
prints the dplyr code.
In function calls in the printed code, long lists of arguments may be
truncated and appended with ...
if you have an older version of the
rlang package installed. To fix this, update to a newer version of rlang.
See Also
Examples
library(dplyr)
library(nycflights13)
query <- "SELECT origin, dest,
COUNT(flight) AS num_flts,
round(AVG(distance)) AS dist,
round(AVG(arr_delay)) AS avg_delay
FROM flights
WHERE distance BETWEEN 200 AND 300
AND air_time IS NOT NULL
GROUP BY origin, dest
HAVING num_flts > 5000
ORDER BY num_flts DESC, avg_delay DESC
LIMIT 100;"
show_dplyr(query)
[Package tidyquery version 0.2.4 Index]