# RTutor: Improving Interactive Problem Sets by Analyzing Submissions

**Economics and R - R posts**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

At Ulm University, we currently use RTutor for several elective courses where students solve interactive problem sets at home. They can test their solutions and get automatic hints, and then submit their solution. Starting next year, we plan to use RTutor in a new compulsory data science project course in our business and economics bachelor. For a compulsory course, it seems even more important that the problem sets are well polished to avoid excessive frustration by students who might get stuck. In this blog post, I want to illustrate how the new companion package RTutorSAGI can be used to systematically analyse students’ submission in order to improve the RTutor problem sets used in class.

Also note that there have been substantial updates for RTutor itself in July 2019. There is finally a pkgdown powered project page:

http://skranz.github.io/RTutor/

In the Manuals section you can find the new, fully rewritten documentation. Other new features are easier customization of hints and improved adaptive automatic hints (see here).

Now, let us directly exemplify RTutorSAGI (SAGI stands for Submission Analysis for Grading and Improvement) with some code:

```
<span class="n">library</span><span class="p">(</span><span class="n">RTutorSAGI</span><span class="p">)</span><span class="w">
</span><span class="c1"># Load all submission files from directory ./sub</span><span class="w">
</span><span class="n">sub.li</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">load.subs</span><span class="p">(</span><span class="n">sub.dir</span><span class="o">=</span><span class="s2">"sub"</span><span class="p">,</span><span class="w"> </span><span class="n">warn</span><span class="o">=</span><span class="kc">FALSE</span><span class="p">)</span><span class="w">
</span><span class="c1"># Create summary of solution attempts by chunk</span><span class="w">
</span><span class="n">sum.df</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">analyse.subs</span><span class="p">(</span><span class="n">sub.li</span><span class="p">,</span><span class="w"> </span><span class="n">rps.dir</span><span class="o">=</span><span class="s2">"org_ps"</span><span class="p">,</span><span class="w">
</span><span class="n">just.summary</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">,</span><span class="w"> </span><span class="n">protracted.minutes</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">30</span><span class="p">)</span><span class="w">
</span><span class="c1"># Show top 10 of chunks were students</span><span class="w">
</span><span class="c1"># needed most solution attempts</span><span class="w">
</span><span class="n">sum.df</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">arrange</span><span class="p">(</span><span class="o">-</span><span class="n">err</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">head</span><span class="p">(</span><span class="m">10</span><span class="p">)</span><span class="w">
</span>
```

ps.name | chunk | chunk.name | solved | unsolved | protracted | err | users.err | hint | users.hint |
---|---|---|---|---|---|---|---|---|---|

ps_1b1_ols | 22 | 5_a | 14 | 0 | 10 | 127 | 10 | 28 | 7 |

ps_1d | 3 | 1_b_2 | 15 | 0 | 8 | 109 | 8 | 18 | 7 |

ps_2a_logit | 18 | 4_e_2 | 15 | 0 | 4 | 98 | 4 | 15 | 3 |

ps_2a_logit | 2 | 1_b | 15 | 0 | 9 | 88 | 9 | 65 | 8 |

Intro | 13 | 3_b | 15 | 0 | 13 | 88 | 13 | 11 | 8 |

ps_1b2_iv | 23 | 4_2_f | 14 | 0 | 9 | 83 | 9 | 46 | 8 |

ps_2a_logit | 20 | 5_1_b | 15 | 0 | 10 | 82 | 10 | 62 | 10 |

ps_1b1_ols | 12 | 2_d | 15 | 0 | 6 | 80 | 6 | 16 | 5 |

ps_2a_logit | 11 | 3_a | 15 | 0 | 9 | 74 | 9 | 25 | 8 |

ps_2a_logit | 10 | 2_f | 15 | 0 | 7 | 70 | 7 | 11 | 5 |

The code analyses all students’ submissions of the 8 RTutor problem sets of one of my master level economics courses. The created data frame `sum.df`

provides information for the different chunks of how hard they were to solve. From the columns `solved`

and `unsolved`

we learn that in the end all students who tried mastered to solve all 10 shown chunks (and this also holds true for the non shown chunks.). This is reassuring but it was also a small class. The column `err`

shows how often in total students checked their solution for the corresponding chunk and the correctness test failed. This was most often the case for the chunk in the first line, i.e. chunk `5_a`

in my problem set `ps_1b1_ols`

