Created
April 20, 2012 14:39
-
-
Save daroczig/2429150 to your computer and use it in GitHub Desktop.
Building and (re)loading packages with a keypress in Emacs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun ess-build-and-load-package () | |
"Builds R pkg in current project and (re)loads it in R session." | |
(interactive) | |
(setq curbuf (current-buffer)) | |
(setq w1 (selected-window)) | |
(setq w1name (buffer-name)) | |
(setq tmpbuf (get-buffer-create "*pkg build*")) | |
(setq w2 (split-window-horizontally)) | |
(shell-command (format "~/.emacs.d/build-R-pkg.sh %s" eproject-root) tmpbuf ) | |
(ess-command (format "pkg.path <- \"%s\";pkg.name <- readLines(file.path(pkg.path, 'DESCRIPTION'));pkg.name <- strsplit(pkg.name[grepl('Package: ', pkg.name)], ' ')[[1]][2];pkg.ns <- paste0('package:', pkg.name);if (!is.na(match(pkg.ns, search()))){detach(pkg.ns, character.only = TRUE)};library(pkg.name, character.only = TRUE, unload = TRUE)\n" eproject-root)) | |
(set-window-buffer w2 "*pkg build*") | |
(set-window-buffer w1 w1name) | |
) | |
(add-hook 'ess-mode-hook | |
'(lambda() | |
(local-set-key (kbd "C-c b") 'ess-build-and-load-package) | |
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DIR="$1"; | |
if [ -f $DIR/DESCRIPTION ]; then | |
BUILDDIR="/tmp" | |
PKG=`cat $DIR/DESCRIPTION | grep Package: |awk '{ print $2 }'`; | |
VER=`cat $DIR/DESCRIPTION | grep Version: |awk '{ print $2 }'`; | |
RCMD="library(roxygen2); roxygenize('`echo $DIR`'); q()"; | |
echo; | |
echo -e "\e[1;91m ==> Roxygen:"; | |
echo -e "\e[0m"; | |
cd $DIR/man/; | |
ls | xargs rm -rf; | |
echo $RCMD | /usr/bin/r --vanilla; | |
cd $BUILDDIR; | |
echo; | |
echo -e "\e[1;91m ==> Building:"; | |
echo -e "\e[0m"; | |
R CMD build $DIR; | |
echo; | |
echo -e "\e[1;91m ==> Install:"; | |
echo -e "\e[0m"; | |
sudo R CMD INSTALL "${PKG}_${VER}.tar.gz"; | |
echo; | |
else | |
echo "Not an R project!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Colors do not work in Emacs' console :(