Coming to SAS after 6 years of almost exclusively programming in R, I was thrilled to discover ways to combine the strengths of both languages with tools like the R SWAT Package and PROC IML. Most recently I tried the R Runner custom step in SAS Studio Flows, which allows users to code in R, or even upload an entire R script to be used in a flow. The purpose of this post is to share my experience using R Runner and how anyone building a flow may benefit from it.
If you are asking yourself, “What is a ‘flow’?”, SAS Studio Flows offer a low-code option for analyzing data with SAS Viya. A flow is a sequence of operations on data. Data and operations are represented in SAS Studio by steps that you can access from the Steps section of the navigation pane. Each step in a flow is represented by a node on the flow canvas. While SAS provides several predefined steps to use in flows, users and developers also build custom steps to perform specific tasks. R Runner is a custom step that allows users to run R scripts and write R code to analyze data within a flow.
Here are some additional resources regarding SAS Studio Flows:
I accessed R Runner through the SAS Studio Custom Steps GitHub repository which is available to all users.
My first step was to make sure my machine had the necessary requirements for R Runner. I asked my SAS Administrator for the following, which are outlined in more detail here:
Once my environment was set up, I needed to upload the R Runner custom step into SAS Viya following the steps outlined here.
*Before continuing, view a tour of the R Runner interface here to familiarize yourself with the interface.
Now that R Runner was ready to go, I did what any programmer would do and began my exploration by using the text box to print the ever-famous line, “Hello World!”
Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
Navigating to the “Submitted Code and Results” log, I found the output of my R Code.
Next, I submitted a regression model with the following steps to analyze the SASHELP.CARS table to understand the relationship between Horsepower and Highway MPG.
model <- lm(MPG_Highway ~ Horsepower, data=r_input_table)
print(summary(model))
In addition to printing R output, R Runner has the ability to modify SAS tables with R code within a flow.
For example, let’s say I want to filter the SASHELP.CARS table by Make, only keeping Audis. The tidyverse set of packages in R includes convenient data transformation functions. tidyverse was installed with the SAS Open Source Configurator so all I needed to do was build my flow and include library(tidyverse) in my R code to load in the tidyverse packages. To create a table with only Audi vehicles included, I followed these steps:
library(tidyverse)
AUDI <- r_input_table %>% filter(Make == “Audi”)
Next, I put the same code in an R script and provided the location of the script to R Runner which gave the same results. This method is especially helpful to run longer programs and allows users to use the editing capabilities provided in an IDE such as R Studio to build the script, then execute it within a flow.
In some Viya environments, if using the folder button on the right, the path provided may not be complete. If you receive an error, find the location of your R script in the file system and copy/paste it to the text box instead with sasserver: in front of the path.
You can even take advantage of R’s graphing capabilities within a flow. Below is an example creating a histogram using the ggplot2 package in R. This feature is limited to creating PDFs currently, but future developments will expand R Runner’s graphing capabilities.
I created a histogram of the Highway MPG data from SASHELP.CARS following these steps:
p <- ggplot(r_input_table, aes(x=MPG_Highway)) +
geom_histogram(fill = “white”, color = “blue”) +
ggtitle(“Highway MPG”)
ggsave(“MPG_Hist.pdf”, p, path = “/home/student”)
When configuring R with SAS Viya using the SAS Configurator for Open Source, certain R packages are suggested as part of the installation manifest. If there are specific R packages you know you will need to use as part of your R script, please let your SAS administrator know so they can include those packages in the configuration. As of now, users cannot install R packages directly using R Runner.
R Runner developers are in the process of planning improvements and maintain an upstream repository for this purpose here.
R Runner serves as an excellent tool for integrating the capabilities of both R and SAS within flows. The most current version of R Runner can be accessed here.
SAS Studio Flows Quick Start Video
SAS Studio Flows Documentation
SAS Studio Custom Steps -- R Runner Git Repository
Custom Step Installation Instructions
R Runner Upstream GitHub Repository
Find more articles from SAS Global Enablement and Learning here.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.