Guest User

Untitled

a guest
Jul 15th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. # Makefile for knitr
  2.  
  3. # optionally put all RNW files to be compiled to pdf here, separated by spaces
  4. RNW_FILES= $(wildcard *.Rnw)
  5.  
  6. # location of Rscript
  7. R_HOME?=/Library/Frameworks/R.framework/Resources
  8.  
  9. # these pdf's will be compiled from Rnw and Rmd files
  10. PDFS= $(RNW_FILES:.Rnw=.pdf)
  11.  
  12. # these R files will be untangled from RNoWeb files
  13. R_FILES= $(RNW_FILES:.Rnw=-purled.R)
  14.  
  15. # cache and figure directories
  16. CACHEDIR= cache
  17. FIGUREDIR= figures
  18.  
  19.  
  20. .PHONY: all purled clean cleanall open
  21. .SUFFIXES: .Rnw .pdf .R .tex
  22.  
  23.  
  24. # these targets will be made by default
  25. all: $(PDFS)
  26.  
  27. # use this to create R files extracted from RNoWeb files
  28. purled: $(R_FILES)
  29.  
  30. # these tex files will be generate from Rnw files
  31. TEX_FILES = $(RNW_FILES:.Rnw=.tex)
  32.  
  33.  
  34. # remove generated files except pdf and purled R files
  35. clean:
  36. rm -f *.bbl *.blg *.aux *.out *.log *.spl *tikzDictionary *.fls
  37. rm -f $(TEX_FILES)
  38.  
  39. # run the clean target then remove pdf and purled R files too
  40. cleanall: clean
  41. rm -f *.synctex.gz
  42. rm -f $(PDFS)
  43. rm -f $(R_FILES)
  44.  
  45. # compile a PDF from a RNoWeb file
  46. %.pdf: %.Rnw Makefile
  47. mkdir -p build
  48. $(R_HOME)/bin/Rscript\
  49. -e "require(knitr)" \
  50. -e "knitr::opts_chunk[['set']](fig.path='$(FIGUREDIR)/$*-')" \
  51. -e "knitr::opts_chunk[['set']](cache.path='$(CACHEDIR)/$*-')" \
  52. -e "knitr::knit('$*.Rnw', output='build/$*.tex')"
  53. pdflatex -halt-on-error -output-directory=build build/$*.tex
  54. [ -h "$*.pdf" ] || ln -s build/$*.pdf $*.pdf
  55.  
  56. # extract an R file from an RNoWeb file
  57. %-purled.R: %.Rnw
  58. $(R_HOME)/bin/Rscript\
  59. -e "require(knitr)" \
  60. -e "knitr::opts_chunk[['set']](fig.path='$(FIGUREDIR)/$*-')" \
  61. -e "knitr::opts_chunk[['set']](cache.path='$(CACHEDIR)/$*-')" \
  62. -e "knitr::purl('$*.Rnw', '$*-purled.R')"
  63.  
  64. # open all PDF's
  65. open:
  66. open -a Skim $(PDFS)
Add Comment
Please, Sign In to add comment