How To Install R on Linux Mint 19 and configure PyCharm

Install R on Linux Mint

Installation is straightforward and consists of a few commands. This will install latest version 3.5 (which include many major changes) and will use standard repository for the installation. So first to add key and repository:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'
sudo apt update

If everything was fine now you can install R by:

sudo apt-get install r-base

This will install R version 3.5. You can start it by:

sudo -i R

or simply by

R

The output should be something like:

R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

If you want to install R packages and do a simple test in are you can do:

> install.packages("ggplot2")
> install.packages('txtplot')

Loading of installed libraries is done by:

> install.packages("ggplot2")
> library('txtplot')

Usage of libraries:

ggplot(mpg, aes(displ, hwy, colour = class)) + 
  geom_point()
textplot(loc[,1],loc[,2],rownames(loc))
txtplot(cars[,1], cars[,2], xlab = 'speed', ylab = 'distance')

Closing R

quit()

or

q()

PyCharm integration

In order to use R with PyCharm you need to install additional plugin (if you don't add it on the installation):

  • File
  • Settings Ctrl+Alt+S
  • Plugins - from left pane
  • Browse JetBrains Plugins Dialog
  • Search for R plugin
  • Download and Install
  • Confirm installation
  • OK

Once the plugin is installed you can create new R file by right click of the mouse and select R script.

Sample R script:

library('txtplot')
txtplot(cars[,1], cars[,2], xlab = 'speed', ylab = 'distance')

it can be run as the other scripts by: Ctrl+Alt+F10