: 127 times. We also see that 10 students (column `users.err`

) entered at least one wrong solution. For this chunk, a hint was requested in total 28 times and 7 users asked at least once for a hint.

The column `protracted`

is an indicator whether or not it took a long time to finally solve the chunk. More precisely, we compute the duration between the first time a student entered a wrong solution (that differed from the original shown task code) and the time when that student finally solved the chunk. We then count the number of students for whom that duration is longer than 30 minutes. We set the threshold 30 minutes via the argument `protracted.minutes`

in the call to `analyze.subs`

. Here 10 from 14 students took longer than 30 minutes. That does not neccessarily mean that they worked more than 30 minutes on the chunk. Many of the students could have decided to take a break because they could not solve it immediately. We get more detailed information by looking at the individual chunk logs illustrated further below.

Given that students in this class had a total of 164 tasks in RTutor problem sets where they needed to enter code, I decided for the benefit of future students to smooth some problematic tasks by changing the structure of some problem sets and adding more informative custom hints.

Let us look at the chunk `5_a`

discussed above. In this task students should create the following function that will later be used for a systematic Monte-Carlo Simulation of an OLS estimator:

```
<span class="n">sim.and.est</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">beta0</span><span class="o">=</span><span class="m">100</span><span class="p">,</span><span class="n">beta1</span><span class="o">=</span><span class="m">-1</span><span class="p">,</span><span class="n">...</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="n">data</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">sim.data</span><span class="p">(</span><span class="n">beta0</span><span class="o">=</span><span class="n">beta0</span><span class="p">,</span><span class="w"> </span><span class="n">beta1</span><span class="o">=</span><span class="n">beta1</span><span class="p">,</span><span class="w"> </span><span class="n">...</span><span class="p">)</span><span class="w">
</span><span class="c1"># Compute the estimated coefficient beta.hat from a linear regression</span><span class="w">
</span><span class="c1"># of the demand function </span><span class="w">
</span><span class="n">beta.hat</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">coef</span><span class="p">(</span><span class="n">lm.fit</span><span class="p">(</span><span class="n">y</span><span class="o">=</span><span class="n">data</span><span class="o">$</span><span class="n">q</span><span class="p">,</span><span class="w"> </span><span class="n">x</span><span class="o">=</span><span class="n">cbind</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="n">data</span><span class="o">$</span><span class="n">p</span><span class="p">)))</span><span class="w">
</span><span class="c1"># Generate and return a data.frame containing </span><span class="w">
</span><span class="c1"># the estimated and true coefficients</span><span class="w">
</span><span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">data.frame</span><span class="p">(</span><span class="n">coef.name</span><span class="o">=</span><span class="nf">c</span><span class="p">(</span><span class="s2">"beta0"</span><span class="p">,</span><span class="s2">"beta1"</span><span class="p">),</span><span class="w">
</span><span class="n">est.coef</span><span class="o">=</span><span class="n">beta.hat</span><span class="p">,</span><span class="w"> </span><span class="n">true.coef</span><span class="o">=</span><span class="nf">c</span><span class="p">(</span><span class="n">beta0</span><span class="p">,</span><span class="n">beta1</span><span class="p">))</span><span class="w">
</span><span class="nf">return</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span><span class="w">
</span><span class="p">}</span><span class="w">
</span>
```

Writing a function tends to be tricky for inexperienced users. Even though I gave students some additional information and a partial solution, it is ex-post understandable that several students got stuck here.

For improving a problem set, it is helpful to know how students tried to solve the task and what exactly went wrong. For this purpose, we can run once the RTutorSAGI function `write.chunk.logs`

:

```
<span class="n">write.chunk.logs</span><span class="p">(</span><span class="n">sub.li</span><span class="p">,</span><span class="n">logs.dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"chunk_logs"</span><span class="p">,</span><span class="w"> </span><span class="n">rps.dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"org_ps"</span><span class="p">)</span><span class="w">
</span>
```

The call above saves in the directory `./chunk_logs`

for every chunk where at least one user entered a wrong solution an R file that contains a log of the solution attempts of all users. Here is an exercept from the log of chunk 5_a:

```
<span class="c1"># ps_1b1_ols 5_a</span><span class="w">
</span><span class="c1"># 14 users solved (10 took long time) and 0 failed.</span><span class="w">
</span><span class="c1"># Failed checks: 127, Hints: 28</span><span class="w">
</span><span class="c1"># NEW USER solved after 3 failures (3.9 mins) *********************</span><span class="w">
</span><span class="c1"># A function that simulates random prices and demand</span><span class="w">
</span><span class="c1"># and estimates beta.hat</span><span class="w">
</span><span class="n">sim.and.est</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">beta0</span><span class="o">=</span><span class="m">100</span><span class="p">,</span><span class="n">beta1</span><span class="o">=</span><span class="m">-1</span><span class="p">,</span><span class="n">...</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="n">data</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">sim.data</span><span class="p">(</span><span class="n">beta0</span><span class="o">=</span><span class="n">beta0</span><span class="p">,</span><span class="w"> </span><span class="n">beta1</span><span class="o">=</span><span class="n">beta1</span><span class="p">,</span><span class="w"> </span><span class="n">...</span><span class="p">)</span><span class="w">
</span><span class="c1"># Compute the estimated coefficient beta.hat from a linear regression</span><span class="w">
</span><span class="c1"># of the demand function (use lm.fit or lm and coef)</span><span class="w">
</span><span class="n">reg</span><span class="o"><-</span><span class="n">lm</span><span class="p">(</span><span class="n">q</span><span class="o">~</span><span class="n">p</span><span class="p">)</span><span class="w">
</span><span class="n">coef</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w">
</span><span class="c1"># enter your code here ...</span><span class="w">
</span><span class="c1"># Generate and return a data.frame containing the</span><span class="w">
</span><span class="c1"># estimated and true coefficients</span><span class="w">
</span><span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">data.frame</span><span class="p">(</span><span class="n">coef.name</span><span class="o">=</span><span class="nf">c</span><span class="p">(</span><span class="s2">"beta0"</span><span class="p">,</span><span class="s2">"beta1"</span><span class="p">),</span><span class="w">
</span><span class="n">est.coef</span><span class="o">=</span><span class="n">beta.hat</span><span class="p">,</span><span class="w"> </span><span class="n">true.coef</span><span class="o">=</span><span class="nf">c</span><span class="p">(</span><span class="n">beta0</span><span class="p">,</span><span class="n">beta1</span><span class="p">))</span><span class="w">
</span><span class="nf">return</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="c1"># *** 102 secs later... </span><span class="w">
</span><span class="c1"># A function that simulates random prices and demand and estimates beta.hat</span><span class="w">
</span><span class="n">sim.and.est</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">beta0</span><span class="o">=</span><span class="m">100</span><span class="p">,</span><span class="n">beta1</span><span class="o">=</span><span class="m">-1</span><span class="p">,</span><span class="n">...</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="n">data</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">sim.data</span><span class="p">(</span><span class="n">beta0</span><span class="o">=</span><span class="n">beta0</span><span class="p">,</span><span class="w"> </span><span class="n">beta1</span><span class="o">=</span><span class="n">beta1</span><span class="p">,</span><span class="w"> </span><span class="n">...</span><span class="p">)</span><span class="w">
</span><span class="c1"># Compute the estimated coefficient beta.hat from a linear regression</span><span class="w">
</span><span class="c1"># of the demand function (use lm.fit or lm and coef)</span><span class="w">
</span><span class="n">reg</span><span class="o"><-</span><span class="n">lm.fit</span><span class="p">(</span><span class="n">cbind</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="n">p</span><span class="p">),</span><span class="w"> </span><span class="n">q</span><span class="p">)</span><span class="w">
</span><span class="n">coef</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w">
</span><span class="c1"># enter your code here ...</span><span class="w">
</span><span class="c1"># Generate and return a data.frame containing the</span><span class="w">
</span><span class="c1"># estimated and true coefficients</span><span class="w">
</span><span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">data.frame</span><span class="p">(</span><span class="n">coef.name</span><span class="o">=</span><span class="nf">c</span><span class="p">(</span><span class="s2">"beta0"</span><span class="p">,</span><span class="s2">"beta1"</span><span class="p">),</span><span class="w">
</span><span class="n">est.coef</span><span class="o">=</span><span class="n">beta.hat</span><span class="p">,</span><span class="w"> </span><span class="n">true.coef</span><span class="o">=</span><span class="nf">c</span><span class="p">(</span><span class="n">beta0</span><span class="p">,</span><span class="n">beta1</span><span class="p">))</span><span class="w">
</span><span class="nf">return</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="c1"># *** 24 secs later... </span><span class="w">
</span><span class="c1"># A function that simulates random prices and demand and estimates beta.hat</span><span class="w">
</span><span class="n">sim.and.est</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">beta0</span><span class="o">=</span><span class="m">100</span><span class="p">,</span><span class="n">beta1</span><span class="o">=</span><span class="m">-1</span><span class="p">,</span><span class="n">...</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="n">data</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">sim.data</span><span class="p">(</span><span class="n">beta0</span><span class="o">=</span><span class="n">beta0</span><span class="p">,</span><span class="w"> </span><span class="n">beta1</span><span class="o">=</span><span class="n">beta1</span><span class="p">,</span><span class="w"> </span><span class="n">...</span><span class="p">)</span><span class="w">
</span><span class="c1"># Compute the estimated coefficient beta.hat from a linear regression</span><span class="w">
</span><span class="c1"># of the demand function (use lm.fit or lm and coef)</span><span class="w">
</span><span class="n">reg</span><span class="o"><-</span><span class="n">lm.fit</span><span class="p">(</span><span class="n">p</span><span class="p">,</span><span class="w"> </span><span class="n">q</span><span class="p">)</span><span class="w">
</span><span class="n">coef</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w">
</span><span class="c1"># enter your code here ...</span><span class="w">
</span><span class="c1"># Generate and return a data.frame containing the</span><span class="w">
</span><span class="c1"># estimated and true coefficients</span><span class="w">
</span><span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">data.frame</span><span class="p">(</span><span class="n">coef.name</span><span class="o">=</span><span class="nf">c</span><span class="p">(</span><span class="s2">"beta0"</span><span class="p">,</span><span class="s2">"beta1"</span><span class="p">),</span><span class="w">
</span><span class="n">est.coef</span><span class="o">=</span><span class="n">beta.hat</span><span class="p">,</span><span class="w"> </span><span class="n">true.coef</span><span class="o">=</span><span class="nf">c</span><span class="p">(</span><span class="n">beta0</span><span class="p">,</span><span class="n">beta1</span><span class="p">))</span><span class="w">
</span><span class="nf">return</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="c1"># *** 9 secs later... asked for hint.</span><span class="w">
</span><span class="c1"># *** 100 secs later... solved succesfully!</span><span class="w">
</span><span class="c1"># NEW USER solved after 4 failures (4.6 hours) *********************</span><span class="w">
</span><span class="c1"># ... over 2000 more lines ...</span><span class="w">
</span>
```

