Skip to contents

This function takes an npi_results S3 object returned by npi_search and flattens its list columns. It unnests the lists columns and left joins them by npi. You can optionally specify which columns from df to include.

Usage

# S3 method for npi_results
npi_flatten(df, cols = NULL, key = "npi")

Arguments

df

A data frame containing the results of a call to npi_search.

cols

If non-NULL, only the named columns specified here will be be flattened and returned along with npi.

key

A quoted column name from df to use as a matching key. The default value is "npi".

Value

A data frame (tibble) with flattened list columns.

Details

The names of unnested columns are prefixed by the name of their originating list column to avoid name clashes and show their lineage. List columns containing all NULL data will be absent from the result because there are no columns to unnest.

Examples

# Flatten all list columns
data(npis)
npi_flatten(npis)
#> # A tibble: 48 × 42
#>           npi basic_fi…¹ basic…² basic…³ basic…⁴ basic…⁵ basic…⁶ basic…⁷ basic…⁸
#>         <int> <chr>      <chr>   <chr>   <chr>   <chr>   <chr>   <chr>   <chr>  
#>  1 1194276360 ALYSSA     COWNAN  PA      NO      F       2016-1… 2018-0… A      
#>  2 1194276360 ALYSSA     COWNAN  PA      NO      F       2016-1… 2018-0… A      
#>  3 1306849641 MARK       MOHRMA… MD      NO      M       2005-0… 2019-0… A      
#>  4 1306849641 MARK       MOHRMA… MD      NO      M       2005-0… 2019-0… A      
#>  5 1306849641 MARK       MOHRMA… MD      NO      M       2005-0… 2019-0… A      
#>  6 1306849641 MARK       MOHRMA… MD      NO      M       2005-0… 2019-0… A      
#>  7 1326403213 RAJEE      KRAUSE  AGPCNP… NO      F       2015-1… 2019-0… A      
#>  8 1326403213 RAJEE      KRAUSE  AGPCNP… NO      F       2015-1… 2019-0… A      
#>  9 1326403213 RAJEE      KRAUSE  AGPCNP… NO      F       2015-1… 2019-0… A      
#> 10 1326403213 RAJEE      KRAUSE  AGPCNP… NO      F       2015-1… 2019-0… A      
#> # … with 38 more rows, 33 more variables: basic_name <chr>,
#> #   basic_name_prefix <chr>, basic_middle_name <chr>,
#> #   basic_organization_name <chr>, basic_organizational_subpart <chr>,
#> #   basic_authorized_official_credential <chr>,
#> #   basic_authorized_official_first_name <chr>,
#> #   basic_authorized_official_last_name <chr>,
#> #   basic_authorized_official_middle_name <chr>, …

# Only flatten specified columns
npi_flatten(npis, cols = c("basic", "identifiers"))
#> # A tibble: 12 × 25
#>           npi basic_fi…¹ basic…² basic…³ basic…⁴ basic…⁵ basic…⁶ basic…⁷ basic…⁸
#>         <int> <chr>      <chr>   <chr>   <chr>   <chr>   <chr>   <chr>   <chr>  
#>  1 1194276360 ALYSSA     COWNAN  PA      NO      F       2016-1… 2018-0… A      
#>  2 1306849641 MARK       MOHRMA… MD      NO      M       2005-0… 2019-0… A      
#>  3 1326403213 RAJEE      KRAUSE  AGPCNP… NO      F       2015-1… 2019-0… A      
#>  4 1346604592 SARAH      LOWRY   OTR/L   YES     F       2016-0… 2018-0… A      
#>  5 1427454529 YONGHONG   TAN     NA      NO      F       2014-1… 2018-1… A      
#>  6 1558362566 AMY        TIERST… M.D.    YES     F       2005-0… 2019-0… A      
#>  7 1558713628 ROBYN      NOHLING FNP-BC… YES     F       2016-0… 2018-0… A      
#>  8 1639173065 SAKSHI     DUA     M.D.    YES     F       2005-0… 2019-0… A      
#>  9 1639173065 SAKSHI     DUA     M.D.    YES     F       2005-0… 2019-0… A      
#> 10 1639173065 SAKSHI     DUA     M.D.    YES     F       2005-0… 2019-0… A      
#> 11 1790786416 NOAH       GOLDMAN M.D.    NO      M       2005-0… 2018-0… A      
#> 12 1962983775 NA         NA      NA      NA      NA      2018-0… 2018-0… A      
#> # … with 16 more variables: basic_name <chr>, basic_name_prefix <chr>,
#> #   basic_middle_name <chr>, basic_organization_name <chr>,
#> #   basic_organizational_subpart <chr>,
#> #   basic_authorized_official_credential <chr>,
#> #   basic_authorized_official_first_name <chr>,
#> #   basic_authorized_official_last_name <chr>,
#> #   basic_authorized_official_middle_name <chr>, …