NESCent / popgenInfo

Vignettes for Population Genetics in R
http://popgen.nescent.org
MIT License
20 stars 50 forks source link

Add generation of R files to build? #197

Open zkamvar opened 7 years ago

zkamvar commented 7 years ago

Something useful for teaching might be to have the R scripts available for people to download from the website by replacing "html" with "R". This is easily achieved with the command knitr::purl('$<', documentation = 2).

I would issue a pull request, but I'm not terribly literate in Make. What do you think, @hlapp?

hlapp commented 7 years ago

Sounds like a good idea. Can you elaborate how you envision this to work? For example, can you show the commands (or steps) someone would type (into R? the command line?) if this were enabled?

zkamvar commented 7 years ago

So, in the makefile, we would have a rule that converts Rmd to R using knitr::purl(). These R files will be placed in the same directory as the html files so that if one wanted to download the R file, they could simply change the URL from http://popgen.nescent.org/LMM-Genetic-Diversity.html to http://popgen.nescent.org/LMM-Genetic-Diversity.R.

It is currently possible to obtain an R script from the original Rmd with the following, but it might be a bit cumbersome for novice users.

vig <- "LMM-Genetic-Diversity.Rmd"
head <- "https://raw.githubusercontent.com/NESCent/popgenInfo/master/use/"
knitr::purl(paste0(head, vig), documentation = 2)
hlapp commented 7 years ago

I looked into this. I think the main challenge here would be to implement this such that only those .Rmd documents get their scripts extract to an R script for which using them as an R script (or a template for one) would be intended.

It seems most of the documents for which this wouldn't be the case are already recognizable as plain Markdown (.md) and not Rmarkdown (.Rmd) documents. However, there seem to be a few more which are really only meant to be rendered to HTML.

We could just live with their corresponding .R scripts lying around on the website with no actual purpose (and nothing linking to them). It does feel a little unsatisfying, though, so I'm wondering whether all the .Rmd files we have that aren't vignettes really do have actively executed code during execution. Or maybe there's another rule or pattern by which we can pinpoint what should have its R code extracted? Such as being in the use/ directory?

zkamvar commented 7 years ago

Such as being in the use/ directory?

I think setting the rule for all .Rmd documents in the use/ and develop/ directories would be a good rule for this. I'm not very well versed in Make, so I'm not quite sure how it would work.