title | description | author | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|
Set up a lab with R and RStudio on Windows using Azure Lab Services |
Learn how to set up labs to teach R using RStudio on Windows |
emaher |
how-to |
08/26/2021 |
enewman |
[!INCLUDE preview note]
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.
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.
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
Important
Advanced networking must be enabled during the creation of your lab plan. It can't be added later.
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.
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 |
After the template machine is created, start the machine, and connect to it to install R and RStudio Desktop.
- 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 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 "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
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.
- Download the installer for R Studio for Windows 10. The installer file will be 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 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.
$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
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
Important
The cost estimate is for example purposes only. For current pricing information, see Azure Lab Services pricing.
[!INCLUDE next steps for class types]