Skip to content

Instantly share code, notes, and snippets.

@halpo
Created November 17, 2011 20:07
Show Gist options
  • Save halpo/1374344 to your computer and use it in GitHub Desktop.
Save halpo/1374344 to your computer and use it in GitHub Desktop.
Makefile for R Packages
# Makefile for generating R packages.
# 2011 Andrew Redd
#
# Assumes Makefile is in a folder where package contents are in a subfolder pkg.
# Roxygen uses the roxygen2 package, and will run automatically on check and all.
PKG_VERSION=$(shell grep -i ^version pkg/DESCRIPTION | cut -d : -d \ -f 2)
PKG_NAME=$(shell grep -i ^package pkg/DESCRIPTION | cut -d : -d \ -f 2)
R_FILES := $(wildcard pkg/R/*.R)
SRC_FILES := $(wildcard pkg/R/*.R)
PKG_FILES := pkg/DESCRIPTION pkg/NAMESPACE $(R_FILES) $(SRC_FILES)
.PHONY: tarball install check clean roxygen
tarball: $(PKG_NAME)_$(PKG_VERSION).tar.gz
$(PKG_NAME)_$(PKG_VERSION).tar.gz: $(PKG_FILES)
R CMD build pkg
all: check install
check: $(PKG_NAME)_$(PKG_VERSION).tar.gz roxygen
R CMD check $(PKG_NAME)_$(PKG_VERSION).tar.gz
install: $(PKG_NAME)_$(PKG_VERSION).tar.gz
R CMD INSTALL $(PKG_NAME)_$(PKG_VERSION).tar.gz
roxygen:
Rscript -e "library(roxygen2);roxygenize('pkg')"
clean:
-rm -f $(PKG_NAME)_*.tar.gz
-rm -r -f $(PKG_NAME).Rcheck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment