Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get each line of code in a code chunk to be shown in the 'R Markdown' window as it is executed

Tags:

r

rstudio

knitr

When knitting an R markdown file, I often find myself staring at the Markdown output waiting for a chunk to finish. Unfortunately, I don't know of any way of seeing what command that chunk is currently executing. This would be handy to get a sense of the progress, or to find performance bottlenecks.

Is there some knitr option I have missed ? Setting progress=TRUE, verbose=TRUE just shows the chunk code before that chunk is executed. I want each line of code to be shown in the console just after/before it is executed, just like in an interactive session.

like image 980
Mathias Versichele Avatar asked Oct 30 '22 23:10

Mathias Versichele


1 Answers

Next to Console tab at the bottom, you will see R Markdown tab, all steps can be seen there, see screenshot below:

enter image description here

EDIT 1: We need to set up global options opts_knit$set(progress = TRUE, verbose = TRUE)

Example:

---
title: "Untitled"
output: html_document
---

```{r global_options, include=FALSE}
library(knitr)
opts_knit$set(progress = TRUE, verbose = TRUE)
```

This is an R Markdown document. Markdown is a simple ...


```{r SummaryCars}
summary(cars)
```

Output on R Markdown window:

processing file: temppp.Rmd
  |................                                                 |  25%
  ordinary text without R code

  |................................                                 |  50%
label: global_options (with options) 
List of 1
 $ include: logi FALSE

  |.................................................                |  75%
  ordinary text without R code

  |.................................................................| 100%
label: SummaryCars
   ~~~~~~~~~~~~~~~~~~~~~~~~~ R code chunk ~~~~~~~~~~~~~~~~~~~~~~~~~~ 
   summary(cars) 
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
##------ Fri Jul 17 09:00:42 2015 ------##


output file: temppp.knit.md

EDIT 2: This answer doesn't meet OP's requirement, keeping this answer as an example to illustrate OP's code.

like image 89
4 revs Avatar answered Nov 13 '22 21:11

4 revs