Hannes Datta
make
cheatsheet from Tilburg Science HubLet's describe our toolstack…
tidyverse
& data preparation, setup + ITOToday, we learn how to automate projects.
make
I'll show you the basic functions of make
in one of my projects.
make -n
, make
If you can't run make
and Rscript
from your terminal, you won't be able to proceed.
make
is properly installed
make
(enter). make: *** No targets specified
– then it is correctly installed!Rscript
from the terminal/command prompt
Rscript
(enter). Usage: Rscript [options] file [args]
…? – then you are all set!Today's project is based on a prototype project using Airbnb data. Please download the source code now (run code below).
download.file('https://gist.githubusercontent.com/hannesdatta/1f764090ae3ebfaabe7a91ea4b971c3d/raw/2df12443cd144141dedb866967cbe985b97052f5/run_antwerp.R', 'run_antwerp.R')
run_antwerp.R
in RStudio to check out the code - can you run the first few lines? Does it work?Rscript run_antwerp.R
. What happens?R --vanilla < run_antwerp.R
- what difference does it make?We will now gradually “modularize” (split in multiple code files) and automate our project, using make
.
makefile
and put it in the root of our project directorymakefile
consists of one or multiple “recipes”
makefile
(no extension)R --vanilla
or Rscript
…)make
on terminal. What happens?plot_all.pdf: run_Antwerp.R
R --vanilla < run_Antwerp.R
Let us now change something in the source code of run_antwerp.R
, e.g., change Universiteitsbuurt
to Stadspark to experience a
make workflow.
make -n
(preview what will have to be done)make
(to run the pipeline)make
again (verify everything up-to-date & makefile has been correctly specified)Last step really important and often forgotten in projects.
When working with make
, it's handy to keep our project tidy (i.e., get right of “old” files automatically).
Try implementing such a clean
rule in make
:
clean:
R -e "unlink('*.pdf')"
make clean
. What happens? R -e
do?How? split up code, implement setup + ITO, write makefile
rule, test rule. Step-by-step.
download.R
listings.csv
and reviews.csv
Rscript download.R
makefile
to be able to run it.How? split up code, implement ITO, write makefile
rule, test rule. Step-by-step.
But… we have not cleanly separated src
files from generated output files. See also here for full description on how to name directories.
Do:
src
code directory and move source code files theregen
directory in an R file (preferably run early on).R
filesmake
still runs.make
)