Category Archives: shell scripts

Messing with R packages

This was really frustrating. I'm trying to modify a package from Matt Johnson and although I could get the package he sent me to install flawlessly, I couldn't un-tar it, make a change, re-tar it, and then R CMD INSTALL it. I was about to pull out my hair. The error I got was:
ERROR: cannot extract package from ‘hrm-rev9.tar.gz’

The secret: you have to have the name correct.
R CMD INSTALL hrm-rev9.tar.gz
barfs. But
R CMD INSTALL hrm_0.1-9.tar.gz
works fine. I'm sure it's somewhere in the docs. I just couldn't find it.

As always, I made a script to do it for me: (Updated 6/17/2010 15:41)

#!/bin/bash
# Quick script to tar & gzip the package, remove the old one, and install the new one
# I'll add options automatically tag and release it later.

#Set the library that I'm using
LIB="/home/vanhoudn/R/i486-pc-linux-gnu-library/2.10/"

#Commit
svn commit -m "Build commit"

#get the revision number from svn
REV=`svn info -R | grep Revision | cut -d: -f 2 | sort -g -r | head -n 1 | sed 's/ //g'`

#Build the filename
FILENAME="hrm_0.1-$REV.tar.gz"

# I need to tar up the pkg so I can install it.
# Jump to the parent directory and work from there.
cd ..
# Exclude any hidden files under the directories (svn has a bunch)
# and add the named files
tar czf $FILENAME --exclude '.*' hrm/DESCRIPTION hrm/NAMESPACE hrm/src hrm/R

# Remove the old version of the package
R CMD REMOVE -l $LIB hrm

# Install the new package
R CMD INSTALL $FILENAME

# Clean up
rm $FILENAME

# Go back to our previous directory
cd hrm

CMU Web Publishing is Strange

The My Andrew web publishing workflow is a little strange. Once you get everything setup, maintenance is a pain. Once you copy the updated files to ~/www, you must visit a webpage to "publish" those files. Presumably the script that copies the files from ~/www to somewhere else in the infrastructure does some security checking or something.

Visiting a webform is a pain. Luckily, it is unauthenticated and uses GET so it is simplicity itself to "publish" from the command line. A quick script:

#!/bin/sh</code>

<code>#Change these to where your local copy of www sits and your username
SOURCE=/home/nathanvan/winhome/workspace/www/
USER=nmv

rsync -rv $SOURCE $USER@unix.andrew.cmu.edu:www
#Since I'm triggering an event, I'm not worried about certificate integrity.
wget --no-check-certificate 'https://www.andrew.cmu.edu/cgi-bin/publish?FLAG=0&NAME='$USER

#Clean up what wget left behind.
rm 'publish@FLAG=0&NAME='$USER

Clearly there are other ways to do this, but this is simple and compatible with my workflow. Since I don't do this often, I'm okay with typing my password. I could use ssh-agent and such, but I haven't got that setup on this machine yet and doubtfully ever will.