Setting up R
Connect R and RStudio to the PEARS data mart using the RPostgres and DBI libraries.
The PEARS data mart can be used in combination with R and RStudio as follows.
Prerequisites
Install R and RStudio
Visit https://posit.co/download/rstudio-desktop/ to install both R and RStudio, if you haven't already.
Setup
Certificates
Before a trusted connection can be established with the data mart, Amazon's RDS certificates must be downloaded to a local folder on the device.
Download the certificate bundle
Download a certificate bundle from Amazon. You will either need the specific bundle for the us-east-1 region or the AWS global bundle.
Global (any AWS region): https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem
US East (N. Virginia): https://truststore.pki.rds.amazonaws.com/us-east-1/us-east-1-bundle.pem
Place the file locally
Place the file downloaded into a location on your local drive that can be accessed by R.
One suggestion is under the root of the drive, such as
C:\Certificates\.If you have limited access to your local drive, consider a location under your user folder, such as
C:\Users\<username>\Certificates\.
Package Installation
R can connect directly to the data mart using the RPostgres library along with the standard DBI library.
install.packages("RPostgres")
install.packages("DBI")It is recommended that you not provide your password in clear text as part of your script. One way to handle your password more securely is to utilize the keyring with an initial one-time step. The script below will prompt for the password and save it securely for future use.
install.packages("keyring")
library(keyring)
# One-time setup to store password
key_set("PEARS_datamart") # You'll be prompted to enter the password securelyUsage
Following is a sample R script that will connect to the data mart and list all available tables. Replace the values for host, port, dbname, and user with those provided by the PEARS Client Success team. Additionally, sslrootcert should reference the certificate file downloaded as part of the setup described above.
Last updated