The first user makes several mistakes: not using the variables `p`

and `q`

from the data frame `data`

and not assigning `coef(reg)`

to `beta.hat`

. (These errors were not so easily detected by the user because in earlier tasks the variables `p`

, `q`

and `beta.hat`

were assigned, i.e. the function did run without error in RStudio). None of the 3 first attempts corrected that mistake. In the new RTutor version the automatic hint provides some information about the problem:

```
Warning: Your function uses the global variable(s)
beta.hat, p, q
Often global variables in a function indicate a bug and you just have
forgotten to assign values to beta.hat, p, q inside your function.
Either correct your function or make sure that you truely want to
use these global variables inside your function.
```

However the automatic hints in RTutor don’t allow to analyse step by step the different commands inside a function. Looking at more users in the log, one finds that there are many ways to write an erroneous function. This means custom hints were also of limited use here.

In the revision of my problem sets, I made the following change. If students shall write a function, it is now almost always done in a two step procedure. In an initial task students just write the future function body as normal R code for some example values of the function arguments. Since the code is not yet in a function, RTutor can nicely test it step by step and provide informative automatic hints. In a subsequent task students have to copy that function body into a function where I already provide the function header and closing `}`

in a `fill_in`

block.

For another example, let us look at a much simpler task from the same problem set:

Using the command

`cbind`

, generate the matrix X of explanatory variable whose first column consists of 1 and the second column consists of p

The sample solution is just:

```
<span class="n">X</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cbind</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="n">p</span><span class="p">)</span><span class="w">
</span>
```

Here is an extract from the corresponding chunk log that was created by `write.chunk.logs`

:

