R/cik_search.R

Defines functions cik_search

Documented in cik_search

#' SEC CIK Search
#'
#' Provides access to the SEC CIK search tool from
#' \href{https://www.sec.gov/edgar/searchedgar/cik.htm}{here}
#'
#' @param company Search term to search for CIK
#' @return A dataframe with one row per company with
#'        Includes the following columns -
#'  \itemize{
#'    \item cik
#'    \item company_href
#'    \item company_name
#'  }
#' @examples
#' \donttest{
#' try(cik_search("cloudera"))
#' }
#' @export
cik_search <- function(company) {
  href <- paste0("https://www.sec.gov/cgi-bin/cik_lookup",
                "?company=", URLencode(company, reserved = TRUE))
  res <- edgar_GET(href)
  doc <- xml2::read_html(res, base_url = href, options = "HUGE")

  entries_xpath <- "//pre/a[starts-with(@href,'browse-edgar')]"

  pieces <- list(
    cik = ".",
    company_href = "@href",
    company_name = "following-sibling::text()[1]"
  )

  trim_cols <- c("company_name")

  res <- map_xml(doc, entries_xpath, pieces, trim = trim_cols)

  return(res)
}

Try the edgarWebR package in your browser

Any scripts or data that you put into this service are public.

edgarWebR documentation built on April 24, 2021, 5:09 p.m.