BookmarkSubscribeRSS Feed

Getting Started with R in SAS Viya Workbench

Started 2 weeks ago by
Modified 2 weeks ago by
Views 339

As data science tools continue to evolve, the ability to integrate familiar languages like R and Python into powerful platforms such as SAS Viya Workbench is a game-changer. For developers and analysts who rely on R for modeling, visualization, or custom workflows, SAS Viya Workbench offers a flexible environment to bridge open-source and enterprise analytics. In this post, we’ll explore how to run R code in SAS Viya Workbench and share practical tips to make the most of this integration.

 

 

What is SAS Viya Workbench?

 

SAS Viya Workbench is a cloud-based development environment that lets developers, data scientists and modelers code in SAS, Python or R through Visual Studio Code or Jupyter Notebook.

 

For step-by-step instructions to start a workbench instance visit SAS Tutorial | Getting Started with SAS Viya Workbench for Learners.

 

Students and educators can access SAS Viya Workbench for Learners for free: SAS Viya Workbench for Learners | SAS

 

Those outside of education can learn how to access SAS Viya Workbench here: SAS Viya Workbench | SAS

 

 

How do I start developing R code?

 

Users can choose between Visual Studio Code and Jupyter Lab to develop R code. Simply select either Launch Jupyter Lab – Python and R or Launch VS Code – SAS and R. This post will focus on navigating the Visual Studio Code Interface.

 

01_ST_wb1-1.png

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

After selecting a programming interface, users can create an R Document or R Markdown file by selecting the top left menu > File > New File...

 

02_ST_wb2.png

 

03_ST_wb3.png

 

 

R Documents

 

Begin by creating a new R Document. The interface is divided into two main sections: the source pane at the top, where you can write and edit R scripts, and the console at the bottom, where you can run individual lines of code and view the results from both the console and the source pane.

 

To run the entire R script, click the play icon on the top right icon1_play.png. To run single lines or sections of code, put your cursor on a line, or highlight the section of code you want to run and click Ctrl + Enter or Command + Enter if using a Mac.

 

Any plots will appear in a window to the right of the script, while the results appear in the console, including any errors or warnings.

 

04_ST_rblog1.gif

 

Users can directly install and load R packages in workbench. The standard R libraries are installed by default along with the following:

 

  • caret
  • table
  • tidymodels
  • tidyverse

 

See SAS Help Center: Managing the R Environment for more details on available packages.

 

Users can see their workspace by selecting the R icon on the lefthand side. This shows any objects created during the R session along with attached and loaded namespaces. From here, workspaces can be loaded, saved, or cleared.

 

05_ST_rsymbol.png

 

 

R Markdown

 

Go back to the top left menu > File > New File… and this time create a new R Markdown file. Notice several template options appear:

 

06_ST_templates.png

 

R Markdown is a file format for making dynamic documents with R. An R Markdown document is written in markdown (an easy-to-write plain text format) and contains chunks of embedded R code, like the document below. Users have the option to name chunks and set specific options within the chunk header. For example, the last chunk in the document below has the header {r pressure, echo=FALSE}. The name of the chunk is pressure and echo=FALSE prevents printing the R code that generates the output.

 

07_ST_pressure-1024x261.png

 

R Markdown templates define the structure and style of your output, making it easy to create specific types of documents. For example, the GitHub document template formats your content for clean display on GitHub, ideal for sharing code and analysis in repositories.

 

Select GitHub Document (Markdown) and notice example chunks of code appear. Users can run a single chunk of code or the entire file above a specific chunk.

 

08_ST_chunk.png

 

When you press the Knit Rmd icon icon2_arrow.png a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You will be prompted to save the R Markdown file and knitted document to a location of your choosing. To preview the knitted file, click the Open Preview to the Side icon icon3_preview.png.

 

09_ST_rblog2.gif

 

 

Creating a Shortcut

 

If a user knows they will be creating several R files, they can create a keyboard shortcut to create an R file. To do so, select the top left menu > File > New File… and select the Configure Keybinding icon icon4_setting.png next to the type of file for which the shortcut applies. Then select the plus sign icon5_plus.png and provide the keyboard shortcut to create the document.

 

10_ST_rblog3.gif

 

 

Conclusion

 

SAS Viya Workbench offers a flexible, cloud-based environment for running R code, making it easier for users to develop, visualize, and share their work. Its intuitive interface and support for common R workflows—like script editing, plotting, and markdown reporting—make it a great fit for both learning and everyday analysis. Whether you're analyzing data or building models, Viya Workbench helps you stay productive with the tools you already know.

 

 

Find more articles from SAS Global Enablement and Learning here.

Version history
Last update:
2 weeks ago
Updated by:
Contributors

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

SAS AI and Machine Learning Courses

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.

Get started

Article Tags