Before you begin
Before you begin, create an R framework Notebooks instance.
Open a JupyterLab notebook
Follow these steps to open a Notebooks instance.
Go to the Notebooks page in the Google Cloud Console.
Next to the R instance that you want to open, click Open JupyterLab.
Select File > New > Notebook, and then select the R kernel.
Load the bigrquery R package
Follow these steps to load the bigrquery R package.
In the notebook file's first code cell, enter the following:
# Load the package library(bigrquery)
ClickRun the selected cells and advance.
R loads the package.
Load data from BigQuery
Follow these steps to load BigQuery data into a
bigrquery R package. Since you are running this from
a Notebooks instance, you are already authenticated.
To add a code cell, click the notebook file'sInsert a cell below button.
In the new code cell, enter the following.
# Store the project id projectid = "PROJECT_ID" # Set your query sql <- "SELECT * FROM `bigquery-public-data.usa_names.usa_1910_current` LIMIT 10" # Run the query and store the data in a tibble tb <- bq_project_query(projectid, sql) # Print 10 rows of the data bq_table_download(tb, max_results = 10)
Replace PROJECT_ID with your Google Cloud project ID.
To get your project ID, click the drop-down arrow next to your project name in the Google Cloud Console.
Run the cell to view 10 rows of data from one of BigQuery's public datasets.
Read bigrquery documentation to learn more about how you can use BigQuery data in your R notebooks.