2014-05-15 13 views
5

(được chỉnh sửa để cố tạo ví dụ có thể tái sản xuất)Cách tạo txt BigQuery bằng cách sử dụng dplyr

Tôi đang cố gắng kết nối với BigQuery qua dplyr (và phụ thuộc) và tôi gặp lỗi. Tôi đang làm gì sai?

require(dplyr) #installed from cran 
devtools::install_github("assertthat") 
devtools::install_github("bigrquery") 
require(bigrquery) 

billing_project = "omitted" 

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

# returns 
# Auto-refreshing stale OAuth token. 
# year month day weight_pounds 
# 1 1969  1 2  8.999270 
# 2 1969  1 15  8.375361 
# 3 1969  1 27  9.124933 
# 4 1969  1 9  6.000983 
# 5 1969  1 25  7.561856 

bq_db = src_bigquery("publicdata","samples", billing=billing_project) 
bq_db 

# returns 
# src: bigquery [publicdata/samples] 
# tbls: github_nested, github_timeline, gsod, natality, shakespeare, trigrams, wikipedia 


tri=tbl(bq_db, "trigrams") 

# returns 
# Error in UseMethod("sql_select") : 
# no applicable method for 'sql_select' applied to an object of class "bigquery" 

Đó là lỗi cuối cùng mà tôi gặp sự cố.

Tôi đã cài đặt dplyr ban đầu từ cran và phiên bản là 0.1.3. Gói bigrquery được cài đặt từ github thông qua devtools, và nó là 0,1.

sessionInfo() 
R version 3.1.0 (2014-04-10) 
Platform: x86_64-apple-darwin13.1.0 (64-bit) 

locale: 
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 

attached base packages: 
[1] stats  graphics grDevices utils  datasets methods base  

other attached packages: 
[1] bigrquery_0.1 dplyr_0.1.3 

loaded via a namespace (and not attached): 
[1] assertthat_0.1.0.99 devtools_1.5  digest_0.6.4  evaluate_0.5.3  httpuv_1.3.0  
[6] httr_0.3   jsonlite_0.9.7  memoise_0.2.1  parallel_3.1.0  Rcpp_0.11.1   
[11] RCurl_1.95-4.1  stringr_0.6.2  tools_3.1.0   whisker_0.3-2 

Tôi cũng đã cố gắng với điều này:

sql_q <- "SELECT year, month, day, weight_pounds FROM natality LIMIT 5" 
tri=tbl(bq_db, sql(sql_q)) 
# results in 
# Error in UseMethod("qry_fields") : 
# no applicable method for 'qry_fields' applied to an object of class "bigquery" 
+0

Ông có thể làm ví dụ một chút tái sản xuất nhiều hơn? tức là bạn cài đặt và tải bigrquery và dplyr như thế nào? – hadley

+0

hy vọng chỉnh sửa sẽ giúp. Nỗ lực đầu tiên là hình thức nghèo trên một phần của tôi – schnee

+0

Điều đầu tiên tôi muốn thử là dplyr từ github. – hadley

Trả lời

0

Tôi thường làm điều này:

df <- tbl_df(query_exec(sql, project, max_pages = Inf)) 
Các vấn đề liên quan