"R" Reporting Programming Language
R, via RStudio
Testing R (v…) and RStudio (v…) on:
MacBook Pro laptop (macOS High Sierra 10.13.6, 2.9 GHz Intel Core i5, 16GB 2133 MHz LPDDR3 memory)
MacBook Air laptop (macOS High Sierra 10.13.6, 1.8 GHz Intel Core i5, 8 GB 1600 MHz DDR3 memory)
Dell Precision T1650 desktop (Windows 10 Enterprise 2016 LTSB, Intel Xeon CPU E3-1270 V2 @ 3.50 GHz, 32GB RAM)
Setting up PostgreSQL Drivers
R connects to PostgreSQL data sources using ODBC generic connections. First, you will probably need to install something that gets the computer ready to manage ODBC connections, then you’ll have to install a specific PostgreSQL driver. | |
For Mac
| … … … |
For Windows
|
Connecting to the Data Warehouse
For Mac only
[PostgreSQL Driver] Driver = /usr/local/lib/psqlodbcw.so Note: the name inside the square brackets [] can be anything, but you have to remember this name to call this driver later. Note: you should look inside /usr/local/lib make sure this is the correct path to your psqlodbc driver file. | |
For Mac and Windows
odbc::odbcListDrivers() The name of the driver should be the same as the name you gave the driver when you edited odbcinst.ini. | |
Make the connection using code like the following: odbc::odbc(), driver="PostgreSQL Driver", database="ldp", UID="yourusername", PWD="yourpassword", server="glintcore.net", port=5432, sslmode = "require" ) Note: Insert the correct driver name returned from the previous command, as well as your correct login credentials. Note: SSL should be On |
Executing Custom SQL (more info)
Using DBI package:
Using Rmd files:
|
Building Queries In Tool
If you are interested in recreating the original queries using R code, you may want to use dplyr/dbplyr as described at: |
Viewing and Saving Results
The results of the methods mentioned above should be a standard R data frame. R data frames can be exported to csv using “write.csv” (base R) or “write_csv” (readr package inside the tidyverse). See the standard help documentation for syntax information. Other output formats (e.g., Excel files) may be available using other R packages. |