--- title: "Getting started with tensorust" output: markdown::html_format vignette: > %\VignetteIndexEntry{Getting started with tensorust} %\VignetteEngine{knitr::knitr} %\VignetteEncoding{UTF-8} --- ```{r setup, include = FALSE} knitr::opts_chunk$set(collapse = TRUE, comment = "#>") # This vignette is built from API answers cached in inst/extdata, so it never # touches the network. Run the same code yourself to get live data. fixture <- function(req, file, type = "application/json") { path <- system.file("extdata", file, package = "tensorust", mustWork = TRUE) httr2::response( status_code = 200L, url = req$url, headers = list(`Content-Type` = type), body = readBin(path, "raw", file.info(path)$size) ) } cached_api <- function(req) { path <- sub("^.*/api/", "", httr2::url_parse(req$url)$path) switch(path, "datasets" = fixture(req, "datasets.json"), "datasets/afida-foreign-farmland" = fixture(req, "sample_afida-foreign-farmland.csv", "text/csv"), "openbb/bdc_marks" = fixture(req, "bdc_marks.json"), "openbb/credit_disagreements" = fixture(req, "credit_disagreements.json"), "openbb/credit_q3_cuts" = fixture(req, "credit_q3_cuts.json"), "openbb/exposure_institution" = fixture(req, "exposure_institution.json"), "exposure" = fixture(req, "exposure_list.json") ) } httr2::local_mocked_responses(cached_api, env = environment()) old_opts <- options(width = 100) old_key <- Sys.getenv("TENSORUST_API_KEY", unset = NA) Sys.unsetenv("TENSORUST_API_KEY") ``` tensorust reads the 'Tensorust' data API from R and returns tibbles. It covers three things: * **Private credit marks.** Business development companies (BDCs) report a fair value for each private loan in their quarterly 10-Q filings. Several BDCs often lend to the same company, and their marks for the same first-lien loan can sit tens of points apart. * **Banned-vendor exposure.** Federal research awards whose recent papers name a vendor on a US banned-vendor list (1260H, BIOSECURE, UFLPA, Section 889, FCC Covered List). * **The dataset catalog.** About 145 entity-level datasets with free samples. ```{r} library(tensorust) ``` ## Keys Every call works without a key and returns a free preview, such as the top 10 rows. With a key, the same call returns every row. Put the key in your `.Renviron` file so it is never in your scripts: ``` TENSORUST_API_KEY=tdk_your_key_here ``` ```{r} tr_has_key() ``` Keys are at . ## Where lenders disagree `tr_credit_disagreements()` lists the companies whose loan two or more BDC managers mark 10 or more points of par apart, widest gap first. ```{r} gaps <- tr_credit_disagreements() gaps[, c("company", "gap_points", "lowest_manager", "lowest_mark_pct_of_par", "highest_manager", "highest_mark_pct_of_par")] ``` `tr_lender_marks()` shows every fund's mark for the companies you name. It takes a vector, and the `query` column records which name each row answers. ```{r} tr_lender_marks("Pluralsight") ``` ## Third-quarter markdowns `tr_q3_cuts()` follows the third-quarter 10-Qs as they post. Each row is a fund that cut its mark by 5 or more points from June 30 to September 30. `holders_not_filed_yet_above` counts the other lenders that have not filed yet and still carry the same loan higher, which is where the next cut is likely to show up. ```{r} cuts <- tr_q3_cuts() cuts[, c("company", "manager", "jun30_pct_of_par", "sep30_pct_of_par", "change_points", "filed")] ``` A quick summary by manager, in base R: ```{r} aggregate(change_points ~ manager, data = cuts, FUN = min) ``` ## Banned-vendor exposure of federal awards Ask for one institution's awards: ```{r} stanford <- tr_exposure(institution = "Stanford University") stanford[, c("award", "agency", "fy25_obligations", "vendors", "lists", "in_force_or_no_grace")] ``` Or for the largest awards on one list. The totals across every matching award come back in the `summary` attribute: ```{r} on_1260h <- tr_exposure(list = "1260H", limit = 3) on_1260h[, c("award", "recipient", "vendors", "rule_status")] str(attr(on_1260h, "summary")) ``` ## The dataset catalog ```{r} catalog <- tr_datasets() catalog[, c("slug", "name", "category")] ``` Datasets with a free sample have a `sample_csv` link. `tr_sample()` reads it: ```{r} farmland <- tr_sample("afida-foreign-farmland") farmland[, c("state", "county", "parcels", "acres_total_foreign")] ``` ```{r cleanup, include = FALSE} options(old_opts) if (!is.na(old_key)) Sys.setenv(TENSORUST_API_KEY = old_key) ```