Posts

Showing posts from 2019

Build R project using Make

My default for building projects is to use make . I find it helps organise a projects workflow, even if there are other build tools available. It is succinct, and descriptive. A previous post showed how you can use make to build Haskell projects using GHC, Cabal and Stack. This blog show how to do the same for R projects. Below is an R script that can be used to render R markdown to PDF. It is invoked from a parent Makefile which is what is read when you call make. make.R #!/usr/bin/env R   # Render R markdown to PDF. # Invoke with: # > R -q -f make.R --args my_report.Rmd   # load packages require ( rmarkdown )   # require a parameter naming file to render if ( length ( args ) == 0 ) { stop ( "Error: missing file operand" , call. = TRUE ) } else { # read report to render from command line for ( rmd in commandArgs ( trailingOnly = TRUE ) ) { # render Rmd to PDF if ( grepl ( " \\ .Rmd$" , rmd ) &...

Render Jupyter Notebook to HTML or PDF

The following shows how to render a  Jupyter Notebook  into a static form, such as HTML or PDF document.  Render to HTML To render a Jupyter Notebook to HTML: jupyter nbconvert --exec --to html --output document.html document.ipynb You can also specify an output directory: jupyter nbconvert --exec --to html --output document.html --output-dir target document.ipynb The HTML has all images embedded. This makes sharing easy is the HTML is fully self contained. Render to PDF I have had mixed results converting a notebook directly to PDF. The conversion complained that embedded images were not found. Instead I suggest first converting it to LaTeX and then to a PDF. To convert to Tex run: jupyter nbconvert --exec --to latex --output document.tex document.ipynb Now, it is an easy matter to convert TeX to PDF with pdflatex : pdflatex document.tex Build using Makefile A generic Makefile that can be used in a Jupyter project to perform ...

Build Haskell projects using Make

Make has been around for a long time . It does, however, have a moderate learning curve. Once you understand and overcome some of its idiosyncrasies, it is a very powerful generic build tool. Below are my variants for building Haskell projects using make. Most of my projects now use Stack . Even so, having a Makefile helps to coordinate building project artefacts. It becomes an organising script for the project. A full description on building modules can be found in the chapter Using Make in the GHC documentation . For a single target, you can use make to build a Haskell project. Make is whitespace sensitive. You must use tabs. The default is to use a tab setting of 8 spaces. GHC Below is a version using just GHC for compilation. We are defining a custom pattern to build from Haskell source (.hs) to an object (.o). This rule is cheating, as the end result is actually a executable, but as I didn't want to add a .exe extension, we are 'faking' it with ...