Installation

To download R:

  • Go to https://cran.r-project.org/

  • Click “Download R for Mac/Windows”

  • Download the appropriate file:

    • Windows users click Base, and download the installer for the latest R version

    • Mac users select the latest R version that aligns with your OS version

  • Follow the instructions of the installer.

To download RStudio:

For Windows - Install Rtools (needed build R packages with C/C++/Fortran code from source)by visiting this page https://cran.r-project.org/bin/windows/Rtools/rtools40.html

Upgrade/Update

At some point, running old versions of software adds unnecessary difficulty. Is your R version “old”? R had a major version change in April 2020, with the release of 4.0.0. It is a good idea to be on the current major version, meaning 4.something(in 2022). Each major version is followed by several years of smaller releases (minor and patch releases). You can be more relaxed about upgrading minor versions, but you still want to stay reasonably current.

R.version.string
#> [1] "R version 4.1.2 (2021-11-01)"

Then go to <https://cran.r-project.org/> and check if you have the same version. It is almost a must for your version to have the same first number, as the latest stable version, second desirable, and third optional.

Updating RStudio is easy, just go to Help > Check for Updates to install newer version.

Libraries/Packages

CRAN Libraries/Packages

Installation

Several libraries will be necessary to reproduce the provided R materials. Initially, they are listed with some basic background for the future reference. they are also stored in one character vector. These packages could be installed by running the code provided below.

list.of.packages <-
  c(
    "devtools", # package development 
    "conflicted", #Some functions are named the same way across different packages and they can be conflicts and this package helps sorting this problem 
    "here", #helps with the reproducibility across operating systems=
    "conflicted", #Some functions are named the same way across different packages and they can be conflicts and this package helps sorting this problem 
  
    # data import
    "readr", 
    "readxl", # import of data from excel files
    
    # data mundging
    "dplyr", # data manipulation
    "tidyr", # tidying data
    "tidyr", # "modern" data structures
    "reshape2", # reshaping the data
    "purrr", # tools for working with functions and vectors
    
    # Ploting 
    "ggplot2", # most popular 2D visualisation tool in R
    "plotly", # another advanced visualization tool
    "ggsci", # color palletes 
    "ggthemes", # ggplot themes 
    "patchwork", # combine plots
    "stringr", # string manipulation 
    "stringr", # factor manipulation

    # Analysis/Modelling 
    "minpack.lm", # fitting non-linear models
    "deSolve", # solvers for Initial Value Problems of Differential Equations
    "psych",
    "car",
    "emmeans",
    "agricolae", #diverse functions and datasets for agronomy 
    
    # Visualising outputs of statistical analysis 
    "rcompanion", # Useful tool for summarizing model outputs and several other modeling related tasks
    "ggResidpanel", # Diagnostic plots for several models

    # Parallel computation (using multiple cores to execute R code)
    "pbapply", 
    "parallel",

    # Text formatting 
    "rmarkdown",
    "gt", # package for customizing html table view
    "kableExtra", # Another package for html table customization
    
    # Advanced visualisations/ App building
    "shiny", # Package for visualization 
    "shinyscreenshot", #capture screenshots
    "shinydashboard"
  )

Now these packages are installed by passing the vector containing their names to the installation function. Things should go smoothly if your R version is up to date, but…

# You might need to restart R during this process
install.packages(list.of.packages)
# When prompted 

If there are problems installing some package, sometimes defining different repositories helps sorting the issue.

# uncomment the following line, change the name of package and run
#install.packages("ROCR", repos = c(CRAN="https://cran.r-project.org/")) 

To check if all of the packages are installed run following command:

list.of.packages %in% installed.packages()

If you see some FALSE values there, then you can check which package is missing and install it using above specified commands.

list.of.packages[!(list.of.packages %in% installed.packages()[, "Package"])]

Updating

Windows

One wants to update installed packages as often as possible. You might need to restart R during this process, too. On Windows this is straightforward.

update.packages(ask = FALSE, checkBuilt = TRUE)
Other OS

But for other operating systems, after updating R, a lot of packages might have been build under the old R version and it would be safer to re-install all the packages already installed. This can be done with the following commands. Again this won’t update packages installed with devtools::install_github()

## get packages installed
packs = as.data.frame(installed.packages(.libPaths()[1]), stringsAsFactors = F)

## and now re-install install packages using install.packages()
install.packages(packs$Package)

Non-CRAN Packages

There are packages which are not published in public repositories. These are installed directly from some public repository, such as GitHub.

.rs.restartR()
Sys.sleep(2)
remotes::install_github("bbc/bbplot",dependencies = TRUE)

If you run into problems… Installing packages that are not on CRAN can be a pain, so there are a few general notes on what to do.
If you are Windows user it is recommended that you make sure you have the Rtools installed. If you get an error looking like this while updating your packages:

Error: (converted from warning) cannot remove prior installation of package ‘name_of_the_package’

You might need to update some packages manually to match the source version. So, just replace the name_of_the_package to match the name of the package you are missing/need to update.

install.packages("name of the package", type = "source")

After that, try run the code snippet for the installation of package from the beginning of this subsection.

Install our package with apps

Run following lines of code

if(!"devtools" %in% installed.packages ()) install.packages("devtools")
devtools::install_github("mladencucak/AppTest")
AppTest::GrowModAPP()
AppTest::HLIRApp()