Last active
October 25, 2017 06:03
-
-
Save mrchypark/32dd29b568f1cc425af84480fa2aa931 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(googleCloudStorageR) | |
library(dplyr) | |
library(bigrquery) | |
library(dbplyr) | |
# 필요 데이터를 다운로드 받습니다. | |
# dabrp_classnote3 프로젝트 폴더일 때를 기준으로 했습니다. | |
chk<-file.info("./data/recomen/tran.csv") | |
if(is.na(chk$size)){ | |
recoment<-"http://rcoholic.duckdns.org/oc/index.php/s/jISrPutj4ocLci2/download" | |
dir.create("./data", showWarnings = F) | |
dir.create("./data/recomen", showWarnings = F) | |
download.file(recoment,destfile="./data/recomen/tran.csv",mode='wb') | |
} | |
# 클라우드 스토리지의 권한을 받습니다. | |
gcs_auth() | |
# 프로젝트에 있는 버킷을 확인합니다. | |
gcs_list_buckets("striking-port-180613") | |
# 없으면 버킷을 만듭니다. | |
# 버킷 이름은 전세계 기준 유일해야 하므로 어렵게 만듭니다. | |
gcs_create_bucket("bigquery_test_123" | |
,"striking-port-180613") | |
# 만든 버킷 경로로 파일을 업로드합니다. | |
# name을 지정하지 않으면 경로명으로 자동 설정됩니다. | |
upload_try <- gcs_upload(bucket="bigquery_test_123" | |
, file="./data/recomen/tran.csv" | |
, name="tran.csv") | |
### bigquery 콘솔로 가서 gs://bigquery_test_123/tran.csv 경로로 테이블을 만듭니다. | |
### 위 기능은 bigrquery 패키지에 제안되어 지금 승인을 기다리고 있습니다. | |
## https://github.com/rstats-db/bigrquery/pull/155 | |
## dataset 과 porject 를 지정하는 것으로 연결됩니다. | |
con <- DBI::dbConnect(bigrquery::bigquery() | |
, dataset="class3_tt" | |
, project="striking-port-180613") | |
dbListTables(con) | |
fl<-tbl(con, "flights14") | |
fl %>% | |
select(year) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment