Thursday, 5 January 2012

Finding files duplicates

One of my all time favourites : fdupes. You have a bunch a files in a directory (and/or sub-directories) and you suspect that some of them have the same content but different filenames. Fdupes will find them and will list them for you (or prompt you to delete them with the -d option).


Syntax : 

fdupes [ options ] DIRECTORY

The -r option will search sub-directories recursively. Look up the MAN page for some other useful options.

Wednesday, 4 January 2012

Exporting a Lattice plot as a grayscale PDF file

Took me a while to figure out how to output a simple grayscale plot using the Lattice package.

A few solutions are provided here : http://stackoverflow.com/questions/3712402/r-how-to-change-lattice-levelplot-color-theme. However, I somehow had troubles using the PDF device in R: the output file was blank. Using the PNG device works fine, but I'd rather have PDF files included in my thesis as I'm working with LaTeX.

The simplest solution was to output a PDF with the basic Lattice code then to use the gs command in bash to convert to grayscale. Job done!


1. Output the plot :
pdf(file='myfile.pdf')
## my lattice plot code
dev.off()


2. Convert to grayscale using gs in bash :
$ gs -sOutputFile=output.pdf -sDEVICE=pdfwrite -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray -dCompatibilityLevel=1.4 myfile.pdf < /dev/null


The result simply looks like this :






Saving a lattice plot with grayscale directly in R can be a bit too tricky, to me this is by far the fastest solution around.