Table of Contents
How to install R and Rstudio
For semester 112-1: make sure that you have the latest version of R and RStudion installed on your computers:
- R - version 4.3.1 or newer
- RStudio - version 2023.06.1+524 or newer
Note that first, you need to install (or update) R on your computer (this is where all commands are processed), and then you install RStudio (this is just an editor, a wrapper around R). RStudio without R does not work, and installing or updating only RStudio without R is insufficient.
How to install R
- Download the installation file of the newest R version from CRAN1). Choose your operation system (e.g.
Donwload R for Windows), and then choose either
Install R for the first timeif you haven't install R before you your computer, or
baseif you already did and you are installing a new version; download the installation file and proceed further). If you are using Mac, you may need to Google some help (eg see this website for help).
- Install the R program - you may keep the default location of installation files in Program Files/R. On Windows, the R folder in your Program Files folder may contain several subfolders with different R versions installed in parallel, e.g. R-2.10.1, R-2.11.1 etc.
- When you run the R program, you may change some basic setting (e.g. the size of the font, colour of the background (if you feel it is more comfortable to have it e.g. orange) in menu Edit > GUI preferences. If you change anything in this window, you need to click on Save button and save the file Rconsole to the folder /Program Files/R/R-version/etc.
How to update R
If you have R already installed on your computer and you want to update to newer version, the easiest way is simply to install the new version along the old one (and later possibly delete the old one if you don't need it or you want to save space on hard drive). All R versions are, if not changed, installed beside each other in R subfolder of Program Files folder (in the case of Windows). You may need to install also all the packages you used in the previous version. You can simply copy the folder
library from the old R version to new R version and run an update procedure in new R version using the command
update.packages. For this, do the following:
- Close all running R programs (or RStudio) before starting!
- Open some file manager (like Total Commander or Windows Explorer) and locate the
libraryfolder with R libraries from the previous version. This is usually located in c:\Program Files\R\R-x.x.x\library, where R-x.x.x is the number of the previous R version, e.g. R-3.1.2. In some cases it could, however, be somewhere else; if not sure, open R, and type
.libPaths ()to see location of library path on your computer.
- Copy all subfolders in
libraryfolder of the new version. Do not overwrite the newer versions of files in the
libraryfolder of the new R version.
- Open the new R version, and update all packages using command
update.packages(ask = F)2). This should update all the packages to their latest version compatible with current version of R.
How to install RStudio
Download the latest version from RStudio website; you will need Desktop version, Open Source Edition for your system; you may click here to get directly to the selection of actual RStudion version. Follow instructions for installation. If you already have RStudio installed in your computer, please check whether you have the latest version and update if you don't (in RStudio menu, go to Help > Check for Updates).
RStudio is a convenient software, which combines R program with text editor and graphical user interface (and offers much more, like organization of scripts and outputs into a projects within single folder, and for advanced users also convenient building of packages, document markup etc.). One thing I found a bit not handy is RStudio's native graphical output - it offers its own unique sizeable graphical output into one of the subpanels (usually the bottom-right one), but it sometimes produces troubles (especially in case when you draw more complex figures). The workaround is to open the original R drawing panel - just type
windows () into the console, and new active window will open (you can move it around the screen, or right-click on it by mouse and select “Stay on top” to keep it as the top window always visible on your screen).
Optionally, there is a number of other text editors, which can be associated with R, e.g. Tinn-R. You are free to use the editor of your choice. In the class, I will use RStudio.
ask = Fin the function
update.packagesmakes sure that the update function will not ask you to prompt updating each package separately.