How to use Makefiles with R CMD build

I am developing the package R. It is based on a project that uses only the Makefile. Most of it is easily translated into the workflow R CMD build. However, the pdf files I need to create are a bit complicated, and I don’t understand them if I didn’t bother - so far I have decided how to do this using the Makefile.

In the R-package docs, I find links to using the Makefile for sources and even for vignettes .

I do not understand how they should be applied. From these documents, I got the impression that Makefiles will be called in the process R CMD build, but when I put Makefiles in the directories described, they are simply ignored. However, it R CMD checkrecognizes them and displays passing tests.

I also saw some Make files that are called R CMD buildinside, but I keep wondering how they will be executed when I use install.packages. That doesn't seem right - I mean, why do it if it didn't bother. And there is also a page in R packages about adding SystemRequiremens: GNU make- why do this for a file that you are not using?

So what is the best practice these days? And are there wild examples that I can look at?

Update

Since I was asked to give an example

I want to build a vignette in the same way as described in Writing Package Vignetting . There is a Latex master file that contains several Rnw files. Specific Dilemmas:

  • How can I create a pdf vignette?
  • - , rnws
  • Rnw , ( ), - .

Makefile, :

tmp/test.pdf: tmp/test.tex tmp/rnw1.tex tmp/rnw2.tex
    latexmk -outdir=$(@D) $<

tmp/%.tex: r/%.rnw
    Rscript -e "knitr::knit('$<', output='$@')"

tmp/rnw1.tex tmp/rnw2.tex: tmp/slowdata.Rdata

tmp/slowdata.Rdata: r/ireallytakeforever.R
    Rscript $<
+6
1

Bdecaf,

, 2.0 - .

, " , Makefiles ". , , make R:

knitr makefile ( ) , . makefile , , .

maker, Makefile for R. , Karl Broman ( , , , - ( ).

  • make: Make
  • R- Primer.

- ,

, , . , R, .

, .

.


:

make -

, Sweave knitr, GNU make.

, , , . R script LaTeX . BibTeX .

PDF - :

  • R script R, .
  • , bibtex, .

R , , .

GNU make . Makefile, ( pdflatex).

mypaper.pdf: mypaper.bib mypaper.tex Figs/fig1.pdf Figs/fig2.pdf
    pdflatex mypaper
    bibtex mypaper
    pdflatex mypaper
    pdflatex mypaper

Figs/fig1.pdf: R/fig1.R
    cd R;R CMD BATCH fig1.R

Figs/fig2.pdf: R/fig2.R
    cd R;R CMD BATCH fig2.R

, (), , ( ), , . , tab ( ).

: youd build fig1.pdf, fig1.R . , . fig1.R, fig1.pdf , mypaper.pdf .

: , cd , . :

### this doesn't work ###
Figs/fig1.pdf: R/fig1.R
    cd R
    R CMD BATCH fig1.R
You can, however, use \ for a continuation line, line so:

### this works ###
Figs/fig1.pdf: R/fig1.R
    cd R;\
    R CMD BATCH fig1.R

, (;).

GNU make

, GNU . make -version /, . ( Windows , make.)

make:

  • .
  • Makefile.
  • , , make.
  • , fig1.pdf mypaper.pdf, make fig1.pdf.

make, , , . , , .

, . ( . ).

, .

, R --vanilla. R_OPTS:

R_OPTS = - $(R_OPTS) ( ${R_OPTS}, ), R -

cd R; R CMD BATCH $(R_OPTS) fig1.R , , ; R, , .

, :

R_OPTS = - no-save --no-restore --no-init-file --no-site-file --vanilla, --no-environ ( , .Renviron R_LIBS, , R-, ).

, , . , :

$@    the file name of the target
$<    the name of the first prerequisite (i.e., dependency)
$^    the names of all prerequisites (i.e., dependencies)
$(@D)    the directory part of the target
$(@F)    the file part of the target
$(<D)    the directory part of the first prerequisite (i.e., dependency)
$(<F)    the file part of the first prerequisite (i.e., dependency)

,

Figs/fig1.pdf: R/fig1.R
    cd R;R CMD BATCH fig1.R

Figs/fig1.pdf: R/fig1.R
    cd $(<D);R CMD BATCH $(<F)

$(<D) , R . $(<F) , fig1.R .

, . , , , , , . .

, . , % , .

, . , , fig1.pdf fig2.pdf:

Figs/%.pdf: R/%.R
    cd $(<D);R CMD BATCH $(<F)

. , (.. ) mypaper.pdf.

,

, Makefile .

R_OPTS=--vanilla

mypaper.pdf: mypaper.bib mypaper.tex Figs/fig1.pdf Figs/fig2.pdf
    pdflatex mypaper
    bibtex mypaper
    pdflatex mypaper
    pdflatex mypaper

Figs/%.pdf: R/%.R
    cd $(<D);R CMD BATCH $(R_OPTS) $(<F)

: , , . : , GNU Make, , .

Make . github .

:

:

Makefile Yihui Xie s knitr R.

maker, Makefile for R.


R-

R.

R- - R- , , , ( R-) , .

R- , . , R, . , .

R ( , Amazon). .

R. , . R .

, , , . , (, , ). , Hadley book, ?

- , R.

, .

:

- ( !), , ( ) fork GitHub -, .


github.

. tutorials git/github, GNU make, knitr, - GitHub, , .

+4

All Articles