Unveiling the Power of get_cms_meta_data() in healthyR.data
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Introduction
Hey, R users! š Today, weāre going to look at a great new addition to the healthyR.data packageāthe get_cms_meta_data()
function! This function is a helpful tool for retrieving and analyzing metadata from CMS (Centers for Medicare & Medicaid Services) datasets. Whether youāre a healthcare analyst, data scientist, or R programming fan, youāll find this function very useful. Letās break it down and explore how it works.
Overview of get_cms_meta_data()
The get_cms_meta_data()
function lets you retrieve metadata from CMS datasets easily. You can customize your search using various parameters, ensuring you get precisely the data you need. Hereās the syntax:
get_cms_meta_data( .title = NULL, .modified_date = NULL, .keyword = NULL, .identifier = NULL, .data_version = "current", .media_type = "all" )
Arguments:
.title
: Search by title..modified_date
: Search by modified date (format: āYYYY-MM-DDā)..keyword
: Search by keyword..identifier
: Search by identifier..data_version
: Choose between ācurrentā, āarchiveā, or āallā. Default is ācurrentā..media_type
: Filter by media type (āallā, ācsvā, āAPIā, āotherā). Default is āallā.
Return Value:
A tibble containing data links and relevant metadata about the datasets.
Details:
The function fetches JSON data from the CMS data URL and extracts relevant fields to create a tidy tibble. It selects specific columns, handles nested lists by unnesting them, cleans column names, and processes dates and media types to make the data more useful for analysis. The columns in the returned tibble include:
title
description
landing_page
modified
keyword
described_by
fn
has_email
identifier
start
end
references
distribution_description
distribution_title
distribution_modified
distribution_start
distribution_end
media_type
data_link
Practical Examples
Letās see the get_cms_meta_data()
function in action with a couple of examples.
Example 1: Basic Usage
First, weāll load the necessary libraries and fetch some metadata:
# Library Loads library(healthyR.data) library(dplyr) # Get data cms_data <- get_cms_meta_data() glimpse(cms_data)
Rows: 107 Columns: 19 $ title <chr> "Accountable Care Organization Participants",ā¦ $ description <chr> "The Accountable Care Organization Participanā¦ $ landing_page <chr> "https://data.cms.gov/medicare-shared-savingsā¦ $ modified <date> 2024-01-29, 2024-04-23, 2024-01-12, 2024-01-ā¦ $ keyword <list> <"Medicare", "Value-Based Care", "Coordinateā¦ $ described_by <chr> "https://data.cms.gov/resources/accountable-cā¦ $ fn <chr> "Shared Savings Program - CM", "Shared Savingā¦ $ has_email <chr> "[email protected]", "SharedSaā¦ $ identifier <chr> "https://data.cms.gov/data-api/v1/dataset/976ā¦ $ start <date> 2014-01-01, 2017-01-01, 2021-01-01, 2021-01-ā¦ $ end <date> 2024-12-31, 2024-12-31, 2021-12-31, 2021-12-ā¦ $ references <chr> "https://data.cms.gov/resources/acos-aco-partā¦ $ distribution_description <chr> "latest", "latest", "latest", "latest", "lateā¦ $ distribution_title <chr> "Accountable Care Organization Participants",ā¦ $ distribution_modified <date> 2024-01-29, 2024-04-23, 2024-01-12, 2024-01-ā¦ $ distribution_start <date> 2024-01-01, 2024-01-01, 2021-01-01, 2021-01-ā¦ $ distribution_end <date> 2024-12-31, 2024-12-31, 2021-12-31, 2021-12-ā¦ $ media_type <chr> "API", "API", "API", "API", "API", "API", "APā¦ $ data_link <chr> "https://data.cms.gov/data-api/v1/dataset/976ā¦
# Attributes atb <- attributes(cms_data) atb$names
[1] "title" "description" [3] "landing_page" "modified" [5] "keyword" "described_by" [7] "fn" "has_email" [9] "identifier" "start" [11] "end" "references" [13] "distribution_description" "distribution_title" [15] "distribution_modified" "distribution_start" [17] "distribution_end" "media_type" [19] "data_link"
atb$class
[1] "cms_meta_data" "tbl_df" "tbl" "data.frame"
atb$url
[1] "https://data.cms.gov/data.json"
atb$date_retrieved
[1] "2024-05-28 10:20:18 EDT"
atb$parameters
$.data_version [1] "current" $.media_type [1] "all" $.title NULL $.modified_date NULL $.keyword NULL $.identifier NULL
In this example, weāre simply calling get_cms_meta_data()
without any parameters. This fetches the default dataset metadata. The glimpse()
function from the dplyr
package provides a quick overview of the data structure.
Example 2: Custom Search by Keyword and Title
Now, letās refine our search by specifying a keyword and title:
get_cms_meta_data( .keyword = "nation", .title = "Market Saturation & Utilization State-County" ) |> glimpse()
Rows: 1 Columns: 19 $ title <chr> "Market Saturation & Utilization State-County" $ description <chr> "The Market Saturation and Utilization State-ā¦ $ landing_page <chr> "https://data.cms.gov/summary-statistics-on-uā¦ $ modified <date> 2024-04-02 $ keyword <list> <"National", "States & Territories", "Countieā¦ $ described_by <chr> "https://data.cms.gov/resources/market-saturā¦ $ fn <chr> "Market Saturation - CPI" $ has_email <chr> "[email protected]" $ identifier <chr> "https://data.cms.gov/data-api/v1/dataset/89ā¦ $ start <date> 2023-10-01 $ end <date> 2023-12-31 $ references <chr> "https://data.cms.gov/resources/market-saturaā¦ $ distribution_description <chr> "latest" $ distribution_title <chr> "Market Saturation & Utilization StateCounty" $ distribution_modified <date> 2024-04-02 $ distribution_start <date> 2023-10-01 $ distribution_end <date> 2023-12-31 $ media_type <chr> "API" $ data_link <chr> "https://data.cms.gov/data-api/v1/dataset/890ā¦
In this example, we filter the metadata by the keyword ānationā and the title āMarket Saturation & Utilization State-Countyā. The pipe operator (|>
) is used to pass the result directly into the glimpse()
function for a quick preview.
Breaking Down the Code
Letās break down the code blocks to understand what theyāre doing:
Basic Usage
Load Libraries:
library(healthyR.data) library(dplyr)
We load the
healthyR.data
package to access theget_cms_meta_data()
function and thedplyr
package for data manipulation.Fetch Metadata:
cms_data <- get_cms_meta_data()
We call
get_cms_meta_data()
without any parameters to get the default dataset metadata.Preview Data:
glimpse(cms_data)
The
glimpse()
function gives us a quick look at the structure and contents of the fetched metadata.
Custom Search
Custom Search Call:
get_cms_meta_data( .keyword = "nation", .title = "Market Saturation & Utilization State-County" ) |> glimpse()
Here, we call
get_cms_meta_data()
with specific parameters for keyword and title to narrow down our search. The result is passed toglimpse()
using the pipe operator for an immediate preview.
Conclusion
The get_cms_meta_data()
function is a versatile and flexible tool for accessing CMS metadata, making your data analysis tasks more efficient and effective. Whether youāre looking for specific datasets or just exploring the available metadata, this function has got you covered.
Try out get_cms_meta_data()
in your next R project and explore the potential of CMS data with ease! Happy coding! š
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.