View source: R/dl-provider-data.R
fetch_provider_data | R Documentation |
This function retrieves provider data from the provided link and returns it as a tibble with cleaned names or downloads the data as a CSV file if the link ends in .csv. This function is intended to be used with the CMS provider data API.
fetch_provider_data(.data_link, .limit = 500)
.data_link |
A character string containing the URL to fetch data from. |
.limit |
An integer specifying the maximum number of rows to fetch. Default is 500. If set to 0, all records will be returned. |
The function sends a request to the provided URL using httr2::request
and
httr2::req_perform
. If the response status is not 200, it stops with an
error message indicating the failure. If the URL ends in .csv, it uses utils::download.file
to download the CSV file to a directory chosen by the user. Otherwise, the
response body is parsed as JSON and converted into a tibble using
dplyr::as_tibble
. The column names are cleaned using janitor::clean_names
,
and any character columns are stripped of leading and trailing whitespace
using stringr::str_squish
. The default limit for a return on records is 500.
If the limit is set to 0, all records will be returned.
A tibble containing the fetched data with cleaned names, or downloads
a CSV file to the user-selected directory. If an error occurs, returns NULL
.
get_provider_meta_data
library(dplyr)
# Example usage:
data_url <- "069d-826b"
df_tbl <- fetch_provider_data(data_url, .limit = 1)
df_tbl |>
glimpse()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.