Visualizzazione post con etichetta tool. Mostra tutti i post
Visualizzazione post con etichetta tool. Mostra tutti i post

mercoledì 29 aprile 2009

screen in ubuntu 9.04

As I told in a previous post, I consider the unix tool screen essential for my work. It seems that the just released Ubuntu 9.04  contains a package that make it easier to configure and use. You can find the full story here.

martedì 31 marzo 2009

Multiple plot in a single image using ImageMagick

Sometimes you need to add several plots/images either by row or by column to a single page/sheet.
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

Not specifically R-related.
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:

  1. Log in to remote server
  2. Run screen
  3. Run R and the long calculation
  4. Detach screen (Ctrl-a, Ctrl-d)
  5. 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:

  1. Log in remotely via secure shell
  2. Start screen -r, which recalls the unattached session
  3. Examine how your calculation/script is performing
  4. Detach the screen session, (Ctrl-a, Ctrl-d)
  5. 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 (man screen in this case) will provide all sort of information you need to know about the tool.

mercoledì 18 aprile 2007

It's not R but It's VERY useful

On the chance that you are talking about replacing a word, say, 500 times in a large text file, you might be interested in sed.

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.