The following document, copied below, is a quick guide to using RStudio as the tool to querying the APPROACH Online Reporting platform
...
If you don’t yet have an RStudio account, check in with the Approach Service Desk to check if your account was assigned and set up to have one. One can be requested through the Approach access approval form and registration process.
Tip: Changing your password
You will most likely want to change the auto-generated password provided to you. To do so, follow these steps.
Sign into RStudio with your credentials
Click on the ‘Terminal’ tab
Type
passwd
and press EnterFill out your current password, your new password and confirm your new password
Your password has been changed. Next time you log into RStudio, use your new password.
Step 3. RStudio landing page layout and summary
...
I. Script/Source Editor:
R scripts can be written and tested here. Either create a new script from File -> New File, or you may open and edit an existing script/project saved to your workspace. RStudio provides a set of core features as part of the source editor tool which is explained in detail here - https://support.rstudio.com/hc/en-us/articles/200484448-Editing-and-Executing-Code
II. Workspace Variables & Console History:
...
Step 4. Installing and importing the necessary libraries used to query the Approach database
Note: The Approach library and dependencies should already be preinstalled once you have access to your account.
To confirm the APPROACH package has been installed, do the following:
Sign into RStudio
On the right-hand side of the screen, click on the 'Packages' tab
Confirm that the ‘approach’ library is underneath the ‘User Library’ list
a. (Ignore this step if you already have the package installed)
Install the Query Utility R Package for APPROACH. This package is not public, and only available on the RStudio server. To install, run the following command in the console
install.packages("/home/cru/approach_0.1.1.tar.gz", source = TRUE, repos = NULL)
If successful, the console should return the following
Code Block |
---|
Installing package into ‘/home/<your-username>/R/x86_64-pc-linux-gnu-library/3.6’ |
...
(as ‘lib’ is unspecified) |
...
* installing *source* package ‘approach’ ... |
...
** using staged installation |
...
** R |
...
** byte-compile and prepare package for lazy loading |
...
** help |
...
** |
...
installing help indices |
...
** building package indices |
...
** testing if installed package can be loaded from temporary location |
...
** testing if installed package can be loaded from final location |
...
** testing if installed package keeps a record of temporary installation path |
...
* DONE (approach) |
b. Import the installed APPROACH library, running the following command in console
library(approach)
c. Create an ApproachAPI instance/object as follows
api = ApproachAPI()
This api variable will be used to authenticate yourself, and send PostgreSQL queries to the database
...
a. Logging In
Before submitting a query, the API must authenticate all subsequent requests. Authenticate yourself first using the ApproachAPI $login() function as below
api$login()
You will be prompted for your APPROACH reporting platform credentials.
...
b. Submitting Queries
Warning - Some tables have 100,000+ records stored. Try to refrain from selecting all from large data sets.
...
See here: https://front.approach.org/model-explorer (must be logged in)
e.g., api$query("SELECT count(*) as c, bmi FROM approach.patient WHERE bmi IS NOT NULL and bmi > 0 GROUP BY bmi ORDER BY c DESC;")
The query function will render the query’s results into a table
...
c. Logging Out
To close off your session with the API, run the $logout function as below
api$logout()
A confirmation message will be displayed once logged out
...