```
<span class="c1"># ps_1b1_ols 1_b_2</span><span class="w">
</span><span class="c1"># 15 users solved (4 took long time) and 0 users failed.</span><span class="w">
</span><span class="c1"># Failed checks: 8 Hints: 4</span><span class="w">
</span><span class="c1"># NEW USER solved after 3 failures (3.1 mins) *********************</span><span class="w">
</span><span class="n">cbind</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="n">p</span><span class="p">)</span><span class="w">
</span><span class="c1"># *** 29 secs later... </span><span class="w">
</span><span class="n">x</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">cbind</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="n">p</span><span class="p">)</span><span class="w">
</span><span class="c1"># *** 13 secs later... </span><span class="w">
</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cbind</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="n">p</span><span class="p">)</span><span class="w">
</span><span class="c1"># *** 98 secs later... asked for hint.</span><span class="w">
</span><span class="c1"># *** 49 secs later... solved succesfully!</span><span class="w">
</span><span class="c1"># NEW USER solved after 1 failures (6.7 mins) *********************</span><span class="w">
</span><span class="c1"># asked for hint.</span><span class="w">
</span><span class="c1"># *** 359 secs later... </span><span class="w">
</span><span class="n">x</span><span class="o">=</span><span class="w"> </span><span class="n">cbind</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="n">p</span><span class="p">)</span><span class="w">
</span><span class="c1"># *** 41 secs later... solved succesfully!</span><span class="w">
</span><span class="c1"># NEW USER solved after 2 failures (2.7 mins) *********************</span><span class="w">
</span><span class="n">x</span><span class="o">=</span><span class="n">cbind</span><span class="p">(</span><span class="nf">rep</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="nb">T</span><span class="p">),</span><span class="n">p</span><span class="p">)</span><span class="w">
</span><span class="c1"># *** 22 secs later... </span><span class="w">
</span><span class="n">x</span><span class="o">=</span><span class="n">cbind</span><span class="p">(</span><span class="nf">rep</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="nb">T</span><span class="p">),</span><span class="n">p</span><span class="p">)</span><span class="w">
</span><span class="c1"># *** 103 secs later... asked for hint.</span><span class="w">
</span><span class="c1"># *** 38 secs later... solved succesfully!</span><span class="w">
</span>
```

Here is not really a need to customize any hint because every student finally managed to solve the chunk in reasonable time. Nevertheless, it is a nice example to showcase a simple adaptive custom hint. In the new version of the problem set solution file, this chunk is now specified as follows:

```
<span class="n">X</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cbind</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="n">p</span><span class="p">)</span><span class="w">
</span><span class="c1">#< add_to_hint</span><span class="w">
</span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">exists</span><span class="p">(</span><span class="s2">"x"</span><span class="p">)</span><span class="w"> </span><span class="o">&</span><span class="w"> </span><span class="o">!</span><span class="n">exists</span><span class="p">(</span><span class="s2">"X"</span><span class="p">))</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="n">cat</span><span class="p">(</span><span class="s2">"It looks like you assigned the value to 'x' (lowercase),
but you shall assign the value to 'X' (uppercase)."</span><span class="p">)</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="c1">#></span><span class="w">
</span>
```

Even more than customizing the problem sets of my course, I used the insights from the analysis of submissions to to improve the automatic hints and tests of the RTutor package. For example, it is quite valuable to teach students how to effectively use longer dplyr chains. This can be done now in RTutor problem sets in most cases without the need for any customized hints. Assume you just specified in your solution file the following command

```
<span class="n">dat</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">group_by</span><span class="p">(</span><span class="n">a</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">summarize</span><span class="p">(</span><span class="n">mean_x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mean</span><span class="p">(</span><span class="n">x</span><span class="p">))</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">arrange</span><span class="p">(</span><span class="o">-</span><span class="n">mean_x</span><span class="p">)</span><span class="w">
</span>
```

and the student enters the following wrong code

```
<span class="n">dat</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">group_by</span><span class="p">(</span><span class="n">a</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">summarize</span><span class="p">(</span><span class="n">mean_x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">sum</span><span class="p">(</span><span class="n">x</span><span class="p">))</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">arrange</span><span class="p">(</span><span class="o">-</span><span class="n">mean_x</span><span class="p">)</span><span class="w">
</span>
```

Then RTutor’s automatic hint gives the student a relatively detailed error analysis:

```
In your following pipe chain, I detect an error in the 3rd element:
dat %>%
group_by(a) %>%
summarize(mean_x = sum(x)) %>% !! WRONG !!
arrange(-mean_x)
It is correct to call summarize. But: Your argument mean_x = sum(x)
differs from my solution, where I call the function mean.
```

**leave a comment**for the author, please follow the link and comment on their blog:

**Economics and R - R posts**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.