SAS Studio needs a quick and easy interface to R. This repository provides a custom step (a low-code component) which will enable developers to quickly submit R scripts from within SAS Studio (on SAS Viya) in a quick and no-nonsense manner.
Analytics developers appreciate unified interaction with SAS and R, especially in certain industries such as Pharma and Healthcare, which have significant R developers. R Runner helps such developers create solutions using R (as well as SAS and Python if required) within SAS Studio on SAS Viya.
R Runner enables you to submit R scripts from within SAS Studio and develop integrated analytics pipelines. You can submit either:
-
Short R snippets in the text area provided
-
R scripts (programs) through a file selector
Variables created within the R script (also known as R environment variables) can also be written to an output SAS dataset for reference and reuse in downstream code.
In this early version, you'll also be able to attach an input table (SAS dataset) to the custom step, which will be converted to an R data frame (via Python) for analysis in the R script.
This is the first release of R Runner and facilitates the basic task of executing R scripts within SAS Studio. We'll consider additional improvements in future.
To set correct expectations,
-
R Runner should NOT be considered an R editor / IDE for SAS Studio (though it's tempting for us, the creators, to label it so :)).
-
Given the recency of this step, there are bound to be teething troubles. We appreciate your patience (and even more so, suggestions and contributions).
-
While this may seem obvious, do not expect syntax checks, highlighting or other convenience you are used to with R interfaces.
Tested in Viya 4, Stable 2023.08
This custom step accesses an R interpreter through a Python package (rpy2). Therefore, ensure:
-
A SAS Viya 4 environment (monthly release 2023.08 or later) with SAS Studio Flows. Earlier versions of Viya 4 (where Proc Python is supported) should be okay, as long as you understand the configuration for R_HOME and the packages involved. Try it out and let us know.
-
SAS Viya has access to an active Python and R environment. Proc Python makes use of this Python environment.
-
The rpy2 Python package is installed and configured. Refer documentation for details on rpy2.
-
A path to R is available through the R_HOME environment variable.
-
Preferable / recommended: Administrators could make use of the SAS Configurator for Open Source (also commonly known as sas-pyconfig) to install and configure Python and R access from SAS Viya. Refer SAS Viya Deployment Guide (monthly stable 2023.08 onwards) for instructions on the same. Documentation provided below.
-
Input Data (input port, optional): attach an input table (SAS dataset) to this port to facilitate analysis in R. You should refer this input dataset as r_input_table inside the R script.
-
Input R Script (file selector, optional): attach an R script which you wish to execute.
-
R Snippet (text area, optional): use this for short (less than 32768 characters) snippets of R code you wish to execute.
Ensure your R script is styled and indented as per R conventions to avoid failures.
-
R dataframe to output (text field, optional): refer an R dataframe (which exists in the R session) which you desire to output to a SAS dataset for downstream analysis.
-
Output table (output port, optional): attach a SAS dataset to this port which will contain data from a R dataframe you wish to output.
-
R_HOME path (Configuration tab, verify/change defaults): rpy2 needs to know where to find R on the system. Change this default value after consulting your administrator. The default is based on an environment where R and Python are installed using the SAS Configurator for Open Source (also known as sas-pyconfig) and sas-open-source-config utilities.
- Reference dataset for R environment variables (output port, optional) : attach a SAS dataset to the envData output port of this custom step to refer variables created during R execution. These are known as R environment variables and can be accessed through the globalenvs attribute of the robjects object in rpy2 (documentation below).
-
Documentation on the rpy2 package: here
-
Access to R from inside a SAS Viya environment is governed by some environment variables, including R_HOME and DM_RHOME, used within this custom step to configure the rpy2 package. Refer this link (and embedded references) for instructions on configuring open source environments with SAS Viya:
-
This SAS Communities article on R integration is also useful. Note especially the way that R_HOME is defined.
-
The SAS Viya Platform Deployment Guide (refer to SAS Configurator for Open Source within): here
- Refer to the steps listed here.
- Samiul Haque ([email protected])
- Sundaresh Sankaran ([email protected])
This is not a comprehensive list of all known issues with rpy2. However, it's likely you may encounter some of these (given that you are working with THREE languages !) issues and the following links may be helpful.
-
Pandas may not transfer cleanly to R dataframe due to a mismatch in types: https://stackoverflow.com/questions/60197294/error-when-using-pandas-dataframe-in-r-cell-in-rpy2-jupyter-notebook
-
A table may be created but you are not able to access / export it. This might be due to global envs vs. local sessions: https://stackoverflow.com/questions/15227926/rpy2-object-not-found-error
Version 1.0 (18AUG2023)
- Initial Step Creation