我希望能够
- 访问 BQ 表。这是课
[1] "tbl_BigQueryConnection" "tbl_dbi" "tbl_sql"
[4] "tbl_lazy" "tbl" `
- 使用 dbplyr 更改表以创建新表。再次,有课
[1] "tbl_BigQueryConnection" "tbl_dbi" "tbl_sql"
[4] "tbl_lazy" "tbl"
- 将此新表写入 BQ。
我收到以下错误:
(函数(类,fdef,mtable)中的错误:无法找到签名“BigQueryConnection”、“字符”、“tbl_BigQueryConnection”的函数“dbWriteTable”的继承方法</p>
MRE
library(DBI)
library(dplyr, warn.conflicts = FALSE)
library(bigrquery)
############ CREATE BQ TABLE TO ACCESS #################
dataset = bq_dataset(bq_test_project(), "test_dataset")
if (bq_dataset_exists(dataset))
{
bq_dataset_delete(dataset, delete_contents = T)
}
#> Suitable tokens found in the cache, associated with these emails:
#> * ariel.balter@gmail.com
#> * ariel.balter@providence.org
#> The first will be used.
#> Using an auto-discovered, cached token.
#> To suppress this message, modify your code or options to clearly consent to the use of a cached token.
#> See gargle's "Non-interactive auth" vignette for more details:
#> https://gargle.r-lib.org/articles/non-interactive-auth.html
#> The bigrquery package is using a cached token for ariel.balter@gmail.com.
bq_dataset_create(dataset)
#> <bq_dataset> elite-magpie-257717.test_dataset
conn = DBI::dbConnect(
bigrquery::bigquery(),
project = bq_test_project(),
dataset = "test_dataset",
KeyFilePath = "google_service_key.json",
OAuthMechanism = 0
)
if (dbExistsTable(conn, "mtcars"))
{
dbRemoveTable(conn, "mtcars")
}
dbWriteTable(conn, "mtcars", mtcars)
#######################################################
### Access BQ table
mtcars_tbl = tbl(conn, "mtcars")
class(mtcars_tbl)
#> [1] "tbl_BigQueryConnection" "tbl_dbi" "tbl_sql"
#> [4] "tbl_lazy" "tbl"
### Create new virtual table
hp_gt_100_tbl = mtcars_tbl %>% filter(hp>100)
class(hp_gt_100_tbl)
#> [1] "tbl_BigQueryConnection" "tbl_dbi" "tbl_sql"
#> [4] "tbl_lazy" "tbl"
### Write new table
dbWriteTable(conn, "hp_gt_100", hp_gt_100_tbl)
#> Error in (function (classes, fdef, mtable) : unable to find an inherited method for function 'dbWriteTable' for signature '"BigQueryConnection", "character", "tbl_BigQueryConnection"'
dbExecute(conn, "DROP TABLE mtcars")
#> [1] 0
dbExecute(conn, "DROP TABLE hp_gt_100")
#> Error: Job 'elite-magpie-257717.job_O8e7BtdfAnAb_8Vdtwybibgd7DpA.US' failed
#> x Not found: Table elite-magpie-257717:test_dataset.hp_gt_100 [notFound]
由reprex 包(v0.3.0)于 2020 年 11 月 11 日创建