MyNixOS website logo
Description

Access 'Wharton Research Data Services' ('WRDS').

Provides simple functions for accessing data from 'Wharton Research Data Services' ('WRDS'), a widely used financial database in academic research. Includes credential management via the system keyring, database tools, and functions for downloading generic tables, 'Compustat' fundamentals, and linking tables.

wrds

Simple functions for accessing data from Wharton Research Data Services (WRDS).

Installation

Install from CRAN:

install.packages("wrds")

Or install the development version from GitHub:

# install.packages("pak")
pak::pak("statzhero/wrds")

Setup

Before first use, store your WRDS credentials securely:

library(wrds)
wrds_set_credentials()

Credentials are stored in your system's keyring (Keychain on macOS, Credential Manager on Windows).

Usage

Explore

library(wrds)

wrds <- wrds_connect()

# Discover available data
list_libraries(wrds)
list_tables(wrds, "comp")

# Inspect table structure
describe_table(wrds, "comp", "funda", max_cols = 5)
#> comp.funda
#> Rows: 929,001
#> Columns: 948
#> $ gvkey    <chr>  "001000", "001000", "001000", "001000", "001000", ...
#> $ datadate <date> 1961-12-31, 1962-12-31, 1963-12-31, 1964-12-31, ...
#> $ fyear    <int>  1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, ...
#> $ indfmt   <chr>  "INDL", "INDL", "INDL", "INDL", "INDL", "INDL", "INDL", ...
#> $ consol   <chr>  "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", ...
#> # ... with 943 more columns

To browse interactively in the Positron or RStudio Connections pane:

library(connections)
connection_view(wrds)

Download

Pre-built functions for common datasets:

# Compustat annual fundamentals (North America)
funda <- get_compustat(wrds,
  start_date = "2024-01-01",
  end_date = "2025-12-31"
)

# Compustat quarterly (Global)
g_fundq <- get_compustat(wrds,
  frequency = "quarterly",
  region = "global",
  start_date = "2025-01-01"
)

# Company header data (SIC, NAICS, state, etc.)
company <- get_company(wrds)

# Linking tables
ccm <- link_ccm(wrds)
ibes_link <- link_ibes_crsp(wrds)

# Preview before downloading
preview <- get_compustat(wrds, n = 100)

# Historical SIC codes are included by default
get_compustat(wrds, n = 100) |> dplyr::count(sich)
#> # A tibble: 4 × 2
#>    sich     n
#>   <int> <int>
#> 1  4841     1
#> 2  5080    24
#> 3  5712     3
#> 4    NA    72

# Fill missing historical SIC codes with SIC from comp.company
get_compustat(wrds, fill_sic = TRUE, n = 100) |> dplyr::count(sic)
#> # A tibble: 8 × 2
#>   sic       n
#>   <chr> <int>
#> 1 3089     17
#> 2 3825     13
#> 3 3949      3
#> 4 4841      2
#> 5 4911      1
#> 6 5080     46
#> 7 5712     10
#> 8 5812      8

wrds_disconnect(wrds)

Custom queries

Access any table and build queries with dplyr:

# Filter CRSP monthly returns for specific stocks
big_tech <- c(14593, 90319, 13407)  # Apple, Alphabet, Meta
get_table(wrds, "crsp", "msf") |>
  filter(permno %in% big_tech, date >= "2020-01-01") |>
  select(permno, date, ret, prc, shrout) |>
  collect()

# Lazy queries for large datasets
get_compustat(wrds, lazy = TRUE) |>
  filter(fyear >= 2000) |>
  select(gvkey, datadate, at, sale) |>
  collect()

Non-standard usage

get_compustat() applies standard research filters by default. You can customize these for specialized analyses:

# Financial services firms (banks, insurance, etc.)
# Default indfmt = "INDL" excludes these
get_compustat(wrds, indfmt = "FS", n = 100)

# Include non-consolidated statements
# Default consol = "C" returns only consolidated
get_compustat(wrds, consol = "B", n = 100)

# Add columns beyond the defaults
get_compustat(wrds, add_columns = c("emp"), n = 100)

# Specify your own column list (replaces defaults)
get_compustat(wrds, columns = c("gvkey", "datadate", "at", "lt", "seq"), n = 100)

Default filters by region:

FilterNorth AmericaGlobal (without US)
datafmt"STD""HIST_STD"
popsrc"D" (domestic)"I" (international)
indfmt"INDL""INDL"
consol"C""C"

To inspect the default columns and table names for any frequency/region combination:

wrds:::compustat_config("annual", "na")
wrds:::compustat_config("quarterly", "global")

Functions

FunctionDescription
wrds_connect()Connect to WRDS using keyring credentials
wrds_disconnect()Close connection
wrds_set_credentials()Store credentials in system keyring
list_libraries()List available schemas
list_tables()List tables in a schema
describe_table()Glimpse table structure and sample values
get_table()Generic access to any WRDS table
get_compustat()Download Compustat fundamentals
get_company()Download Compustat company header data
link_ccm()Get CRSP-Compustat linking table
link_ibes_crsp()Get IBES-CRSP linking table

References

Metadata

Version

0.0.1

License

Unknown

Platforms (78)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows