Custom R installation on a WURclient computer

Image credit: Panos Sakalakis on Unsplash
Table of Contents

Motivation

A WURclient desktop or laptop at Wageningen University & Research is not a standard Windows 10 computer. WURclients use Windows 10 Enterprise, which has been modified by Facilities and Services Information Technology (FB-IT) among others with respect to installation rights for security reasons.

WURclient desktops and laptops at Wageningen University & Research can install R from the Software Center created by the IT department, which is launched by clicking on Start and selecting the “Software Center” tile. At the time this post was written the latest version of R in Software Center is R 4.1.0 Rcmdr. Currently the latest available version in Software Center is R 4.3.1 Rcmdr.

This version of R was packaged for educational purposes, where Rcmdr reflects that the installer includes R Commander. Only once per year a new version of R (including R Commander and additional packages for serveral courses) is released in Software Center. The consequence is, that core packages can not be updated by users.

Many users, however, need to be able to update core packages, because of dependencies with packages they would like to install or would just like to use a newer version of R than the one in Software Center. At the moment of writing this post the latest version of R released on r-project.org is R version 4.0.5 named: “Shake and Throw” (released on 2021-03-31). The post has been updated, with the exception of the screenshots, to R version 4.3.1 named: “Beagle Scouts”.

This post will show how to custom install R on a WURclient desktop or laptop computer without using Software Center.
The installation instructions in this post are not to be used on privately owned desktops or laptops! For a privately owned desktop or laptop see the post: R installation on Windows 10/11.

Prerequisite

  • To be able to perform a custom installation of R you need to have POWER USER RIGHTS on the WURclient desktop or laptop.

To see whether you possess these rights, right-click any icon (except Recycle Bin or WUR HELP) on the desktop. When the opened menu contains the option ‘WUR - Run with administrative rights’ (seventh or eighth from the top), it means you have power user rights on that particular desktop or laptop.

Uninstall a previously installed R version

Before performing a new custom installation of R it is recommended to uninstall a previously installed version.

Here two procedures are described, follow the one that fits your needs:

In case you have no version of R installed on your WURclient desktop or laptop you can proceed to the section Custom R installation.

Installed from Software Center

If you previously installed R from Software Center, then to remove R reopen the Software Center by clicking on Start and next click on the Software Center tile. If for some reason you lack this tile in your start menu, just type ‘Software Center’ and it will appear in a search results window in your Windows task bar.

In the left column of Software Center navigate to “Installation Status”. Select the installed R version and click on the green button bearing the text “Uninstall”. This will start the removal of the software. You will be informed by the Software Center, when the software has been uninstalled.

Next you will need to remove the packages, you have installed manually (added yourself via the install.packages() command in R).

Be aware that all packages you have installed manually will be removed, if you continue here!

Let’s assume you had previously installed CRAN R 3.6.1 Rcmdr from Software Center on your WURclient computer. The user installed packages will reside in C:\ProgramData\R\win-library\3.6. If you try to remove the folder via File Explorer in Windows, you will discover that you have insufficient rights to do so. The reason is that Software Center installs software with ADMINISTRATOR RIGHTS, you on the other hand only have POWER USER RIGHTS. The POWER USER does not have full administrator privileges!

However, there is a way to still delete the previously manually installed packages from C:\ProgramData\R\win-library\3.6. To do so you need to use either Command Prompt or Windows PowerShell with POWER USER RIGHTS. Perform the following steps:

  1. Search for the Command Prompt application by typing cmd in the search field (displayed as a magnifying glass) of the Windows task bar.

  2. The left part of the search results will show the Command Prompt App as best match and it will be highlighted in blue. Click on Open file location (third from the top) in the right part displaying the options for the Command Prompt App.

  3. A File Explorer window will open with the shortcut to Command Prompt highlighted in blue. Right-click the Command Prompt shortcut and select ‘WUR - Run with adminstrative rights’ as shown in Figure 1 below.

Run CMD with 'WUR administrative rights' from File Explorer.
Run CMD with ‘WUR administrative rights’ from File Explorer.
  1. The Command Prompt application will open, as shown in Figure 2 below, on the folder C:\Windows. The top of the window shows that the Command Prompt application is used in Administrator mode (WARNING: BE CAREFULL!!).
Command Prompt with Adminstrative Rights.
Command Prompt with Adminstrative Rights.
  1. Change the working directory to C:\ProgramData. This is done by copying (CTRL+C) the following line, pasting (CTRL+V) it behind the prompt and pressing return (Enter) to execute.
cd C:\ProgramData
  1. Remove the directory C:\ProgramData\R\win-library\3.6 with all its content (subdirectories and files). This is done by copying (CTRL+C) the following line, pasting (CTRL+V) it behind the prompt and pressing return (Enter) to execute.
rmdir /S C:\ProgramData\R\win-library\3.6
  1. The question C:\ProgramData\R\win-library\3.6, Are you sure (Y/N)? will appear. Confirm the removal of the directory with all its content by answering Y.

  2. The Command Prompt application can now be closed by typing exit and executing it by pressing return (Enter).

If you have not installed another version of R, either via Software Center or via a custom installation, your computer should now be lacking a functioning R installation. Continue with the section Custom R installation to perform a new custom installation of R.

When you do still have a working R installation on your WURclient computer, return to Uninstall a previously installed R version and follow the procedure applicable to your situation.

Installed previously as a custom installation

Let’s assume you previously installed R version 3.6.3 on a WURclient computer (either a desktop or laptop) by following the steps for a custom installation of R as described in this post. For a newer version of R the steps are the same, but names of folders will differ with respect to the R version number.

To uninstall R and delete the manually installed packages (added yourself via the install.packages() command in R) perform the following steps:

  1. Open a File Explorer and navigate to the folder C:\MyPrograms\R\R-3.6.3. Right-click the file unins000.exe and select ‘WUR - Run with administrative rights’ as displayed in Figure 3 below.
Uninstall Custom R Installation from File Explorer.
Uninstall Custom R Installation from File Explorer.
  1. The uninstaller will start as shown below in Figure 4. Click the ‘Yes’ to proceed.
R for Windows Uninstall Announcement.
R for Windows Uninstall Announcement.
  1. Once the uninstallation has completed, a message of success will be display as shown below in Figure 5. Click the ‘OK’ button to finish.
R for Windows Uninstalled Successfully.
R for Windows Uninstalled Successfully.
  1. Search for the Command Prompt application by typing cmd in the search field (displayed as a magnifying glass) of the Windows task bar.

  2. The left part of the search results will show the Command Prompt App as best match and it will be highlighted in blue. Click on Open file location (third from the top) in the right part displaying the options for the Command Prompt App.

  3. A File Explorer window will open with the shortcut to Command Prompt highlighted in blue. Right-click the Command Prompt shortcut and select ‘WUR - Run with adminstrative rights’ as shown in Figure 6 below.

Run CMD with 'WUR administrative rights' from File Explorer.
Run CMD with ‘WUR administrative rights’ from File Explorer.
  1. The Command Prompt application will open, as shown in Figure 7 below, on the folder C:\Windows. The top of the window shows that the Command Prompt application is used in Administrator mode (WARNING: BE CAREFULL!!).
Command Prompt with Adminstrative Rights.
Command Prompt with Adminstrative Rights.
  1. Change the working directory to C:\MyPrograms. This is done by copying (CTRL+C) the following line, pasting (CTRL+V) it behind the prompt and pressing return (Enter) to execute.
cd C:\MyPrograms
  1. Remove the directory C:\MyPrograms\R\R-3.6.3 with all its content (subdirectories and files). This is done by copying (CTRL+C) the following line, pasting (CTRL+V) it behind the prompt and pressing return (Enter) to execute.
rmdir /S R\R-3.6.3
  1. The question R\R-3.6.3, Are you sure (Y/N)? will appear. Confirm the removal of the directory with all its content by answering Y.

  2. To delete the manually installed packages (added yourself via the install.packages() command in R) change the working directory to C:\ProgramData. This is done by copying (CTRL+C) the following line, pasting (CTRL+V) it behind the prompt and pressing return (Enter) to execute.

cd C:\ProgramData
  1. Remove the directory C:\ProgramData\R\win-library\3.6 with all its content (subdirectories and files). This is done by copying (CTRL+C) the following line, pasting (CTRL+V) it behind the prompt and pressing return (Enter) to execute.
rmdir /S C:\ProgramData\R\win-library\3.6
  1. The question C:\ProgramData\R\win-library\3.6, Are you sure (Y/N)? will appear. Confirm the removal of the directory with all its content by answering Y.

  2. The Command Prompt application can now be closed by typing exit and executing it by pressing return (Enter).

If you have not installed another version of R, either via Software Center or via a custom installation, your computer should now be lacking a functioning R installation. Continue with the section Custom R installation to perform a new custom installation of R.

When you do still have a working R installation on your WURclient computer, return to Uninstall a previously installed R version and follow the procedure applicable to your situation.

Custom R installation

To prepare the custom R installation a couple of folders need to be created prior to the installation of R. Perform the following steps exactly as described:

  1. Search for the Command Prompt App by typing cmd in the search field of the Windows task bar.

  2. The left part of the search results will show the Command Prompt App as best match and it will be highlighted in blue. Click on Open file location (third from the top) in the right part displaying the options for the Command Prompt App.

  3. A File Explorer window will open with the shortcut to Command Prompt highlighted in blue. Right click the Command Prompt shortcut and select ‘WUR - Run with adminstrative rights’ as shown in Figure 8 below.

Run CMD with 'WUR administrative rights' from File Explorer.
Run CMD with ‘WUR administrative rights’ from File Explorer.
  1. The Command Prompt application will open, as shown in Figure 9, on the folder C:\Windows. The top of the window shows that the Command Prompt application is used in Administrator mode (WARNING: BE CAREFULL!!).
Command Prompt with Adminstrative Rights.
Command Prompt with Adminstrative Rights.
  1. Create the directory C:\MyPrograms. This is done by copying (CTRL+C) the following line, pasting (CTRL+V) it behind the prompt and pressing return (Enter) to execute. In case the directory already exists, the message A subdirectory or file C:\MyPrograms already exists. will appear.
mkdir C:\MyPrograms
  1. Next create the directory C:\MyData. This is done by copying (CTRL+C) the following line, pasting (CTRL+V) it behind the prompt and pressing return (Enter) to execute. In case the directory already exists, the message A subdirectory or file C:\MyData already exists. will appear.
mkdir C:\MyData
  1. Finally create the directory C:\ProgramData\R\win-library\4.3, where user installed packages, via the install.packages() command in R, will be stored. The last part of the directory path reflects the major release version of R you are installing and should be adapted for other versions, e.g. for R v4.4.0 the directory created should end with 4.4. To create the beforementioned directory copy (CTRL+C) the following line, paste (CTRL+V) it behind the prompt and execute by pressing return (Enter). In case the directory already exists, the message A subdirectory or file C:\ProgramData\R\win-library\4.3 already exists. will appear.
mkdir C:\ProgramData\R\win-library\4.3
  1. The Command Prompt application can now be closed by typing exit and executing it by pressing return (Enter).

Download

At the time this post was written, the latest release of R was version 4.0.3. It has been updated to the latest release version 4.3.1 of R.

The installer for Windows 10 can be downloaded directly from this link: R 4.3.1 for Windows (ca. 79 MB, 64-bit).

From R version 4.2.0 the installer is only available for 64-bit Windows 10 and will not install on a 32-bit version of the Operating System.

Save the following files into the Downloads folder of your WURclient desk- or laptop by right-clicking the link and selecting the option ‘Save link as…’ (IMPORTANT: DO NOT CHANGE THE FILE NAMES!):

Installation

For newer versions of R than 4.0.3 the steps described below are the same and still correct, but start with a newer version of the downloaded executable file of R. The screenshots in this post have not been updated. Therefore, what you see during your installation will differ with respect to the version number shown in the screenshots.

  1. Right-click the downloaded file R-4.3.1-win.exe and select ‘WUR - Run with administrative rights’. This file will most likely reside in your Downloads folder of your user account.
  2. If asked for allow to install the software on your computer.
  3. After the installer has started, a first selection window will appear as displayed below in Figure 10. Select the English language and click the ‘OK’ button to proceed.
