add a simple script to the package build process


#1

I'd like to add a little script that builds my package vignette Rmarkdown into markdown which will be my github README.md. Basically it's:


knitr::knit("./vignettes/my_vignette.rmd", "testing.md" )

vig_in <- readLines("testing.md")
vig_out = vig_in[-(1:11)]

writeLines(vig_out, "README.md")

If I want this built EVERY time I build my package is there a simple way to add an R script to the end of a package build process?

The answer to this from SO is basically: "Use a build script from devtools" Which feels remarkably like "draw the rest of the f'ing owl" because it's not entirely obvious to me what it means to "use a build script" in the context of devtools. I suspect this is trivial, but I've been unable to grok how to do this.


#2

I think what the SO answer means is to use a custom script that will execute some commands. This seems the simplest.

You can also use a make file for that with a specific rule to build the readme. See as example the one use in knitr :package:

This seems a good use of make file. You could have a build-readme rule that is executed each time you build the vignette. I let you dig about makefile if you are not familiar.

Another solution would be to make advance use to Rmarkdown features. You can setup everything to reuse chunk in README and vignette, like showcased in this blog post and from this :package: example

Also, I have never done it but I think this is possible to use ref.label and knitr::all_labels() to generate the README from the vignette directly... Not sure how it would behave on CRAN though. :thinking:

Makefile solution could be the more common and standard.
If you have a :package: on github to play with, I can help setup all this.


#3

this is a huge help and gives me a lot of interesting ideas!

I think I had my head on crooked when I first read about this. I thought folks were somehow hooking the make file from the build process. I now realize the whole package build process is driven by make so when using make one does not build the package in the regular way, but rather calls make from the command line. Yeah, that seems obvious in retrospect.