Skip to navigation

R: Installing weaver to cache Sweave code chunks

May 28th, 2009

The package weaver lets you cache code chunks in your .Rnw file so the computations don’t have to be repeated if you only make small changes to the document — potentially a huge timesaver.

If you simply try to install it using install.packages(), you will get the message that the package weaver cannot be found. Instead, you have to do the following. Get package “digest” if you don’t have it yet (I didn’t). In R, as root (unless you have a per-user local installation):

install.packages("digest")

Then:

source("http://bioconductor.org/biocLite.R")
biocLite("weaver")

Look at the documentation on the weaver site for information on how to use it, from within R or from a shell script.

R: lme4/ Matrix not finding “libRlapack.so”

March 20th, 2009

I had a problem in R when trying to load the package lme4 on Xubuntu Intrepid:

> library(lme4)
Loading required package: Matrix
Loading required package: lattice
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared library '/usr/local/lib/R/site-library/Matrix/libs/Matrix.so':
  libRlapack.so: cannot open shared object file: No such file or directory
Error: package 'Matrix' could not be loaded

Found solution here, which is as follows:

sudo ln -s /usr/lib/R/modules/lapack.so /usr/lib/libRlapack.so

How to use mutt to send individual e-mails to lots of people at once

March 18th, 2009

So, you want to send an e-mail to a list of people, but you don’t want to put them all in the “To:” or the “Bcc:” field of a single mail. You want each person to get an individual e-mail, but with the same subject line and the same content. It’s easy using mutt.

  • Create a text file that contains all the recipients, one on each line. This can be the full e-mail address, or it can be the alias you have defined in your mutt aliases file (which is your mutt “addressbook”). For our example, we’ll call it recipients.txt
  • Create a text file with the text of your message. Let’s call it message.txt.
  • Create a bash shell script containing the following:
    #!/bin/bash
    while read line
    do
    mutt $line -s 'Message subject'  < message.txt
    done < recipients.txt

    Where "Message subject" is whatever your message subject should be. Of course, you need to run your shell script from the directory in which the files "message.txt" and "recipients.txt" are stored. Otherwise, you need to substitute their names with the full path name, e.g. ~/message.txt.

  • Make your bash script executable and run it. Done. Your individual e-mails should show up in your mailfolder for sent mail (defined by set record=... in your ~/.muttrc.

LaTeX: using apacite and hyperref in the same document

March 18th, 2009

The latest (4.0) version of apacite no longer conflicts with the
package hyperref, but you must load hyperref before
apacite
.

That is, the preamble of your document should look something like this:

\documentclass{article}
... other packages etc ...
\usepackage{hyperref}
\usepackage{apacite}
\begin{document}
... 

At least, that is the only way it worked for me. When I had apacite
loaded first, LaTeX would hang on the second run, with an error
message along these lines:

! Undefined control sequence.
\hyper@@link ->\let \Hy@reserved@a
...

Rsync: syncing back and forth using only one single ssh connection

February 20th, 2009

Rsync is really handy for transferring files and keeping directories in sync, and it’s damn fast. If you transfer only very little, what takes longest is actually establishing the SSH connection to the server. While this is usually negligible, it has still irked me. Some googling turned up this post. Nice. One SSH tunnel for rsyncing back and forth.

Here’s a little example for a shell script I use to sync my mutt directory up and down:

if `ping -c1 $server > /dev/null 2>&1` ; then                                          
    ssh -S $HOME/.tunnel.socket -M -N -f $server  # create shared connection                       
    $HOME/bin/muttup && $HOME/bin/muttdown          # sync up and down                               
    ssh -q -S $HOME/.tunnel.socket -O exit $server 2> /dev/null # close shared                     
                                                                  # connection                       
fi

I’ve set this to run whenever mutt starts, to keep my mutt stuff synced across different machines. (muttup and muttdown are obviously other tiny scripts. I keep them separately so I can run them individually)