title: Assistance understanding why my custom function can be applied to a character vector but not a data frame
body: <p>I have hacked together a function that pulls data from a U.S. government API when provided a character vector of NPI IDs.</p>
  <pre><code>providerIDs &lt;- c('1982812681','1336201888','1902121692','1164496618','1073557641','1255522488','1679705214','1467719260')
  </code></pre>
  <p>I have since pulled a list of thousands of IDs from a database that I need to pass into my function to pull the correct information for.</p>
  <pre><code>providerIDs &lt;- c('1982812681','1336201888','1902121692','1164496618','1073557641','1255522488','1679705214','1467719260') %&gt;% 
    as.data.frame()
  </code></pre>
  <p>When I pass this data in as a data frame using lapply</p>
  <pre><code>x &lt;- lapply(providerIDs[,1], MARGIN = 2, FUN = getNPI)
  </code></pre>
  <p>I receive the following error:</p>
  <pre><code>Error in providerIDs[, 1] : incorrect number of dimensions
  </code></pre>
  <p>I know this is fundamentals for some folks but a little help understanding how I can pass in a character vector and not a data frame would be a huge help.</p>
  <p>Here is the function I am using:</p>
  <pre><code>pacman::p_load(tidyverse,httr,jsonlite,purrr)
  
  path &lt;- &quot;https://npiregistry.cms.hhs.gov/api/?&quot;
  
  # CREATE A FUNCTION TO QUERY THE NPPES NPI REGISTRY
  getNPI &lt;- function(object) {
    request &lt;- httr::GET(url = path,
                         query = list(version = &quot;2.0&quot;,
                           number = object))
    
    warn_for_status(request)
  
    df &lt;- content(request, 
                  as = &quot;text&quot;, 
                  encoding = &quot;UTF-8&quot;
                  ) %&gt;%
      jsonlite::fromJSON(., 
                         flatten = TRUE) %&gt;%
      data.frame() %&gt;% 
      tidyr::unnest(c(results.addresses,results.taxonomies), 
                    names_repair = &quot;unique&quot;)
    
    df_col_names &lt;- names(df)
    cols_to_add &lt;- setdiff(c(&quot;result_count&quot;,
                             &quot;results.enumeration_type&quot;,
                             &quot;results.number&quot;,
                             &quot;results.last_updated_epoch&quot;,
                             &quot;results.created_epoch&quot;,
                             &quot;results.other_names&quot;,
                             &quot;country_code&quot;,
                             &quot;country_name&quot;,
                             &quot;address_purpose&quot;,
                             &quot;address_type&quot;,
                             &quot;address_1&quot;,
                             &quot;address_2&quot;,
                             &quot;city&quot;,
                             &quot;state&quot;,
                             &quot;postal_code&quot;,
                             &quot;telephone_number&quot;,
                             &quot;code&quot;,
                             &quot;desc&quot;,
                             &quot;primary&quot;,
                             &quot;state1&quot;,
                             &quot;license&quot;,
                             &quot;results.identifiers&quot;,
                             &quot;results.basic.first_name&quot;,
                             &quot;results.basic.last_name&quot;,
                             &quot;results.basic.middle_name&quot;,
                             &quot;results.basic.credential&quot;,
                             &quot;results.basic.sole_proprietor&quot;,
                             &quot;results.basic.gender&quot;,
                             &quot;results.basic.enumeration_date&quot;,
                             &quot;results.basic.last_updated&quot;,
                             &quot;results.basic.status&quot;,
                             &quot;results.basic.name&quot;), df_col_names)
    if (length(cols_to_add) &gt; 0) {
        for(i in cols_to_add){
          df[,i] &lt;- &quot;UNKNOWN&quot;
        }
     }
  
    df %&gt;%
      select(results.number,
             results.basic.name,
             results.enumeration_type,
             results.basic.gender,
             results.basic.credential,
             desc,
             primary) %&gt;%
      rename(Provider_NPI = results.number,
             Provider_Name = results.basic.name,
             Provider_Gender = results.basic.gender,
             Provider_Credentials = results.basic.credential,
             Provider_Taxonomy = desc) %&gt;%
      mutate(
        Provider_Type = case_when(
          results.enumeration_type == &quot;NPI-1&quot; ~ 'Individual Provider',
          results.enumeration_type == &quot;NPI-2&quot; ~ 'Organizational Provider'
        )
      ) %&gt;%
      select(-results.enumeration_type) %&gt;% 
      # some providers have more than 1 taxonomy, this keeps the primary value
      filter(primary == 'TRUE') %&gt;% 
      # unnesting results in duplicate rows beacause of different address types
      distinct()
  }
  </code></pre>