show_dplyr: Show dplyr code equivalent to a SQL query

View source: R/show_dplyr.R

show_dplyrR 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 SELECT statement

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 ....

See Also

query

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)

ianmcook/tidyquery documentation built on Jan. 26, 2023, 3:22 p.m.