Posts

Showing posts with the label data science

Thoughts on Random Number Generation - Shell Scripts

Image
This blog was first published in 2019, but the site has since been shut down. One of the first exercises given to me as a mathematics student was to write a random number generator (RNG). This turned out to be not so easy. Test sequences cycled quickly or were too predictable or were not evenly distributed. Typically when we talk of RNG’s we are describing  pseudorandom  number generators. Nowadays, we have a many programs that will generate  pseudorandom  numbers. Where are random numbers used? As a developer they were rarely required. Recently, however we’ve seen them appear in more and more places - it seems they are  everywhere ! In DevOps, I’ve used RNG’s for creating message payloads of arbitrary size, and for file or directory names. These values are often created using scripts written in  bash . This first article will explore three simple RNG’s that can be run from bash. It is not an exhaustive list, as there are others such as  jot  that...

Build R project using Make

Image
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 ...