title: How can I insert non-repeated records into BigQuery using the bigrquery library?
body: <p>I'm trying to insert a non-repeated record into BigQuery but keep receiving the error <code>Array specified for non-repeated field: record.</code>.</p>
  
  <p>My question is: How can I insert non-repeated records into BigQuery using the <a href="https://github.com/r-dbi/bigrquery" rel="nofollow noreferrer">bigrquery</a> library?</p>
  
  <p>If I have the following schema:</p>
  
  <pre><code>bqSchema &lt;- bq_fields(list(
    bq_field(name = "record", type = "RECORD", fields = list(
      bq_field(name = "a", type = "INTEGER"),
      bq_field(name = "b", type = "STRING")
    ))
  ))
  </code></pre>
  
  <p>And this data frame:</p>
  
  <pre><code>df &lt;- tibble(
    record = list(
      a = 1,
      b = "B"
    )
  )
  </code></pre>
  
  <p>Inserting the data as below causes the error in BigQuery:</p>
  
  <pre><code>bq_perform_upload(bqTableObj, df, fields = bqSchema)
  # Array specified for non-repeated field: record
  </code></pre>
  
  <p>I think this is in part because bigrquery <a href="https://github.com/r-dbi/bigrquery/blob/f7eb39de0d5050dac8a3d567eecb2651370a2590/R/old-job-upload.R#L92" rel="nofollow noreferrer">converts the dataframe to JSON</a> with <code>jsonlite::stream_out()</code>, but doesn't use the argument <code>auto_unbox = TRUE</code>, resulting in arrays, rather than objects. This results in the following newline delimited JSON being sent to BigQuery:</p>
  
  <pre><code>{"record": [1]}
  {"record": ["B"]}
  </code></pre>
  
  <p>The correct NDJSON that should be sent to BigQuery I believe should be:</p>
  
  <pre><code>{"record": {"a": 1, "b", "B"}}
  </code></pre>
  
  <p>Has anyone had this problem before, or have ideas how I can resolve this?</p>