Set up a lab to teach R on Windows with Azure Lab Services
Important
Azure Lab Services will be retired on June 28, 2027. For more information, see the retirement guide.
Note
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] (class-type-deep-learning-natural-language-processing.md) 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.
Prerequisites
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.
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.
Important
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:
Start the template virtual machine and connect to the machine using RDP.
Install R in the template VM
Install RStudio in the template VM
Install R
To install R in the template virtual machine:
Download the latest installer for R for Windows.
For a full list of versions available, see the R for Windows download page.
Run the installer.
- For the Select Setup Language prompt, choose the language you want and select OK
- On the Information page of the installer, read the license agreement. Select Next to accept agreement and continue on.
- On the Select Destination Location page, accept the default install location and select Next.
- 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.
- 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.
- On the Select Start Menu Folder page, select Next.
- On the Select Additional Tasks page, optionally select Create a desktop shortcut. Select Next.
- On the Installing page, wait for the installation to finish.
- 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 "https://cran.r-project.org/bin/windows/base/release.html" -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 "https://cran.r-project.org/bin/windows/base/$outputfile" -OutFile $outputfile
}else{
Write-Error "Unable to find latest version of R installer. Go to https://cran.r-project.org/bin/windows/base/release.html 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.
Download the installer for R Studio for Windows 10. The installer file is in the format
rstudio-{version}.exe
.Run the RStudio installer.
- On the Welcome to RStudio Setup page of the RStudio Setup wizard, select Next.
- On the Choose Install Location page, select Next.
- On the Choose Start Menu Folder page, select Install.
- On the Installing page, wait for the installation to finish.
- 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.
$rstudiover="1.4.1717"
$outputfile = "RStudio-$rstudiover.exe"
#Download installer executable
Invoke-WebRequest "https://download1.rstudio.org/desktop/windows/RStudio-$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.
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: