read_from_database takes a database connection and table name, applies a dplyr-based query, and returns either a lazy-table or a data frame of the query results.
Arguments
- db
A database connection or the path to a database file (if sqlite or duckdb file extension).
- table_name
A character string specifying the table to read from.
- query_fun
A function taking a single argument (the data.frame-like object to be queried) and returning a data frame. Default is
NULL, which does not apply a query fun. Mostdplyrfunctions will be implemented here (see dbplyr::dbplyr for details). (e.g.query_fun = \(df) df |> dplyr::select(column1, column2)) Anything else beyond variable names needs to be prefaced with!!(e.g.... |> dplyr::filter(month |> dplyr::between(!!select_months[1], !!select_months[2]))).- collect
A logical value indicating whether to use
dplyr::collect()to fetch the data from the database. Will be overidden ifpullis notNULL. Default isTRUE.- pull
A single character string to use with
dplyr::pull()to pull a column after applyingquery_fun. Default isNULL, which does not pull any columns.