- Defining targets that depend on other targets
- Write a Makefile with various dependent targets
More than one target
All of the previous examples have been about Makefiles that use one or more independent targets.
Now let's consider a couple of targets in which some of them play the role of dependencies for other targets.
In this case we will work with a toy data analysis in R. More specifically, we will perform a regresison analysis on simulated data.
Toy Regression in R
The code of the analysis is:
# random data set.seed(754321) x <- rnorm(20) y <- x + rnorm(20) # regression line reg <- lm(y ~ x) summary(reg) # scatter diagram with fitted regression line plot(x, y, las = 1, pch = 19, col = "#555555") abline(reg, col = "#0000DD70", lwd = 3)
For illustration purposes, the previous code has been split into three R scripts, each producing an output file:
You can see the files of this example in the folder
Input and Output files
regression-data.Rgenerates the random vectors, fits the regression model, and sends the data and the model to a binary file
regression-model.Rreads in the regression data, and then sends the summary of the regression object to the file
regression-plot.Rreads in the regression data, and creates a scatter plot that is saved in the file
The main output is the file
regression.htmlwhich depends directly on
report.md, in turn, uses
Here's the content of the
all: regression.html regression.html: report.md regression-model.md scatterplot.png pandoc report.md regression-model.md -s -o regression.html scatterplot.png: regression-plot.R regression.RData Rscript regression-plot.R regression-model.md: regression-model.R regression.RData Rscript regression-model.R regression.RData: regression-data.R Rscript regression-data.R