[Bioc-devel] To use knitr, how to write the right Makefile for bioconductor devel and released branch?

Martin Morgan mtmorgan at fhcrc.org
Thu Sep 27 21:56:36 CEST 2012

On 09/27/2012 11:46 AM, Tengfei Yin wrote:
> On Thu, Sep 27, 2012 at 10:08 AM, Dan Tenenbaum <dtenenba at fhcrc.org> wrote:
>> On Wed, Sep 26, 2012 at 11:41 PM, Tengfei Yin <yintengfei at gmail.com>
>> wrote:
>>> Dear maintainers and developers,
>>> I am wondering, is there a way to use knitr to built my vignette, I am
>>> trying to write a Makefile under my inst/doc, something like
>>> # Makefile to use knitr for package vignettes
>>> # put all PDF targets here, separated by spaces
>>> PDFS= ggbio.pdf
>>> all: $(PDFS)
>>> clean:
>>> rm -f *.tex *.bbl *.blg *.aux *.out *.log *.spl *tikzDictionary
>>> %.pdf: %.Rnw
>>> $(R_HOME)/bin/Rscript -e "library(knitr); knit2pdf('ggbio.Rnw')"
>>> Then I realize the bioc maintained two branch, released and development,
>> so
>>> the R version it used to check each branch must be different, I don't
>>> really know how to specify those in my Makefile, especially after next
>>> Monday, the devel-branch become released version automatically, there
>> must
>>> be a problem if I set up a fixed point to some */bin/Rscript?
>>> I don't really know how it works with bioconductor, the example above
>>> should work for cran, but I guess things are very different between cran
>>> and bioc.
>> If you use "$(R_HOME)/bin/R" in your Makefile, as you do, the correct
>> R will be used.
>> Dan
>> Hi Dan,
> Thanks a lot, I will give a try to see how it works.

I'm not 100% sure of the following.

 From 'Writing R Extensions' section 1.4.1, "By default R CMD build will 
run Sweave on all files in Sweave format in vignettes, or if that does 
not exist, inst/doc". R will then go on to evaluate the Makefile. So 
your 'Rnw' file will be processed (to .tex) by R, regardless of what 
your Makefile says -- you get to build your vignette twice, and discard 
once! (maybe knitr defines directives that are not consistent with 
evaluation by Sweave, and then your only choice is to avoid those 
directives). There aren't easy, non-hackish ways to avoid this that I 
know of; maybe the knitr community has this all worked out? I think the 
designers of Sweave thought that people wishing to offer alternative 
parsers would have used the hooks it provides, rather than reinventing 
it entirely.

One other minor point is that $(R_HOME) can expand to a path with spaces 
in it, so enclose in quotations

%.pdf: %.Rnw
	"$(R_HOME)/bin/R" -e "library(knitr); knit2pdf('ggbio.Rnw')"

(I used bin/R instead of bin/Rscript because that is how most examples 
in Writing R Extensions are written; there is a warning on ?Rscript 
about availability only on systems with execv, but I don't really know 
how that translates into reality).

Comments from Kasper in this thread (especially toward the end, where we 
get past my misleading comments)


might also be helpful.


> Tengfei
>>> thanks a lot!
>>> Tengfei
>>> --
>>> Tengfei Yin
>>> MCDB PhD student
>>> 1620 Howe Hall, 2274,
>>> Iowa State University
>>> Ames, IA,50011-2274
>>>          [[alternative HTML version deleted]]
>>> _______________________________________________
>>> Bioc-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/bioc-devel

Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

More information about the Bioc-devel mailing list