knitr in a knutshell tutorial

I spent a lot of time this week writing a short tutorial on knitr: knitr in a knutshell.

This is my third little tutorial. (The previous ones were a git/github guide and a minimal make tutorial.)

I’m pleased with these tutorials. In learning new computing skills, it can be hard to get started. My goal was to provide the initial motivation and orientation, and then links to other resources. I think they are effective in that regard.

I’ve gotten really excited about the tools for reproducible research. I think the main reason that statisticians have been so slow to adopt a reproducible workflow is a lack of training.

I’m hoping that these tutorials, plus the other materials that I’m putting together over the course of this semester, for my Tools for Reproducible Research course, will help.

But take a look at the material that Jeff, Roger, and Brian are developing for their Data Science MOOCs; you’ll see that mine are pretty humble contributions.

Advertisements

Tags: ,

16 Responses to “knitr in a knutshell tutorial”

  1. Kent Johnson Says:

    Very helpful document. One thing that would be nice is to include output in some places. Particularly the page on figures and tables would benefit from showing the table results.

  2. MK Says:

    “I think the main reason that statisticians have been so slow to adopt a reproducible workflow is a lack of training.” I think so too, but a runner up is that we are often in a hurry, and the second runner up is that people want a large number of small changes done simultaneously (i.e. don’t know how to define their model): Not much point in documenting every small change meticulously by the book.

    It’s only that the final workflow used, inter alia, for scientific publications, should be documented, and should be reproducible. Guess how often…

  3. Kelvin Says:

    This is extremely helpful given that I have to do a poster presentation in a short notice. Many Thanks!

    I am new to knitr and have a question when running your code knitr_example.Rmd from the knitr Overview section. I keep getting the error message

    Quitting from lines 100-101 (knitr_example.Rmd)
    Error in x[[“name”]] : subscript out of bounds
    Calls: knit … is_par_change -> plot_calls -> sapply -> lapply -> FUN

    where lines 100-101 refer to the chunk

    “`{r summary_plot, fig.height=8}
    plot(sug)
    “`
    In fact, it happens to all the plot execution in the Markdown codes. I tried to look it up on stackoverflow and the internet but couldn’t find anything helpful.

    • Karl Broman Says:

      It looks like you need to install the R/qtl package, with install.packages("qtl")

      In retrospect, having my examples rely on a non-standard package was probably not the best idea, but it was a lot easier for me to edit something I’d already written than write something from scratch.

  4. Gergely Daróczi Says:

    To promote my “pander” package a bit, I cannot stand to mention that you could simply “pander(out)” instead of “kable(summary(out)$coef …., digits = 2)” at the “Tables” part. More details: http://rapporter.github.io/pander/#tables and http://rapporter.github.io/pander/#generic-pander-method

    • Karl Broman Says:

      Wow, that’s cool! For sure, I’ll add mention of this both on the resources page and in the page on Figures and Tables.

      Thanks for the comment, and for the package.

  5. Paolo Says:

    Are you planning to host this course online? something like coursera maybe…

    • Karl Broman Says:

      No immediate plans; it’s hard to improve on the Hopkins Biostat coursera courses. I’ve tried to include sufficient notes with my slides so that they’re useful on their own.

  6. Yet another R package primer | The stupidest thing... Says:

    […] I’d been thinking for some time that I should write another minimal tutorial with an alliterative name, on how to turn R code into a package. And it does seem valuable to have a diversity of resources […]

  7. Zhi Yang Says:

    Hello I have a question about the second ref link. The R studio keeps saying that the pandoc.exe failed to retrieve the file. I noticed that you have corrected the file before. Is there anything I can do to fix it in the R studio? Thank you!

  8. Gui Says:

    love ur tutorial. well done. thx!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s