Generic function to download data from any table in the WRDS database. Returns a lazy table by default, allowing you to build queries with dplyr before collecting.
Arguments
- wrds
A
DBIConnectionobject returned bywrds_connect().- library
Character. The name of the library (schema), e.g.,
"crsp","comp","ibes".- table
Character. The name of the table within the library.
- columns
Character vector of columns to return. If
NULL(default), returns all columns. Usedescribe_table()to see available columns.- n
Maximum number of rows to return. Defaults to
Inf(all rows). Use a smaller value (e.g.,n = 100) to preview data.- lazy
If
TRUE(default), returns a lazytblfor further filtering with dplyr. Set toFALSEto collect immediately.
Details
This function provides generic access to any WRDS table. For commonly-used tables with standard research filters, prefer the specialized functions:
get_compustat()for Compustat fundamentals with standard filtersget_company()for company header datalink_ccm()for CRSP-Compustat linking
The lazy table can be filtered, selected, and mutated using dplyr verbs, which are translated to SQL and executed on the server:
See also
describe_table() to explore table structure,
list_tables() to list available tables in a library
Examples
if (FALSE) { # \dontrun{
wrds <- wrds_connect()
# Preview table structure first
describe_table(wrds, "crsp", "msf")
# Get a lazy table and build your query
get_table(wrds, "crsp", "msf") |>
dplyr::filter(date >= "2025-01-01") |>
dplyr::select(permno, date, ret, prc, vol) |>
dplyr::collect()
# Collect immediately with specific columns
get_table(wrds, "crsp", "dsf",
columns = c("permno", "date", "ret", "prc"),
lazy = FALSE,
n = 1000
)
# Access any table in any library
get_table(wrds, "ibes", "statsum_epsus") |>
dplyr::filter(fpedats >= "2025-01-01") |>
dplyr::collect()
wrds_disconnect(wrds)
} # }