Installation and Authentication

Mark Edmondson

2019-05-04

Setup

Google Compute Engine (GCE) lets you create and run virtual machines on Google infrastructure. See the general Google documentation here.

Before you begin, you will need to set up a Cloud Platform project, and enable billing by adding a credit card.

A quickstart guide to using GCE is available here for making your first VM via the web interface, if you are not familiar with GCE then its best to start there.

Pricing is available here.

For googleComputeEngineR you will need:

Setup video guide

A video guide to setup and launching an RStudio server has been kindly created by Donal Phipps and is available at this link.

Authentication

Auto-authentication via .Renviron

Authentication requires you to set environment arguments with your setup details.

These can be set in an .Renviron file located on your computer home directory - R will look in this file upon startup. Read more via ?Startup

The easiest way to find the right home directory is within RStudio, to click on the Home button in RStudio’s file explorer. Create a file via File > New file > Text File, save and call it .Renviron

My .Renviron file looks a bit like this:

GCE_AUTH_FILE="/Users/mark/xxxxx/auth.json"
GCE_DEFAULT_PROJECT_ID="mark-xxxxxxx"
GCE_DEFAULT_ZONE="europe-west1-a"

The GCE_AUTH_FILE points to the file location of the service account JSON file taken from your Google Project. The other arguments set the default project and zone.

This file will then used for authentication when you load the library:

## GCE_AUTH_FILE set so auto-authentication
> library(googleComputeEngineR)
Successfully authenticated via /Users/mark/auth.json
Set default project name to 'mark-xxxxx'
Set default zone to 'europe-west1-a'

> gce_get_project()
$kind
[1] "compute#project"

$id
[1] "43534234234324324"

$creationTimestamp
[1] "2015-05-08T15:22:38.416-07:00"

$name
[1] "mark-xxxxx"

...etc.... 

Other authentication methods

If you can’t use an .Renviron you can set environment files within the script via Sys.setenv:

Sys.setenv("GCE_AUTH_FILE" = "/fullpath/to/auth.json")