Joe
Joe

Reputation: 3806

create variable in makefile that renders and moves output to new subdirectory

Using a makefile with Rstudio, I will generate an html report from an Rmd file in my analysis/ subdirectory using the variable $(RENDER), and then I will move this html report to the reports/ subdirectory in the next line of the make rule.

# define VARIABLES for Makefile
RENDER = Rscript -e "require(rmarkdown); render('$<')" 
DAT = ./data
ANL = ./analysis
REP = ./reports

VPATH = $(DAT) $(ANL) $(REP)

# generate a report in html
foo.html: foo.Rmd bar.rds
    $(RENDER)
    mv foo.html $(REP)

How can I combine these two steps into one variable command?

# Attempt: 
RENDREP = $(RENDER); mv $($< : .Rmd=.html) $(REP)

# generate a report in html
    foo.html: foo.Rmd bar.rds
        $(RENDREP)

My attempt at the RENDREP variable yields this error message:

Output created: foo.html
usage: mv [-f | -i | -n] [-v] source target
       mv [-f | -i | -n] [-v] source ... directory
make: *** [foo.html] Error 64

Upvotes: 1

Views: 128

Answers (1)

user657267
user657267

Reputation: 21000

The syntax of $($< : .Rmd=.html) is wrong, it should be

RENDREP = $(RENDER); mv $(<:.Rmd=.html) $(REP)

That said, it'd be simpler to just do

RENDREP = $(RENDER); mv $@ $(REP)

Upvotes: 1

Related Questions