makefile knitr

Lazar

Phineas Packard
#1
Ok so I want to make a makefile that will find all .Rmd files and convert them to html files. I have a make file the works but I want to work loop through the .Rmd and then .md files. Here is what I have so far:

Code:
# test comment

all: Day1Part1-Introduction.md Day1Part1-Introduction.html \
Day1Part1-session2.md Day1Part1-session2.html

Day1Part1-Introduction.md: Day1Part1-Introduction.Rmd
	/usr/bin/Rscript -e "knitr::knit('Day1Part1-Introduction.Rmd', 'Day1Part1-Introduction.md')"

Day1Part1-Introduction.html: Day1Part1-Introduction.md
	pandoc -s -t slidy Day1Part1-Introduction.md -o Day1Part1-Introduction.html

Day1Part1-session2.md: Day1Part1-session2.Rmd
	/usr/bin/Rscript -e "knitr::knit('Day1Part1-session2.Rmd', 'Day1Part1-session2.md')"

Day1Part1-session2.html: Day1Part1-session2.md
	pandoc -s -t slidy Day1Part1-session2.md -o Day1Part1-session2.html

clean:
	rm -rf *.md figure *.inp
Any help making this more efficient would be great!!
 

Lazar

Phineas Packard
#2
I tried:
Code:
# Transform .Rmd files to slidy files

FILENAME = Day1Part1-Introduction Day1Part1-session2

all: $(FILENAME).md $(FILENAME).html

$(FILENAME).md: $(FILENAME).Rmd
  /usr/bin/Rscript -e "knitr::knit('$(FILENAME).Rmd', '$(FILENAME).md')"

$(FILENAME).html: $(FILENAME).md
	pandoc -s -t slidy $(FILENAME).md -o $(FILENAME).html

clean:
	rm -rf *.md figure *.inp

cleancach:
 rm -rf *.html
but I get error:
Code:
Makefile:17: *** missing separator.  Stop.
 

Lazar

Phineas Packard
#4
Ok solved (note if you are going to write makefiles in Rstudio make sure you uncheck the box replace tabs with spaces in the global options).

Code:
# Transform .Rmd files to slidy files

.SUFFIXES: .Rmd .html .md

all: Day1Part1-Introduction.md Day1Part1-Introduction.html Day1Part1-session2.md Day1Part1-session2.html \
	Day1Part1-session3.md Day1Part1-session3.html Day1Part2-session1.md Day1Part2-session1.html \
	Day1Part2-session2.md Day1Part2-session2.html

#markdown
%.md: %.Rmd
	/usr/bin/Rscript -e "knitr::knit('$*.Rmd')"

#html slides
%.html: %.md
	pandoc -s -t slidy $*.md -o $*.html

clean:
	rm -rf *.inp *.md 

cleanhtml:
	rm -rf *.html figure
 

TheEcologist

Global Moderator
#5