Set up a lab to teach R on Windows with Azure Lab Services


This article references features available in lab plans, which replaced lab accounts.

This article shows you how to set up a class in Azure Lab Services for teaching R and RStudio.

R is an open-source language used for statistical computing and graphics. The R language is used in the statistical analysis of genetics to natural language processing to analyzing financial data. R provides an interactive command line experience. RStudio is an interactive development environment (IDE) available for the R language. The free version provides code-editing tools, an integrated debugging experience, and package development tools.

This article focuses on using R and RStudio for statistical computing. The [deep learning] ( and Python and Jupyter Notebooks class types set up RStudio differently. Each article describes how to use the Data Science Virtual Machine for Linux (Ubuntu) marketplace image, which has many data science related tools, including RStudio, pre-installed.


To set up this lab, you need access to an Azure subscription. Discuss with your organization's administrator to see if you can get access to an existing Azure subscription. If you don't have an Azure subscription, create a free account before you begin.

Lab configuration

External resource configuration

Some classes require files, such as large data files, to be stored externally. See use external file storage in Azure Lab Services for options and setup instructions.

If you choose to have a shared R Server for the students, the server should be set up before the lab is created. For more information on how to set up a shared server, see how to create a lab with a shared resource in Azure Lab Services. For instructions to create an RStudio Server, see Download RStudio Server for Debian & Ubuntu and Accessing RStudio Server Open-Source.

If you choose to use any external resources, you’ll need to Connect to your virtual network in Azure Lab Services with your lab plan.


Advanced networking must be enabled during the creation of your lab plan. It can't be added later.

Lab plan settings

After you have an Azure subscription, you can create a lab plan in Azure Lab Services. For more information about creating a new lab plan, see Quickstart: Set up resources to create labs. You can also use an existing lab plan.

Lab settings

For instructions on how to create a lab, see Tutorial: Set up a lab. Use the following settings when creating the lab.

Lab setting Value and description
Virtual Machine Size Small GPU (Compute)
VM image Windows 10 Pro

Template configuration

After the template virtual machine is created, perform the following steps to configure the lab:

  1. Start the template virtual machine and connect to the machine using RDP.

  2. Install R in the template VM

  3. Install RStudio in the template VM

Install R

To install R in the template virtual machine:

  1. Download the latest installer for R for Windows.

    For a full list of versions available, see the R for Windows download page.

  2. Run the installer.

    1. For the Select Setup Language prompt, choose the language you want and select OK
    2. On the Information page of the installer, read the license agreement. Select Next to accept agreement and continue on.
    3. On the Select Destination Location page, accept the default install location and select Next.
    4. On the Select Components page, optionally uncheck 32-bit files option. For more information about running both 32-bit and 62-bit versions of R, see Can both 32-bit and 64-bit R be installed on the same machine? frequently asked question.
    5. On the Startup options page, leave startup options as No (accept defaults). If you want the R graphical user interface (GUI) to use separate windows (SDI) or plain text help, choose Yes (customize startup) radio button and change startup options in the following to pages of the wizard.
    6. On the Select Start Menu Folder page, select Next.
    7. On the Select Additional Tasks page, optionally select Create a desktop shortcut. Select Next.
    8. On the Installing page, wait for the installation to finish.
    9. On the Completing the R for Windows page, select Finish.

You can also perform the installation of R by using PowerShell. The following code example shows how to install R without the 32-bit component and adds a desktop icon for the latest version of R. To see a full list of command-line options for the installer, see setup command-line parameters.

#Avoid prompt to setup Internet Explorer if we must parse download page
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main" -Name "DisableFirstRunCustomize" -Value 2

$outputfile = "R-win.exe"

$result = Invoke-WebRequest "" -OutFile $outputfile -PassThru

#Check if we need to parse the result ourselves, to find the latest version of R
if ($result.StatusCode -eq '200' -and $result.Headers["Content-Type"] -eq 'text/html')
    $metaTag = $result.ParsedHtml.Head.children | Where-Object {$_.nodeName -eq 'META'}
    if ($metaTag.content  -match "R-\d+\.\d+\.\d+-win.exe"){
        $outputfile = $Matches.0

        #Download latest version
        Invoke-WebRequest "$outputfile" -OutFile $outputfile
        Write-Error "Unable to find latest version of R installer.  Go to to download manually."

#Install Silently
$installPath = Get-Item -Path $outputfile
Start-Process -FilePath $installPath.FullName -ArgumentList "/VERYSILENT /LOG=r-install.log /NORESTART /COMPONENTS=""main,x64,translations"" /MERGETASKS=""desktopicon"" /LANG=""en""" -NoNewWindow -Wait

Install RStudio

After you install R in the template VM, install the RStudio IDE. In this article, you install the free version of RStudio Desktop. For all available versions, see RStudio downloads.

  1. Download the installer for R Studio for Windows 10. The installer file is in the format rstudio-{version}.exe.

  2. Run the RStudio installer.

    1. On the Welcome to RStudio Setup page of the RStudio Setup wizard, select Next.
    2. On the Choose Install Location page, select Next.
    3. On the Choose Start Menu Folder page, select Install.
    4. On the Installing page, wait for the installation to finish.
    5. On the Completing RStudio Setup page, select Finish.

To perform the RStudio installation steps by using PowerShell, run the following commands. See RStudio downloads to verify the RStudio version is available before executing the commands.

$outputfile = "RStudio-$rstudiover.exe"

#Download installer executable
Invoke-WebRequest "$rstudiover.exe" -OutFile $outputfile

#Install RStudio silently
$installPath = Get-Item -Path $outputfile
Start-Process -FilePath $installPath.FullName -ArgumentList "/S" -NoNewWindow -Wait

Install CRAN packages

Comprehensive R Archive Network (CRAN) is R's central software repository. Among others, the repository contains R packages, which you can use to extend your R programs.

To install CRAN packages on the template virtual machine:

  • Use the install.packages(“package name”) command in an R interactive session as shown in quick list of useful R packages article.

  • Alternately, use the Tools > Install Packages menu item in RStudio.

See the list of packages by task or alphabetic list of packages.


This section provides a cost estimate for running this class for 25 lab users. There are 20 hours of scheduled class time. Also, each user gets 10 hours quota for homework or assignments outside scheduled class time. The virtual machine size we chose was Small GPU (Compute), which is 139 lab units.

  • 25 lab users × (20 scheduled hours + 10 quota hours) × 139 lab units


The cost estimate is for example purposes only. For current pricing information, see Azure Lab Services pricing.

Next steps

The template image can now be published to the lab. For more information, see Publish the template VM.

As you set up your lab, see the following articles: