The steps below are a one-time setup, but they must be followed that one time for the examples on this site to work.
Follow the steps in this video from Donal Phipps:
We’re not going to enter the client ID and client secret directly in any of these examples, but, rather, store them in the .Renviron
file, which is detailed below. It’s fine if you made the full bit of code as Donal describes it in the video, but know that you will need to copy the client_id
and client_secret
into another file as detailed below.
This is a file that loads when an R session gets initiated. There are various options for managing this, but below describes an approach that is inarguably the BEST approach!*
Find your Home directory by clicking on the Home button in the Files pane of RStudio. Then, simply create a new text file (File > New File > Text File) and save it as .Renviron
. You might get a warning about how this will be a hidden file, but just ignore the warning. Live life on the edge!
The examples expect three variables to be in the ‘.Renviron’ file. You’re welcome to add other variables, and, over time, should have a quite robust file. But, we only need three. The file should look something like this:
GA_CLIENT_ID = "XXXXXXXXXXXXX-XXXXXXXXXXXXX-XXXXXXXXXXX.apps.googleusercontent.com"
GA_CLIENT_SECRET = "XXXXXXXXXXXXXXXXXXXXX"
GA_VIEW_ID = "ga:XXXXXXXXXX"
No, silly, you don’t want a bunch of Xs there! You will need to update those with values that are unique to your environment:
ids
value that is the first field under the Query Parameters sectionNow, save the file.
This happens any time you start a new R session, so you won’t have to worry about this going forward unless you change a value (like GA_VIEW_ID
). For this one time, though, select Session > Restart R in RStudio.
Run the following code in your console:
client_id <- Sys.getenv("GA_CLIENT_ID")
Now, check the Environment pane in RStudio. You should see an object called client_id
with the client ID for your Google Project. You can run this for the other two values, too, but let’s just assume that, if it worked for one, you’re all set.
You should be all set! The examples should all work!
* Subjectively… but it’s what @HoloMarkeD does, and you can come up with your own special way at your own risk.
This site is a sub-site to dartistics.com