class: center, middle, inverse, title-slide # autoharp ### Vik Gopal --- # Example Worksheet .left-column[ <img src="user2021-autoharp_files/figure-html/unnamed-chunk-1-1.png" title="2-panel figure shows pdf and cdf of random variable" alt="2-panel figure shows pdf and cdf of random variable" width="110%" /> ] .right-column[ ## Question Write a function that simulates from the pdf $$ f(x) = 4x^3 I(0 < x < 1) $$ Run the function to generate `\(10^4\)` random variates. ## Requirements - A function named `rf( )`, with two arguments. - A vector named `X` of length `1e4`. ] --- class: middle .pull-left[ ## Problems We Faced Students' code failed to run on our machines because of: - logical errors, - packages they used, - objects wrongly named, or - incorrect path settings. ] -- .pull-right[ ## Our Goals We wanted a flexible framework to assess: - correctness of output objects, - run-time efficiency, and - R coding expertise. ] --- class: middle <img src="instructor_overview.png" title="Desired workflow" alt="Desired workflow" width="75%" style="display: block; margin: auto;" /> --- # Testing Correctness Output <img src="framework1-1a.png" title="Solution template is run to generate correct versions of objects and create a test script." alt="Solution template is run to generate correct versions of objects and create a test script." width="65%" style="display: block; margin: auto;" /> --- # Testing Correctness Output <img src="framework1-1b.png" title="Student script is run to generate student versions of objects." alt="Student script is run to generate student versions of objects." width="65%" style="display: block; margin: auto;" /> --- # Testing Correctness Output <img src="framework1-1c.png" title="Correct objects are copied to student environment" alt="Correct objects are copied to student environment" width="65%" style="display: block; margin: auto;" /> --- # Testing Correctness Output <img src="framework1-1d.png" title="Test code is executed in student environment, thus checking student-created objects." alt="Test code is executed in student environment, thus checking student-created objects." width="65%" style="display: block; margin: auto;" /> --- # Run-time Statistics <img src="tut1_runtime.png" title="Histograms of memory usage and run-time for a batch of worksheets" alt="Histograms of memory usage and run-time for a batch of worksheets" width="60%" style="display: block; margin: auto;" /> --- # Static Code Analysis .pull-left[ <img src="user2021-autoharp_files/figure-html/unnamed-chunk-8-1.png" style="display: block; margin: auto;" /> ] .pull-right[ ```r rf <- function (n) { x <- c () for (i in 1:n) { x [i] <- (runif(1)/4)^(1/3) } return (x) } ``` * `igraph` does the plotting. ] --- # Static Code Analysis .pull-left[ <img src="user2021-autoharp_files/figure-html/unnamed-chunk-10-1.png" style="display: block; margin: auto;" /> ] .pull-right[ ```r rf <- function (n) { * x <- c () * for (i in 1:n) { * x [i] <- (runif(1)/4)^(1/3) } return (x) } ``` * This code has room for improvement. ] --- # Static Code Analysis .pull-left[ <img src="user2021-autoharp_files/figure-html/unnamed-chunk-12-1.png" style="display: block; margin: auto;" /> ] .pull-right[ <table> <thead> <tr> <th style="text-align:right;"> id </th> <th style="text-align:left;"> name </th> <th style="text-align:left;"> call_status </th> <th style="text-align:left;"> formal_arg </th> <th style="text-align:right;"> depth </th> </tr> </thead> <tbody> <tr> <td style="text-align:right;"> 1 </td> <td style="text-align:left;"> <- </td> <td style="text-align:left;"> TRUE </td> <td style="text-align:left;"> FALSE </td> <td style="text-align:right;"> 1 </td> </tr> <tr> <td style="text-align:right;"> 2 </td> <td style="text-align:left;"> rf </td> <td style="text-align:left;"> FALSE </td> <td style="text-align:left;"> FALSE </td> <td style="text-align:right;"> 2 </td> </tr> <tr> <td style="text-align:right;"> 3 </td> <td style="text-align:left;"> function </td> <td style="text-align:left;"> TRUE </td> <td style="text-align:left;"> FALSE </td> <td style="text-align:right;"> 2 </td> </tr> <tr> <td style="text-align:right;"> 4 </td> <td style="text-align:left;"> n </td> <td style="text-align:left;"> FALSE </td> <td style="text-align:left;"> TRUE </td> <td style="text-align:right;"> 3 </td> </tr> <tr> <td style="text-align:right;"> 5 </td> <td style="text-align:left;"> { </td> <td style="text-align:left;"> TRUE </td> <td style="text-align:left;"> FALSE </td> <td style="text-align:right;"> 3 </td> </tr> <tr> <td style="text-align:right;"> 6 </td> <td style="text-align:left;"> <- </td> <td style="text-align:left;"> TRUE </td> <td style="text-align:left;"> FALSE </td> <td style="text-align:right;"> 4 </td> </tr> </tbody> </table> <br> * An R expression is stored as an S4 object. * The `TreeHarp` object contains node type information. * Tokenising allows for Natural Language techniques to be applied. ] --- # Additional Functions 1. It's easy for students to make mistakes such as: * slightly different names for objects. * incorrect path settings. 1. `autoharp` provides a [shiny app](https://blog.nus.edu.sg/stavg/files/2021/06/soln_checker_v2.mp4) for students to run their code before submission. 2. The `autoharp` was developed for a class on visualisation in R, so it contains a function to [generate thumbnails](https://blog.nus.edu.sg/stavg/files/2021/06/thumbnails_v2.mp4) of all the plots created. --- # Desired Functionality - Detecting areas for improvement in student scripts, e.g. - duplicated chunks of code within a script. - highlighting where piping, or an apply call could be used instead. ```r x <- f1(w) y <- f2(x) z <- f3(y) ``` - Diffs/Visualisations between data frames. --- class: center, middle ### Is the `autoharp` the right package for me? --- # Alternatives 1. The package helps in the way I create worksheet problems, and grade them. * Students submit an entire script, which I run on my end. 1. There are alternative packages out there, e.g.: * `markmyassignment` * `homework` * `learnr`, together with `grade_this`. --- # Documentation & Contact Information 1. User manuals (and this deck of slides) can be found at https://singator.github.io/autoharp-docs/ 2. The `autoharp` ships with a couple of examples of solution templates and student scripts that you can try out. ```r list.files(system.file("examples", package="autoharp")) ``` ``` ## [1] "question_sheets" "soln_templates" "student_scripts" ``` 2. Feel free to get in touch at **vik.gopal at nus.edu.sg** if you need to. -- <br> ## Thank you for listening, stay safe and healthy! --- class: center, middle ### P.S.: if you are wondering about the name... It's the title of a song by Belgian band known as [Hooverphonic](https://www.hooverphonic.com/). I used to listen to them a lot (Thanks Claudio!).