Installing Some Basic R Packages in Ubuntu

Standard

The following is how I configured my R workspace (and Rstudio) and this was first shared on a Coursera’s “Getting and Cleaning Data” course forums.

First make sure that R is version 3+. If not update it according to this stackoverflow question.

Java for rJava

Install Java (needed for rJava) first from a terminal:

sudo apt-get install openjdk-6-jre

which will install openjdk-6-jdk.
If this doesn’t work install all its packages:

sudo apt-get install openjdk-6-*

OR you might prefer openjdk-7-jdk

sudo apt-get install openjdk-7-*

You should find that it is installed using this command:

sudo apt-get install libmysqlclient-dev # in the terminal
sudo R CMD javareconf

XML package

sudo apt-get install libxml2-dev

source: http://stackoverflow.com/a/7765470

Another source stated this (have NOT tested it!):

sudo apt-get install libmysqlclient-dev # in the terminal
sudo apt-get install r-cran-xml

rJava

sudo apt-get install libmysqlclient-dev # in the terminal
sudo apt-get build-dep r-cran-rjava

source: http://cran.r-project.org/bin/linux/ubuntu/

Now in RStudio

install.packages("rJava")

if you get

* DONE (rJava)

then its installed.

source: http://stackoverflow.com/a/16453399

Similarly for xlsxjars & xlsx (one command at a time)

install.packages("xlsxjars")
install.packages("xlsx")
install.packages("jsonlite")

data.table

data.table is another basic and important package. It contains the fread() function that reads files and is especially fast relative to read.csv and read.table
Install it from within R(studio)

install.packages("data.table")

source

RMySQL

sudo apt-get install libmysqlclient-dev # in the terminal

Hmisc & jpeg

install.packages(c("Hmisc", "jpeg"))

This should do it.

Note: xlsx depends on xlsxjars & rjava. And xlsxjars depends on rjava. That’s why you have to install them in this order. Otherwise you could use the following format for multiple packages:

install.packages(c("package-1", "package-2"))

Update: I have a new post on customizing the R environment with an Rscript. Check it out here.

Advertisement

5 thoughts on “Installing Some Basic R Packages in Ubuntu

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s