Quantcast
Channel: r software hub
Viewing all articles
Browse latest Browse all 1015

ezknitr: R package to avoid the typical working directory pain when using knitr

$
0
0

By Dean Attali’s R Blog

A new package has hit the CRAN shelves this week. While knitr is one of the most useful R packages in existence, ezknitr is a simple extension to it that adds flexibility in several ways.

One common source of frustration with knitr is that it assumes the directory where the source file lives should be the working directory, which is often not true. ezknitr addresses this problem by giving you complete control over where all the inputs and outputs are, and adds several other convenient features. The two main functions are ezknit() and ezspin(), which are wrappers around knitr‘s knit() and spin(), used to make rendering markdown/HTML documents easier.

You can see Jenny Bryan’s way of dealing with this problem in this gist or simply browse the knitr GitHub issues to see people discussing the issue surrounding directories.

Table of contents

Availability

ezknitr is available through both CRAN (install.packages("ezknitr")) and GitHub (devtools::install_github("daattali/ezknitr")).

Overview

If you have a very simple project with a flat directory structure, then knitr works great. But even something as simple as trying to knit a document that reads a file from a different directory or placing the output rendered files in a different folder cannot be easily done with knitr.

ezknitr improves basic knitr functionality in a few ways. You get to decide:

  • What the working directory of the source file is
    • Default is your current working directory, which often makes more sense than the knitr assumption that the working directory is wherever the input file is
  • Where the output files will go
    • With knitr, all the rendered output files will be generated in the folder you’re currently in
  • Where the figures generated in the markdown document will be stored
    • knitr makes it cumbersome to change this directory
  • Any parameters to pass to the source file

Viewing all articles
Browse latest Browse all 1015

Trending Articles