What does this package look like?

May 1, 2012
By

(This article was first published on tuxettechix » R, and kindly contributed to R-bloggers)

In this post, I give a very simple trick to understand the way a package is organized, which functions are included in and how these functions depend from each others. The idea has been brought by one of my student, Soraya, who is currently working in a very hostile environment, surrounded by true geeks. However, she handles the situation pretty well and manages to take the best from them. As I asked her to insert in her report a chart representing the dependency structure between her functions, she learned from them that tools existed to produce such charts automatically and was able (thanks to R blogger) to find one in an R package.

Suppose that you want to know which functions are included in the package GeneNet (that is of interest for another of my students) and to understand the dependency structure between these functions. First, download the package source, decompress it and use the subdirectory R as the working directory of your R session. If you’re on linux, the following command lines will do the job:

tar zxvf GeneNet_1.2.5.tar.gz
cd GeneNet/R
R

Then, collect and source all files located in this subdirectory and use the function foodweb (from the package mvbutils) to display the dependency structure between functions in this package:

?View Code RSPLUS
thefiles = list.files()
sapply(thefiles,source)
library(mvbutils)
par(mar=rep(0.1,4))
foodweb(border=TRUE,boxcolor="pink",lwd=1.5,cex=0.8)

which gives the following picture:

To spare my student’s time, I did the same with simone

and igraph for which I had to exclude a configuration file:

?View Code RSPLUS
thefiles = setdiff(list.files(),"config.R.in")
sapply(thefiles,source)
library(mvbutils)
par(mar=rep(0.1,4))
foodweb(border=TRUE,boxcolor="lightgreen",lwd=1.5,cex=0.8)


I’m not sure whether the last one is very useful ;-)

Now, Soraya is just waiting for her “warhol-R-rabbit” that Paul has promised her to include in her report. It’s gonna be a pop art variant of:

I’m really looking forward to post the R script for it!

To leave a comment for the author, please follow the link and comment on his blog: tuxettechix » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , , ,

Comments are closed.