# NOT RUN {
# }
# NOT RUN {
library(googleCloudStorageR)
library(bigQueryR)
gcs_global_bucket("your-project")
## custom upload function to ignore quotes and column headers
f <- function(input, output) {
write.table(input, sep = ",", col.names = FALSE, row.names = FALSE,
quote = FALSE, file = output, qmethod = "double")}
## upload files to Google Cloud Storage
gcs_upload(mtcars, name = "mtcars_test1.csv", object_function = f)
gcs_upload(mtcars, name = "mtcars_test2.csv", object_function = f)
## create the schema of the files you just uploaded
user_schema <- schema_fields(mtcars)
## load files from Google Cloud Storage into BigQuery
bqr_upload_data(projectId = "your-project",
datasetId = "test",
tableId = "from_gcs_mtcars",
upload_data = c("gs://your-project/mtcars_test1.csv",
"gs://your-project/mtcars_test2.csv"),
schema = user_schema)
## for big files, its helpful to create your schema on a small sample
## a quick way to do this on the command line is:
# "head bigfile.csv > head_bigfile.csv"
## upload nested lists as JSON
the_list <- list(list(col1 = "yes", col2 = "no",
col3 = list(nest1 = 1, nest2 = 3), col4 = "oh"),
list(col1 = "yes2",
col2 = "n2o", col3 = list(nest1 = 5, nest2 = 7),
col4 = "oh2"),
list(col1 = "yes3", col2 = "no3",
col3 = list(nest1 = 7, nest2 = 55), col4 = "oh3"))
bqr_upload_data(datasetId = "test",
tableId = "nested_list_json",
upload_data = the_list,
autodetect = TRUE)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab