Skip to content

Installing R & RStudio

Sam Albers edited this page Apr 20, 2020 · 13 revisions

Instructions for Installing R & RStudio on a Windows 7 and 10 B.C. Government Computer

*Note that the B.C. Software Centre has R and RStudio packaged for installation. If you install from the Software Centre, skip steps 1 and 2. If you have your supervisor's approval (following the Appropriate Use Policy), follow steps 1 and 2 to get up-to-date versions of the software.

  1. Install R from this webpage (or click here to download the current version directly). Accept the defaults for all the installation options.

    • Complete this step if you are updating R: Uninstall previous version of R, and go to C:/Program Files/R/[prev_R_version] and delete all folders and files left over.
  2. Install RStudio: Go to https://www.rstudio.com/products/rstudio/download/#download, and download and install the version for your system. Accept all of the defaults for the installation options.

  3. Open command prompt (Open Start Menu then type cmd and press [Enter]). Note: Make sure your command prompt shows the C:> directory. If it shows any other letter (ie H:) type C: to change to the correct directory.

Now type the following line into the command prompt window exactly as shown:

setx HOME "%USERPROFILE%"

Press [Enter], you should see SUCCESS: Specified value was saved. Quit command prompt by typing exit then pressing [Enter].

  1. Open RStudio and test installing and loading a couple of packages by typing (or copying and pasting) the following at the command prompt (>):

    .libPaths()

    The output should look something like this1:

    [1] "C:/Users/[your_username]/R/win-library/[R-version]/"     "C:/Program Files/R/[R-version]/library"
    
  2. It's a good idea to test installing some packages. Try:

    install.packages(c("dplyr", "ggplot2"))

    If you get no errors, and a message saying: "Installing package into 'C:/Users/[your_username]/R/win-library/[R-version]/'" (plus more) you should be good to go!

  3. If you are updating R from a previous version, you will need to update your packages as well. Run:

    update.packages(checkBuilt = TRUE)

    This will ensure your packages were built for the version of R that you are runnning.

Other tips:

  • Work locally: It is a good idea to try to do your R work on your hard (C:/) drive whenever possible as it is usually much faster than working over the network, especially reading and writing large data files or if you use Git for version control. However, note that C: drives are not backed up, so make sure you have a strategy in place for making sure any work you do on your C: drive is backed up.

  • Keep your packages up date: Check for package updates every day by clicking Tools -> Check for Package Updates in RStudio. You'll get the latest bug fixes and features in your packages and it will make sharing code with other people easier if we all have up-to-date packages.

  • Use Git & GitHub for version control: See the B.C. Policy Framework for GitHub for how to get started using GitHub in the B.C. Government. Happy Git with R is an excellent resource for best practices using Git & GitHub with R & RStudio.

Footnotes

1If it doesn't, then it is a good idea to check your .Renviron file to see if an R_LIBS variable is not overriding the value set in step 3. If you see something like:

R_LIBS = something that is not "C:/Users/[your_username]/R/win-library/[R-version]/"

try commenting out that value, restarting R and running step 6.