R Installation Language Selection.
R Installation Language Selection.
  1. Click on the ‘Next’ button to agree to the terms. After this a window will appear, allowing you to select or choose the destination folder, as shown below, where R version 4.3.0 for Windows should be installed. Change the destination location to C:\MyPrograms\R\R-4.3.1, as shown in Figure 11 below for version 4.0.3, by typing the destination path directly into the text field displayed (currently showing C:\Program Files\R\R-4.3.1) . Click on the ‘Next’ button to continue.
R Installation Destination Folder Selection.
R Installation Destination Folder Selection.
  1. After selecting the installation destination folder the component selector will appear, as displayed below in Figure 12. Most desktop and laptop computers these days are using a 64-bit architecture, therefore select (using the pull down menu) the 64-bit User installation as displayed in the image shown below and click on the ‘Next’ button.
R Installation Components Selection.
R Installation Components Selection.
  1. After selecting the components to install the startup options need to be set. Select, as shown in Figure 13 below, the customized startup by selecting the ‘Yes (customized startup)’ radio button followed by clicking on the ‘Next’ button.
R Installation Customize Startup.
R Installation Customize Startup.
  1. The first startup option to set is the Display Mode, as shown in Figure 14. Select the Single Document Interface by selecting the ‘SDI (separate windows)’ radio button as displayed and clicking on the ‘Next’ button.
R Installation Display Mode Selection.
R Installation Display Mode Selection.
  1. Next select the help style startup option. Leave this at the default ‘HTML help’ value, as displayed below in Figure 15, and click on the ‘Next’ button.
R Installation Help Style Selection.
R Installation Help Style Selection.
  1. The one before last startup option is to set a ‘Start Menu’ folder name (Figure 16). Unless wishing to use a different name, leave the default value as displayed below. This will create a folder named ‘R’ in the ‘Start Menu’ of Windows, from which the R GUI (graphical user interface) can be started.
R Installation Start Menu Folder Selection.
R Installation Start Menu Folder Selection.
  1. The last startup option to set allows for some customization of shortcut links. Preferably leave the default settings and continue by clicking on the ‘Next’ button. This will trigger the installation. At the end Figure 17, shown below, will appear (although the version number will be different!). To exit the setup click on the ‘Finish’ button.
Do not mess around with the ‘Registry entries’ settings.
R Installation Completed Successfully.
R Installation Completed Successfully.
  1. To finalize the custom R installation on your WURclient desk- or laptop copy the files Renviron.site and Rprofile.site from the Downloads folder on your computer and paste them into the C:\MyPrograms\R\R-4.3.1\etc folder. A window will appear, as displayed below in Figure 18, to indicate, that the file Rprofile.site already exists. Select ‘Replace the file in the destination’.
Replace Rprofile.site File.
Replace Rprofile.site File.
Congratulations, 😆, you now have R version 4.3.1 installed on your WURclient desktop or laptop computer!

Changing the R GUI working directory

When starting the default R GUI the current working directory can be displayed at the R prompt with the command:

getwd()

The response at the R prompt will be:

[1] "\\\\WURNET.NL/Homes/user001/My Documents"

where user001 will display your own WUR username.

This could potentially lead to NormalizePath() warning messages. Therefore, it is strongly recommended to set the working directory to a mapped drive (shown by a drive letter, e.g., C:, or M:) in your WURclient. This can be done at the R prompt using the following command, e.g., for setting your working directory to C:\MyData or M:/My Documents/:

setwd("C:/MyData/")
# or
setwd("M:/My Documents/")

No matter which mapped driva and folder you choose, make sure that the location and folder you are providing for the working directory exists!

When using the default R GUI, always change the working directory at the start with the setwd() function at the R prompt!

In earlier versions of this post, the R startup working directory was changed inside the Rprofile.site file. This lead to problems when using the knitr package to compile to portable document format.

Based on posts by Yihui Xie (the developer of the knitr package) the setwd() command in Rprofile.site has been hashed out, making knitting to pdf possible again.

Maikel Verouden, Ph.D.
Maikel Verouden, Ph.D.
Researcher | Lecturer | IT & Organization contact person

My research interests include Statistics, Teaching and programmable matter (statistical software).