"A big computer, a complex algorithm and a long time does not equal science." -- Robert Gentleman
lunedì 11 maggio 2009
vim plugin for R
http://www.vim.org/scripts/script.php?script_id=2628
mercoledì 29 aprile 2009
screen in ubuntu 9.04
martedì 31 marzo 2009
Multiple plot in a single image using ImageMagick
If you generate all your plot with R base graphics you can easily accomplished the task using the par() function, e.g., using par(mfrow=c(2,2)) and then drawing 4 plots of your choice.
However, if you need to create a single image build up from different sources, e.g. external images, plots not compatible with R base graphics, etc. , you can create/retrieve the single images and then merge them together using the tools from the Unix (Linux, Mac OS X, etc.) ImageMagick suite.
## Example # we generate some random plot require(seqLog) ## the first plot is taken from the seqLogo help ( ?seqLogo ) ## I selected this example on purpose because the seqLogo function is based on the grid graphics and is coded in such a way that doesn't allow the use of the par() function mFile <- system.file("Exfiles/pwm1", package="seqLogo") m <- read.table(mFile) pwm <- makePWM(m) png("seqLogo1.png", width=400, height=400) seqLogo(pwm) dev.off() ## totally unrelated png("plot1.png", width=400, height=400) plot(density(rnorm(1000))) dev.off()
Then you can type:
system("convert \\( seqLogo1.png plot1.png +append \\) \\( seqLogo1.png plot1.png +append \\) -background none -append final.png")
Remember that in R you have to start escape character with '\' !
Or, alternatively, from the command line:
convert \( seqLogo1.png plot1.png +append \) \( seqLogo1.png plot1.png +append \) -background none -append final.png
See man convert and man ImageMagick for the full story.
martedì 6 maggio 2008
Replacing Tabs with spaces and back in VIM
If you need to remove all the blank spaces from a file and replace them with tabs for easy importing in R, you can do it in VIM in no time. In normal mode type:
:set noexpandtab
:%retab!
The full story here
lunedì 30 luglio 2007
screen - an other VERY useful Unix tool
from R News Vol. 7/1 April 2007 (http://cran.r-project.org/doc/Rnews/Rnews_2007-1.pdf):
If you need to run R code that executes for long periods of time upon remote machines, this amazing unix tool would became your best friend!
screen is a so-called terminal multiplexor, which allows us to create, shuffle, share, and suspend command line sessions within one window. It provides protection against disconnections and the flexibility to retrieve command line sessions remotely.
Starting using this utility is easy like ABC:
- Log in to remote server
- Run screen
- Run R and the long calculation
- Detach screen (Ctrl-a, Ctrl-d)
- Logout
The R session continues working in the background, contained within the screen session. If we want to revisit the session to check its progress, then we:
- Log in remotely via secure shell
- Start screen -r, which recalls the unattached session
- Examine how your calculation/script is performing
- Detach the screen session, (Ctrl-a, Ctrl-d)
- Log out
This procedure can be used, clearly, for invoking whatever unix program/command you need to use; it is sufficient to substitute the R invoking command with your invoking command line program(for example python).
As usual in the shell-space, invoking man
mercoledì 18 aprile 2007
It's not R but It's VERY useful
Example (you must be in a unix environment with GNU free software):
sed 's/old_word/new_word/g' text_file > new_text_file
After which, new_text_file will contain the contents of text_file, except with the new_word values in place of the old_word values. For those interested in more detailed information, as usual, man (in this case man sed) is your friend.