make 学习笔记
makefile
makefile是一个"自动化编译器",你只需要写好一个makefile, 然后执行一个make命令 , 整个工程就会自动按照规则编译了,极大提高了我们程序猿的效率。
R也只支持makefile的
参考 https://github.com/pavopax/gists/blob/master/assets/makefile-example-1.bash
Makefile quick start
Makefiles are a simple way to organize code execution/compilation.
It's like a recipe for your code repo.
Makefile is a single file that can run all analysis code, or do other
tasks. It is self-documenting, and helps in "reproducibility."
You run it from command line, as follows.
Hello, world!
Here's a simple example.
Make a file Makefile (no extension!) and put this in it:
all: data process output
data:
		Rscript get_datasets.R
		Rscript get_extra_files.R
	
process:
		Rscript process.R
output:
		Rscript write_plots.R
		Rscript write_tables.R
		python app.py
Now, from command line, you can:
- type 
make datato run your "get data" scripts - type 
make outputto only run your "output" script(s) - type 
make allto rerun the entire analysis, which consists of the pieces
specified in the first line (data,process,output) 
all, data, process, output, etc are called "targets"
Advantages
Reproducibility.
Rerun the whole thing with make all.
Speed: Rerun only specific pieces of your analysis with make data, make process, etc
Can be self-documenting.
Examples
Tips
Add a target clean to remove data and start from scratch (reproducibility,
FTW!)
clean:
	rm -rf data
(Consider adding mkdir -p data in your make data target to create
this folder automatically)
If you already have a /data folder, then running make data may give you
error. There are reasons for this. To alleviate this, run it as make -B data
or declare it as .PHONY in Makefile like:
all: process data
.PHONY: data
data:
    Rscript get_datasets.R
More on .PHONY

                
            
        
浙公网安备 33010602011771号