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 ... if you have an older version of the rlang package installed. To fix this, update to a newer version of rlang.

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)

tidyquery documentation built on Jan. 14, 2023, 5:07 p.m.