From 737798763f75fa9fbdc56b37f13f30ccf27ad4b5 Mon Sep 17 00:00:00 2001 From: Peter Humburg Date: Wed, 15 Oct 2014 11:16:24 +0100 Subject: [PATCH 1/7] fixed typo --- example.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example.Rmd b/example.Rmd index 1d1b625..32f3646 100644 --- a/example.Rmd +++ b/example.Rmd @@ -165,7 +165,7 @@ As one might expect a working LaTeX tool chain is required to generate PDF output from LaTeX documents. Several distributions are available online, including [MiKTeX](http://miktex.org/) and [TeX Live](https://www.tug.org/texlive/). -[Python](https://www.python.org/) ($\geq$ 2.7) is required for `pandoc` the +[Python](https://www.python.org/) ($\geq$ 2.7) is required for the `pandoc` filters discussed in the latter parts of this document. # Brief Markdown primer From cb59d6443523bfb88fa42f56477c0eedc3225b65 Mon Sep 17 00:00:00 2001 From: Peter Humburg Date: Wed, 15 Oct 2014 11:28:17 +0100 Subject: [PATCH 2/7] Mention need for `pandocfilters` module in software requirements. --- README.md | 6 ++++-- example.Rmd | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 66c59ec..3d52100 100644 --- a/README.md +++ b/README.md @@ -44,5 +44,7 @@ As one might expect a working LaTeX tool chain is required to generate PDF output from LaTeX documents. Several distributions are available online, including [MiKTeX](http://miktex.org/) and [TeX Live](https://www.tug.org/texlive/). -[Python](https://www.python.org/) (>= 2.7) is required for `pandoc` the -filters discussed in the latter parts of this document. +[Python](https://www.python.org/) ($\geq$ 2.7) is required for the `pandoc` +filters discussed in the latter parts of this document. This also requires +the `pandocfilters` Python module, which can be installed via +[pip](https://pypi.python.org/pypi/pip). \ No newline at end of file diff --git a/example.Rmd b/example.Rmd index 32f3646..1777d36 100644 --- a/example.Rmd +++ b/example.Rmd @@ -166,7 +166,9 @@ PDF output from LaTeX documents. Several distributions are available online, including [MiKTeX](http://miktex.org/) and [TeX Live](https://www.tug.org/texlive/). [Python](https://www.python.org/) ($\geq$ 2.7) is required for the `pandoc` -filters discussed in the latter parts of this document. +filters discussed in the latter parts of this document. This also requires +the `pandocfilters` Python module, which can be installed via +[pip](https://pypi.python.org/pypi/pip). # Brief Markdown primer A Markdown formatted file is in essence a plain text file that may contain a number of From 6e357d8d8cba70a77f4ee5b20b8da343a36578c5 Mon Sep 17 00:00:00 2001 From: Peter Humburg Date: Wed, 15 Oct 2014 15:36:21 +0100 Subject: [PATCH 3/7] fixed typo --- example.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example.Rmd b/example.Rmd index 1777d36..1506d08 100644 --- a/example.Rmd +++ b/example.Rmd @@ -485,7 +485,7 @@ animation::saveGIF(lapply(1:20, plotFun), interval=0.5, movie.name="dist3.gif") ``` Since the graphics output of this code is written directly to a file rather than an on-screen -graphics device it will not outomatically included in the Markdown document produced +graphics device it will not be automatically included in the Markdown document produced by `knitr`. It can be included manually using the Markdown syntax for the inclusion of figures. From de64a39a4940e7cbecada62dfd3415d69f4c76a2 Mon Sep 17 00:00:00 2001 From: Peter Humburg Date: Wed, 15 Oct 2014 15:40:45 +0100 Subject: [PATCH 4/7] fixed typo --- example.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example.Rmd b/example.Rmd index 1506d08..f5231c1 100644 --- a/example.Rmd +++ b/example.Rmd @@ -504,7 +504,7 @@ threeDists(1) dev.off() ``` -Here we make use of `pandoc`'s `--default-image-extension` option to set the daefault +Here we make use of `pandoc`'s `--default-image-extension` option to set the default image format to gif for HTML and docx output and to png for PDF. ## Tables From 2cd359eb5133610451af4ca7ed126bd537c9315c Mon Sep 17 00:00:00 2001 From: Peter Humburg Date: Wed, 15 Oct 2014 16:18:34 +0100 Subject: [PATCH 5/7] Added section explaining possible difficulties in generating animated GIFs on Windows. --- example.Rmd | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/example.Rmd b/example.Rmd index f5231c1..48c0f8e 100644 --- a/example.Rmd +++ b/example.Rmd @@ -507,6 +507,37 @@ dev.off() Here we make use of `pandoc`'s `--default-image-extension` option to set the default image format to gif for HTML and docx output and to png for PDF. +### Creating animations on Windows +The procedure for generating animations may fail on Windows^[Thanks to +[reyntjesr](https://github.com/reyntjesr) for reporting this issue and providing +the work around described here.]. This may be due to a conflict +between ImageMagick's `convert.exe`, which is used to convert from png to gif, +and Windows' own `convert.exe`, which converts between FAT and NTFS file systems. +It may be possible to circumvent this issue by using +[GraphicsMagick](http://www.graphicsmagick.org/) for the conversion instead. To +do this, install GraphicsMagick and replace the call to `saveGIF` above with + +```r +animation::saveGIF(lapply(1:20, plotFun), interval=0.5, movie.name="dist3.gif", + convert="gm convert") +``` + +An alternative work-around involves bypassing the animation package entirely. +Instead, rename ImageMagick's `convert.exe` to `imConvert.exe`^[Instead of +renaming the file it is also possible to use the full path to ImageMagick's `convert.exe` +in the shell command.], generate one +png file for each frame of the animation and then call `imConvert` manually +to create the animated gif. + +```r +png(file="figure/threeDist%02d.png", width=500, heigh=500) + lapply(1:20, threeDists) +dev.off() + +shell("imConvert -delay 40 figure/threeDist*.png dist3.gif") +``` + + ## Tables It is often convenient to display the contents of R objects in the final document. While it is easy to simply display the output of R's `print` statement as it would From 73c666c5e18d5c9f57449dc72741e8cdb12833ea Mon Sep 17 00:00:00 2001 From: Peter Humburg Date: Wed, 15 Oct 2014 16:21:25 +0100 Subject: [PATCH 6/7] Added the requirement for ImageMagick/GraphicsMagick to compilation instructions. --- README.md | 4 +++- example.Rmd | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3d52100..a8cab88 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,9 @@ Additional R packages used: formatting of R objects) These can be installed via the `install.packages` command from within R. -Animations also require [ffmpeg](https://www.ffmpeg.org/). +Animations also require [ffmpeg](https://www.ffmpeg.org/) and either +[ImageMagick](http://www.imagemagick.org/) or +[GraphicsMagick](http://www.graphicsmagick.org/). As one might expect a working LaTeX tool chain is required to generate PDF output from LaTeX documents. Several distributions are available diff --git a/example.Rmd b/example.Rmd index 48c0f8e..78e0e62 100644 --- a/example.Rmd +++ b/example.Rmd @@ -159,7 +159,9 @@ Additional R packages used: formatting of R objects) These can be installed via the `install.packages` command from within R. -Animations also require [ffmpeg](https://www.ffmpeg.org/). +Animations also require [ffmpeg](https://www.ffmpeg.org/) and either +[ImageMagick](http://www.imagemagick.org/) or +[GraphicsMagick](http://www.graphicsmagick.org/). As one might expect a working LaTeX tool chain is required to generate PDF output from LaTeX documents. Several distributions are available From ac488fff28d95519bafebad46c220abfd4633714 Mon Sep 17 00:00:00 2001 From: Peter Humburg Date: Wed, 15 Oct 2014 16:25:13 +0100 Subject: [PATCH 7/7] Added note on using GraphicsMagick. --- example.Rmd | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/example.Rmd b/example.Rmd index 78e0e62..a4bb700 100644 --- a/example.Rmd +++ b/example.Rmd @@ -463,7 +463,7 @@ for(i in 1:20){ ``` It is possible to generate an animated GIF from this sequence of plots by wrapping the -above code in a function and then calling `saveGIF` from the animation package. +above code in a function and then calling `saveGIF` from the animation package. ```{r distributions3, results="hide"} threeDists <- function(df, x=seq(-6,6, by=0.1)){ @@ -486,6 +486,9 @@ plotFun <- function(df){ animation::saveGIF(lapply(1:20, plotFun), interval=0.5, movie.name="dist3.gif") ``` +The code above assumes that ImageMagick is installed. If you are using GraphicsMagick +instead add the option `convert="gm convert"` to the `saveGIF` call. + Since the graphics output of this code is written directly to a file rather than an on-screen graphics device it will not be automatically included in the Markdown document produced by `knitr`. It can be included manually using the Markdown syntax for the inclusion