50% off | Unlimited Data & AI Learning
Get 50% off unlimited learning

RTutor: Interactive R Problem Sets

Author: Sebastian Kranz, Ulm University

RTutor is an R package that allows to develop interactive R exercises. Problem sets can be solved off-line or can be hosted in the web with shinyapps.io. Problem sets can be designed as a Markdown .rmd file (to be solved directly in RStudio) or use a browser-based interface powered by RStudio's Shiny. While the web interface looks nicer, I personally use problem sets in the Markdown format when teaching advanced economic classes.

Trying out some problem sets

You can try out the Rmarkdown version of RTutor via RStudio Cloud:

https://rstudio.cloud/project/39040

For the web-based interface, several students at Ulm University have created very nice problem sets that allow to interactively replicate the main insights of interesting economic articles and to learn a bit about R and econometrics. Before developing your own problem sets, you may want to try out some of these examples:

Public Procurement Auctions: Design, Outcomes and Adaption Costs (by Frederik Collin)

Poverty Reduction and Deforestation (by Katharina Kaufmann)

The Effect of Water Pollution on Cancer (by Brigitte Peter)

Assessing Free Trade Agreements (by Tobias Fischer)

How soap operas reduced fertility in Brazil (by Clara Ulmer)

CO2 Trading and Risk of Firm Relocation (by Benjamin Lux)

On the optimal taxation of top incomes (by Jonas Send)

The effect of the TseTse fly on African Development (by Vanessa Schöller)

Pollution Reduction by Wind Energy (by Anna Sophie Barann)

Wall Street and the Housing Bubble (by Marius Wentz)

Air pollution and house prices (by Moritz Sporer)

A macroeconomic study of credit booms and busts (by Thomas Clausing)

The impact of emmission trading on green innovation (by Arthur Schäfer)

Building Codes and Energy Efficiency (2 versions, by Simon Hertle and Lisa Eilts)

Technological Progress and Fuel Economy of Cars (by Marius Breitmayer)

How can Scandinavians tax so much? (by David Hertle)

An interesting case study of a bank run (by Joachim Plath)

Installation

RTutor and some required packages are not hosted on CRAN (while CRAN is great it takes a lot of time to maintain several packages there). I have created an own Github based R repository, from which you can install RTutor by using the following code:

install.packages("RTutor",repos = c("https://skranz-repo.github.io/drat/",getOption("repos")))

Note: If you want to create your own web-based RTutor problem sets and upload them on shinyapps.io, you need to install RTutor and required packages directly from Github and CRAN as explained below. That is because shinyapps.io only works with R packages directly installed from Github or CRAN.

Installing RTutor directly from Github

To install RTutor and required packages directly from Github and CRAN, you can use the small function in the following gist:

https://gist.github.com/skranz/fad6062e5462c9d0efe4

Copy the code in the link into your R console and then run:

install.rtutor(update.github=TRUE)

Depending on your devtools version, also the following code may work directly (yet source_gist is buggy in some devtools versions):

if (!require(devtools)) 
  install.packages("devtools")

devtools::source_gist("gist.github.com/skranz/fad6062e5462c9d0efe4", filename="install_rtutor.r")
install.rtutor(update.github=TRUE)
library(RTutor)

If you only want to update the RTutor package (and have the other packages already installed). You can just type:

devtools::install_github("skranz/RTutor", upgrade_dependencies=FALSE)

(You may have to restart your R session / RStudio for the update to work.)

Installing and Running RTutor with Docker

If you already use Docker, you can also quickly use RTutor with the docker container skranz/rtutor. The container allows you to work with RTutor via RStudio server in your webbrowser. It already contains some example problem sets, but you can install other problem sets or create your own problem sets. Details are here:

https://hub.docker.com/r/skranz/rtutor/

Since the image contains R, shiny, rstudio and a lot of packages, it has quite some size, however.

Create your own problem sets

Take a look at the files in the vignette folder for documentation of how to create own problem sets.

Suggestions & Feedback

If you have suggestions or find bugs, please don't hesitate to open an issue on this github page. RTutor is still in a preliminary version and feedback is very appreciated.

Copy Link

Version

Install

install.packages('RtutoR')

