Software Requirements

For the purpose of following the examples and working on your assignments we strongly encourage you to install the following packages on your laptops:

  • "git bash" (https://git-scm.com), which is a version control system tool which also brings along a command line Linux-style terminal.
    We will be using in the first week.  If you are using a Windows system you are particularly encouraged to install this software.
  • R, preferably "plain"-R, i.e. not RStudio!, as some of the features we will be exploring during the course are not necessarily available within IDEs (Integrated Development Environments), such as RStudio.

Strange characters in your scripts?

If your text editor is adding some weird characters at the end of the lines, try running the following command from git-bash in the directory where your scripts are:

cat -v myScript.R

If you see "^M" being displayed at the end of the lines, then your encodings are wrong. Try setting your encodings to UTF-8, usually this can be done in the preferences section. If you are using Atom, look at the very bottom of Atom, you will notice that there are 4 clickable panels, check that the first one says "LF" and the second one says "UTF-8", if it doesn't click on each of them and select the corresponding ones from the list displayed. That should help to fix the issue of the encodings.

To make the change permanent in Atom, go to File -> Settings -> Packages and search for "line-ending-selector". When you see the line-ending-selector box, click on Settings. Change the "Default line ending" to "LF". This should make all new files use LF new lines instead of CRLF.


Warning: LF will be replaced by CRLF in myScript.R

If you are using Windows, and git-bash, you may start seeing the warning message warning: LF will be replaced by CRLF in myScript.R when trying to save a git commit of myScript.R. To get rid of this warning, at the bash prompt type the command

git config --global core.autocrlf false


Using Rscript in git-bash on Windows Machines

If you are using a Windows machine and git-bash as your shell (terminal) you may run into a problem when trying to use "Rscript" or "R CMD BATCH" from the command line.  The command may not work, with an error message like: 'command not found'.

The problem is that you need to tell git-bash where to find the R program. There is a predefined variable, called "PATH", which is created automatically when you start a bash session. This variable tells the shell where to look for commands. You need to add the path to your R installation to your PATH variable.

To make the change permanent, we suggest the following.

  1. open your text editor (Atom, Sublime, etc.)
  2. put the following line in it: export PATH=${PATH}:"/c/Program Files/R/R-3.6.1/bin/x64" (confirm that this is the correct path to your R installation. If you have a different version of R the path will be slightly different.) Make sure you put those quotation marks in.
  3. save the file in your home directory (/c/Users/yourusername) with the filename ".bashrc" (make sure to have the file start with a period).  Please notice that some text editors, such as Notepad++, may automatically add a ".txt" extension to the filename. You will have to fix this as it won't work otherwise. For doing so, you can try the following command in the git-bash terminal,
  4. mv -v -i ~/.bashrc.txt ~/.bashrc
  5. Restart your bash program. The PATH variable should now be able to see Rscript.

Installing Libraries for Rscript in Windows Machines

We've been getting quite a few reports of errors when trying to run Rscript from the command line, for users of Windows. The error message is that Rscript can't find the 'ape' package, even though it is installed and works fine when run from within R. If you are encountering this error, please follow the following steps.

From within the R console, type the command ".libPaths()". The directory of interest, which is used below, will be the first entry listed. It will look something like C:/Users/username/Documents/R/win-library/3.4

Now, using your favourite text editor (Atom, Sublime, etc.), open your ".bashrc" file. This will be in your home directory.  Add the following two lines to the end of the file, replacing the directory below with the one you found using ".libPaths()": 

export R_LIBS=C:/Users/username/Documents/R/win-library/3.4 # don't use this! Use the correct path on your computer!
export R_ENVIRON_USER=$R_LIBS

Alternatively, you may need to use

export R_LIBS=/c/Users/username/Documents/R/win-library/3.4 # don't use this! Use the correct path on your computer!
export R_ENVIRON_USER=$R_LIBS

Close git bash. Re-open Git bash and try the command again. Rscript should now be able to find the 'ape' package.


Enabling colour in Atom 

If you are using the Atom editor, you may have noticed that by default R code is not colour-coded ("syntax highlighted", in the technical jargon). To enable R syntax highlighting in Atom, perform the following steps:

  • Find the "Settings" menu. On a Mac this is under Atom -> Preferences.
  • Click on the "Install" tab. Then search for the "language-r" package.
  • Click on Install.

Atom should now use R syntax highlighting on any file that ends in ".R".


Warning message: Setting LC_CTYPE=en_US.UTF-8 failed on Windows

If you are getting the warning message

Warning message: Setting LC_CTYPE=en_US.UTF-8 failed

every time you run Rscript these are the steps you need to perform to remove the warning.

  • Open your text editor (Atom, Sublime, etc.).
  • Copy and paste the following lines in it:

    LC_COLLATE="English_United States.1252"
    LC_CTYPE="English_United States.1252"
    LC_MONETARY="English_United States.1252"
    LC_NUMERIC="English_United States.1252"
    LC_TIME="English_United States.1252"

  • Save the file in your home directory (/c/Users/yourusername) with the filename ".Renviron" (make sure to have the file start with a period).
  • Restart you terminal program. The warning message should be gone.
Last modified: Tuesday, 5 September 2023, 1:13 PM