R Graphical Representation – Installing tikzDevice Package

I have R code embedded within LaTeX files that make use of R plots, and I use Sweave to generate corresponding standalone TeX files. In addition to that though, I also make use of the R tikzDevice package to ensure that the fonts in my R plots are consistent with my LaTeX document. As it turns out, R commands are output at a low level as tikZ commands [1].

I am working on a different machine today and the error below popped up when I tried to Sweave one of my files.

scap@scap-lenovo-g560:~/Projects/masters/msc-thesis/chapter06/figures$ R CMD Sweave survey-background-info.Rnw
Writing to file survey-background-info.tex
Processing code chunks with options ...
 1 : keep.source term verbatim pdf
Loading required package: tikzDevice
Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
 there is no package called ‘tikzDevice’

Error: chunk 1
Error in eval(expr, envir, enclos) : could not find function "tikz"
Execution halted
scap@scap-lenovo-g560:~/Projects/masters/msc-thesis/chapter06/figures$

I got onto the R console and true to that, tikzDevice package is not installed on this machine.

> library('tikzDevice')
Error in library("tikzDevice") : there is no package called ‘tikzDevice’
> require('tikzDevice')
Loading required package: tikzDevice
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
 there is no package called ‘tikzDevice’
>

So here is how I went about installing the tikzDevice package.

Environment Setting
I work with R version 2.14.1 on an Ubuntu 12.04 box.

> version
 _
platform i686-pc-linux-gnu
arch i686
os linux-gnu
system i686, linux-gnu
status
major 2
minor 14.1
year 2011
month 12
day 22
svn rev 57956
language R
version.string R version 2.14.1 (2011-12-22)
>

I initially tried installing the package the normal way but got a rather disturbing warning message shown below… I mean as far as I could tell, my R version was updated and thus compatible with the tikzDevice package.

> install.packages('tikzDevice')
Installing package(s) into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Loading Tcl/Tk interface ... done
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
 package ‘tikzDevice’ is not available (for R version 2.14.1)
>

I decided to poke around the Web and came across this thread [2]. The package installation failed, as shown below, and it turns out, tikzDevice packages is dependent on the filehash package and so I basically performed the installation in two phases.

> install.packages("tikzDevice", repos="http://R-Forge.R-project.org")
Installing package(s) into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)

Warning: dependency ‘filehash’ is not available
trying URL 'http://R-Forge.R-project.org/src/contrib/tikzDevice_0.6.3.tar.gz'
Content type 'application/x-gzip' length 1733547 bytes (1.7 Mb)
opened URL
==================================================
downloaded 1.7 Mb

ERROR: dependency ‘filehash’ is not available for package ‘tikzDevice’
* removing ‘/usr/local/lib/R/site-library/tikzDevice’

The downloaded packages are in
 ‘/tmp/Rtmph2kaKy/downloaded_packages’
Warning message:
In install.packages("tikzDevice", repos = "http://R-Forge.R-project.org") :
 installation of package ‘tikzDevice’ had non-zero exit status

I finally got it to work by first installing the dependency –the filehash package and finally the tikzDevice package from the source.

STEP 1: Install filehash package

> install.packages('filehash')
Installing package(s) into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'http://cran.mirror.ac.za/src/contrib/filehash_2.2-1.tar.gz'
Content type 'text/plain' length 133446 bytes (130 Kb)
opened URL
:
:

STEP 2: Install tikzDevice package from source

> install.packages('tikzDevice', repos="http://R-Forge.R-project.org")
Installing package(s) into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'http://R-Forge.R-project.org/src/contrib/tikzDevice_0.6.3.tar.gz'
:
:

Loading the package finally gave me what I wanted to see 🙂

> require('tikzDevice')
Loading required package: tikzDevice
Loading required package: filehash
filehash: Simple key-value database (2.2-1 2012-03-12)
tikzDevice: R Graphics Output in LaTeX Format (v0.6.2-92-0ad2792)
 LaTeX found in the PATH using the command: pdflatex
 XeLaTeX found in the PATH using the command: xelatex
 LuaLaTeX found in the PATH using the command: lualatex
>

Please leave a comment if you know of an easier way to install the package. I hope this helps.

Bibiliography

[1] http://www.texample.net/tikz/examples/tikzdevice-demo/s
[2] http://r.789695.n4.nabble.com/tikzDevice-not-available-td4640395.html