Monthly Downloads

39

Version

2018.06.08

License

Programm code: GPL >= 2.0 Contributed problem sets: Creative Commons (CY)

Maintainer

Sebastian Kranz

Last Published

September 14th, 2018

Functions in RtutoR (2018.06.08)

RTutorPSApp

Make a problem set app suited for hosting RTutor in the web
check.problem.set

Checks a student problem set
check.file.exists

Check whether a given file exists
hint.for.assign

Default hint for an assignment
check.regression

Check whether an object from a call to lm, glm or some other regression function is correct
hint.for.call

Default hint for a call
check.function

Checks a function written by the student
run.ps

Run a problem set from a package in the browser
holds.true

Test: Does a certain condition on the stud's generated variables hold true
hypothesis.test.result

A helper function for hypothesis test about whether student solution is correct
add.hint

Add a hint to an exercise.
check.variable

Test: Check whether a variable is equal to a specified expression
add.success

Used inside tests: adds a sucess message
default.ups.save

Specify which information will be automatically saved in ups
sc

Like paste0 but returns an empty vector if some string is empty
display

Displays the given text
add.warning

Used inside tests: adds a warning
test.normality

Test: Has a vector of random numbers been drawn from a normal distribution?
check.col

Test: Compare the column col of the matrix or data.frame df with either the values from the given solutions or with the result of an expression that is evaluated in the students solution
hint.for.compute

Default hint for a compute block
parse.chunk.args

Parse the name of a knitr chunk and its arguments
awards

Show all your awards
check.expr

Test: Compare the expression check.expr evaluated in the student's environment with the solution correct.expr
print.yaml

Prints list read from a yaml file
hint.for.function

Default hint for a call
show.success.message

Simply shows a success message when this test is reached for the first time!
test.variance

Test: The variance of the distribution from which a vector of random numbers has been drawn
rtutor.observe.html.query

This function must be called in the initHandler of the app
rtutor.package.skel

Generate a package skeleton for a shiny based RTutor problem set that shall be deployed as a package
check.call

Checks whether the user makes a particular function call in his code or call a particular R statement
compare.calls

Compare if two calls are the same
create.ps

Generate a problem set from a solution file
check.assign

Checks an assignment to a variable
copy.ps.for.session

Makes a local copy of a problem set for a new shiny session
give.award

Used in a solution file. Give an award to a student who made it so far
hint

Shows a hint for the current problem.
sigma.test

Test for variance (copied from TeachingDemos)
name.rmd.chunks

Set default names for the chunks of problem set rmd files
data

Overwrite the base function data, copy data by default into the calling environment instead of the global environment
zip.solution

Create a zip file of your solution that can be submitted
zip.submit.footer.txt

Generate default footer text for a Rmd file
list.ps

Returns a list of the names of all problem sets that are included in RTutor
shinyQuiz

Create a shiny quiz widget
make.submission

Grade your problem set and make submission file
get.ps

Get the current problem set
extract.exercise.code

Extracts the stud's code of a given exercise
show.ps

Run a problem set in the webbroser (or in the viewer pane).
init.ps

Initialize a problem set for the student
old.stats

Shows your progress
stats

Shows your progress
translate.var.names

Translates variable names of a data frame
translate.var.names.in.code

Tool to translate automatically variable names in a .r or .rmd file useful to update
install.header.txt

Generate default header text for a Rmd file
read.yaml

Reads a yaml file and returns as a list
test.mean

Test: The mean of the distribution from which a vector of random numbers has been drawn
test.H0

Check whether a certain null hypothesis is not significantly rejected
test.H0.rejected

Test whether a certain H0 can be significantly rejected
rtutor.app.skel

Generate a skeleton for a shinyapps.io app of a problem set
unpack.big.zips

Takes assignment ZIPs with all students' solutions and unpacks them into separate folders for each assignment
with.random.seed

Calls a function with a specified random.seed
add.failure

Used inside tests: adds a failure to an exercise
check.call.args

Checks whether arguments of stud.call are correct given the specification in check.call
check.package

Tests whether a package is loaded. Not yet implemented for speed reasons
check.chunk

Check the student's solution of an exercise contained in stud.file