Skip to navigation

Mutt: set dynamic email signature from shell command output

October 3rd, 2009

I want to set my signature when mailing to the r-help mailing list to contain information about the R version I have currently installed. Creating a bash script that directly echoes the several lines that I want to have in my signature and executing that in the muttrc using backticks gives a “broken pipe” error.

One solution (I’m sure there are others, maybe better ones) is to make the shell script create a temporary signature file and echo the path to that file, then execute the shell script using backticks.

Shell script (don’t forget to chmod 744):

#!/bin/bash                                                                                          

thesigfile=~/.mutt/rsig

echo  "Marianne Promberger PhD, King's College London
http://promberger.info" > $thesigfile
R --version | head -n 1 >> $thesigfile
cat /etc/issue | head -n 1 | cut -d " " -f 1-2 >> $thesigfile
echo $thesigfile

muttrc:

send-hook '~t r-help' 'set signature=`~/.mutt/signature_r-help`'

extract_url.pl needs MIME-tools perl module

October 3rd, 2009

extract_url.pl fails with:

Can't locate MIME/Parser.pm in @INC

Solution:

sudo aptitude install libmime-tools-perl

R: watch out when comparing vectors using “==”

September 25th, 2009

This question was on the R-help mailing list today:

I have a data frame “test”:

test<-data.frame(x=c(1,2,3,4,5,6,7,8),y=c(2,3,4,5,6,7,8,9),total=c(7,7,8,8,9,9,10,10))
test

I have a vector "needed":

needed<-c(7,9)
needed

I need the result to look like this:

1 2 7
2 3 7
5 6 9
6 7 9

When I do the following:

result<-test[test["total"]==needed,]
result

I only get unique rows that have 7 or 9 in "total":

1 2 7
6 7 9

[...]

The solution is to use %in% instead:

test[test$total %in% needed,]

A quick aside: note that you don't select the column "total" by using test["total"], instead, you need to index correctly and use test[,"total"], or, more succinctly, use test$total for dataframes. Check also identical(test["total"],test$total) and identical(test[,"total"],test$total).

Why doesn't == work here? It works just fine if you want to find all rows where the column total equals 7:

test[test$total == 7,]

The trick is that to R, test$total, needed and 7 are all vectors. == compares them element by element. Since 7 and needed are shorter than test$total, they are recycled as often as needed to give the same length as test$total. (Note, by the way, that you can of course directly look at the logical index by typing: test$total==needed.) So what R is doing is comparing this:

> test$total
[1]  7  7  8  8  9  9 10 10

to this:

> rep(needed,length.out=length(test$total))
[1] 7 9 7 9 7 9 7 9

The two vectors just happen to coincide at test$total[1] and test$total[6]. The recycling is of course no problem when you look for matches with a single number, because:

> rep(7,length.out=length(test$total))
[1] 7 7 7 7 7 7 7 7

will do just fine.

To get the help text on %in% by the way, you need to quote it:

?"%in%"

mutt: match messages that started a thread and have no replies

September 16th, 2009

Thanks to the helpful people on mutt-users.

As the title says. Mainly useful for mailing lists like r-help — questions that still need answering. (As if I knew any answers to r-help questions, ha.)

!~x . ~$

Note it combines ~x which looks into the “References:” header, so !~x . means “No References header”, i.e., messages that started a thread (and those from mail agents that don’t reference properly, alas) and ~$ matches unreferenced messages. Default combination for pattern terms is AND.

Of course, use with the lovely limit command and maybe combine with a date range:

!~x . ~$ ~d <1w

(Note no space after the <).

How to install RGoogleDocs (on Ubuntu)

September 14th, 2009

RGoogleDocs is not available from CRAN, but from Omegahat.org. To install, sudo R, then

install.packages("RGoogleDocs", repos = "http://www.omegahat.org/R")

RGoogleDocs requires RCurl, and will automatically install it. However, for me, this resulted in the error message:

checking for curl-config... no
Cannot find curl-config

and RGoogleDocs was not installed. This is in fact in the RCurl FAQ. The solution may differ for your system, but on Xubuntu Jaunty I needed to get:

sudo aptitude install libcurl4-gnutls-dev

This fixed the RCurl problem, but I installation of XML (also required, and also automatically installed when you install RGoogleDocs) failed with:

checking for xml2-config... no
Cannot find xml2-config
ERROR: configuration failed for package �XML�

You guessed it:

sudo aptitude install libxml2-dev

So here’s the whole thing for cut-and-paste:

sudo aptitude install libcurl4-gnutls-dev libxml2-dev

Then:

sudo R

Then, inside R:

install.packages("RGoogleDocs", repos = "http://www.omegahat.org/R")

Addendum

Just had to install RGoogleDocs again and had a different issue. It complained that it couldn’t get package bitops which seems to be a depenency for RCurl. First step (which I just learned):

install.packages("RGoogleDocs", repos = "http://www.omegahat.org/R", dependencies = TRUE)

was not sufficient in my case. Had to manually first

install.packages("bitops")

Addendum

Version 0.4.0, which you get from Omegahat, doesn’t work but throws an authentication failure when you try to load a spreadsheet.
Try version 0.4.1 (downloads a .tar.gz file). To install the file:

install.packages("~/downloads/RGoogleDocs_0.4-1.tar.gz",repos=NULL)

(of course, replace ~/downloads/ with the appropriate directory).
Doesn’t work for me (22/2/2011). I still get “unauthorized” when trying to access a document (I can access the list of documents just fine).