Modern Plain Text Social Science: Week 5
October 4, 2023
the_paper.pdf
to be successfully produced,03_make_figures.R
needs to have run and created 01_descriptives.png
and 02_coefs_of-interest.png
.03_make_figures.R
to run, 02_clean_data.R
needs to have run.02_clean_data.R
to successfully run, 01_setup.R
needs to run. - This graph is produced via
{targets}
about which more in a bit. - For now just focus on the idea of targets (outputs) having prerequisites
make
manages buildsmake
has been around for a long time.Makefile
.Some variables are built-in:
$@
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)
## All Rmarkdown files in the working directory
SRC = $(wildcard *.Rmd)
## Location of Pandoc binaries
PANDOC = /opt/homebrew/bin
## Location of Pandoc support files.
PREFIX = /Users/kjhealy/.pandoc
## Location of your working bibliography file
BIB = /Users/kjhealy/Documents/bibs/socbib-pandoc.bib
## CSL stylesheet (located in the csl folder of the PREFIX directory).
CSL = apsa
## Pandoc options to use
OPTIONS = markdown+simple_tables+table_captions+yaml_metadata_block+smart
## MS Word template
DOCXTEMPLATE = /Users/kjhealy/.pandoc/templates/rmd-minion-reference.docx
MD=$(SRC:.Rmd=.md)
PDFS=$(SRC:.Rmd=.pdf)
HTML=$(SRC:.Rmd=.html)
TEX=$(SRC:.Rmd=.tex)
DOCX=$(SRC:.Rmd=.docx)
all: $(MD) $(PDFS) $(HTML) $(TEX) $(DOCX)
pdf: clean $(PDFS)
html: clean $(HTML)
tex: clean $(TEX)
docx: clean $(DOCX)
md: clean $(MD)
%.md: %.Rmd
R --no-echo -e "set.seed(100);knitr::knit('$<')"
%.html: %.Rmd
R --no-echo -e "set.seed(100);rmarkdown::render('$<', output_format = distill::distill_article(), encoding = 'UTF-8')"
%.tex: %.md
$(PANDOC)/pandoc -r $(OPTIONS) -w latex -s --pdf-engine=pdflatex --template=$(PREFIX)/templates/rmd-latex.template --citeproc --csl=$(PREFIX)/csl/ajps.csl --bibliography=$(BIB) --filter $(PANDOC)/pandoc-crossref -o $@ $<
# PDFs are generated directly from Rmd with render(), and not indirectly vita knit() to md
%.pdf: %.Rmd
R --no-echo -e "set.seed(100);rmarkdown::render('$<', output_format = 'bookdown::pdf_book')"
%.docx: %.md
$(PANDOC)/pandoc -r $(OPTIONS) -s --citeproc --csl=$(PREFIX)/csl/$(CSL).csl --bibliography=$(BIB) --reference-doc=$(DOCXTEMPLATE) --filter $(PANDOC)/pandoc-crossref -o $@ $<
clean:
rm -f *.md *.html *.pdf *.tex *.bbl *.bcf *.blg *.aux *.log *.docx
rm -f cache/*.*
.PHONY: clean
make
tips<TAB>
not spaces. It has to be tabs.cd
and line continuation gotchas.make --dry-run <target>
is your friend.make
, especially for building single documents.{targets}
is make
for inside R{targets}
.Carl Sagan
Docker
renv
renv
renv workflow, from the renv
package homepage
{usethis}
package