hadley/bigrquery — pull request #3 by jhyrkas (2013-08-05 17:47:11+00:00)
Title: Incorrect JSON generated in query_exec

I've used devtools::install_github to install the latest version of httr and bigrquery. To reproduce, I ran the example given for bigrquery:

>library(bigrquery)
billing_project <- #projectId
sql <- "SELECT year, month, day, weight_pounds FROM natality LIMIT 5"
query_exec("publicdata", "samples", sql, billing = billing_project)

>Loading required package: Rook
Loading required package: tools
Loading required package: brew
starting httpd help server ... done
Waiting for authentication in browser...
Authentication complete.
Error: Job configuration must contain exactly one job-specific configuration object (e.g., query, load, extract, spreadsheetExtract), but there were 0:

I believe the problem comes from the function bq_post() on this line:
> \> config <- c(config, sig, add_headers("Content-type" = "application/json"))

In my own attempt to reproduce, this line makes config a list of length 2, where each element is named 'httpheader'

> \>config
$httpheader
Authorization
"Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
$httpheader
Content-type
"application/json"

So when POST is called, the JSON request is incorrectly formatted. In my case, it looked like "Content-Type: application/json" was absent in the request.

I think what we want is config to be a list of with one element named $httpheader. I'd be happy to try to fix the issue, but I figured I'd submit it here first in case anyone has any insight into what's going on.