Set up a lab to teach R on Windows


This article references features available since the August 2022 Update, when lab plans replaced lab accounts. For more information, see What's New in the August 2022 Update.

R is an open-source language used for statistical computing and graphics. It's 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 will focus on solely RStudio and R as a building block for a class that requires the use of 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.

Lab configuration

To set up this lab, you need an Azure subscription and lab plan to get started. If you don't have an Azure subscription, create a free account before you begin.

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

Once you get have Azure subscription, you can create a new lab plan in Azure Lab Services. For more information about creating a new lab plan, see the tutorial on how to set up a lab plan. 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. Version 2004

Template configuration

After the template machine is created, start the machine, and connect to it to install R and RStudio Desktop.

Install R

  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 execute the installation of R using PowerShell. The 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

Now that we have R installed locally, we can install the RStudio IDE. We'll 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 will be 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 execute the RStudio installation steps 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

CRAN packages

Use the install.packages(“package name”) command in an R interactive session as shown in quick list of useful R packages article. Alternately, use Tools -> Install Packages menu item in RStudio.

If you need help with finding a package, see a list of packages by task or alphabetic list of packages.


Let’s cover an example cost estimate for this class. Suppose you have a class of 25 students. Each student has 20 hours of scheduled class time. Another 10 quota hours for homework or assignments outside of scheduled class time is given to each student. The virtual machine size we chose was Small GPU (Compute), which is 139 lab units.

25 students × (20 scheduled hours + 10 quota hours) × 139 Lab Units × 0.01 USD per hour = 1042.5 USD


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: