Skip to content
Prev 41240 / 63421 Next

Please explain your workflow from R code -> package -> R code -> package

Hi--

I guess I'm a bit late to the party. I enjoyed this thread immensely,
and it helped me discover roxygen2, in what I predict to be the
beginning of a beautiful friendship.

I wrote a couple of wrappers over the last few days which are making
my workflow easier. I code on a computer but run my computations on
several different boxes, meaning that I need a simple way (ideally
one-liner) to deploy the code on each box. So I have a couple of
wrapper functions, which I am happy to share with you.

1) RPush: this bash function roxygenizes, commits and pushes a package
to a git repo. It assumes that your packages are all in a folder, the
path to which is given by the environment variable $RPACK. For example
$RPACK/Package1 and $RPACK/Package2.)

function RPush {
cd $RPACK/$1
R --quiet --vanilla --slave  <<EOF
suppressMessages(library(roxygen2))
roxygenize("./")
EOF
git add ./
git commit -am "$2"
git push
cd - > /dev/null
}

The syntax is
RPush <package name> 'commit message'

2) GitInstall is an R function somewhat inspired by Hadley Wickham's
Intall_Github, except that it is not bound to Github and can (I think)
be used with any git server.

GitInstall <- function(
                       repo,
                       branch = "HEAD",
                       remote="git at yougitserver:yourrepo"
                       ) {
  repo <- as.character(substitute(repo))
  tartf <- tempfile()
  pkgtd <- tempfile()
  dir.create(pkgtd)
  on.exit(unlink(c(tartf, pkgtd)))
  system(
         paste(
               "git archive --format=tar --remote=",
               remote, repo,
               " ", branch, "> ",
               tartf,
               sep=""
               ))
  message("Attempting to install ", repo, " from ", remote, ".")
  system(paste(
               "tar -xf",
               tartf,
               "-C",
               pkgtd
               ))
  install.packages(pkgtd, repo=NULL, type="source")
}

You can then wrap it in a bash function such as

function RInstall {
sudo R --quiet --slave <<EOF
Package1::GitInstall($1)
EOF
}

(where it is assumed that you put the GitInstall function in Package1)

So that to update a package and deploy it to a remote machine you just
need to type:
- on the local machine: RPush Package1 'commit message'
- on the remote machine: RInstall Package1

I don't think it gets much lazier than that!

Hope it helps, though I am sure this code is not super clean and may
break for other people..

Timothee
On Sun, Sep 11, 2011 at 1:48 AM, <Mark.Bravington at csiro.au> wrote:

Thread (16 messages)

Paul Johnson Please explain your workflow from R code -> package -> R code -> package Sep 9 Joshua Ulrich Please explain your workflow from R code -> package -> R code -> package Sep 9 Spencer Graves Please explain your workflow from R code -> package -> R code -> package Sep 9 Dirk Eddelbuettel Please explain your workflow from R code -> package -> R code -> package Sep 9 Duncan Murdoch Please explain your workflow from R code -> package -> R code -> package Sep 9 Spencer Graves Please explain your workflow from R code -> package -> R code -> package Sep 9 Hadley Wickham Please explain your workflow from R code -> package -> R code -> package Sep 9 Hadley Wickham Please explain your workflow from R code -> package -> R code -> package Sep 9 Baptiste Auguie Please explain your workflow from R code -> package -> R code -> package Sep 9 Barry Rowlingson Please explain your workflow from R code -> package -> R code -> package Sep 10 steven mosher Please explain your workflow from R code -> package -> R code -> package Sep 10 Joshua Ulrich Please explain your workflow from R code -> package -> R code -> package Sep 10 Yihui Xie Please explain your workflow from R code -> package -> R code -> package Sep 10 steven mosher Please explain your workflow from R code -> package -> R code -> package Sep 10 Mark Bravington Please explain your workflow from R code -> package -> R code -> package Sep 10 Timothée Carayol Please explain your workflow from R code -> package -> R code -> package Sep 13