show_dplyr {tidyquery} | R Documentation |
show_dplyr
takes a SQL SELECT
statement and prints
equivalent dplyr code
show_dplyr(data, sql)
data |
a data frame or data frame-like object (optional) |
sql |
a character string containing a SQL |
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.
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)