Search code examples
rmoodler-exams

How to include an external file in a Moodle question with R/exams?


In order to include statistical tables when using R-exams, I know that one can just use the option pages inside the function exams2nops(). But when using exams2moodle() how should one proceed?

In Moodle one can upload a file within a question and add a link to the embedded file. Is it possible to do it through R exams?


Solution

  • You can easily include various kinds of supplementary files in R/exams and then export them to Moodle or other learning management systems. Two steps need to be taken:

    1. While processing the .Rmd or .Rnw exercise the supplementary file(s) need to be created in the current working directory (which is a temporary directory by default). This can either be done be creating the file via some R code or by copying an existing file. The convenience function include_supplement() simplifies this.
    2. The supplementary file then needs to be included as a link in the question text. In .Rmd this would be something like [myfile.pdf](myfile.pdf) and in .Rnw exercises \url{myfile.pdf}.

    An example for such an inclusion is the lm exercise template shipped along with the package, see: http://www.R-exams.org/templates/lm/. This exercise creates a .csv file on the fly within R and then includes it.

    An example for the include_supplement() function is available in the Rlogo exercise template that copies the R logo image from the R system and then includes it in the exercise. See: http://www.R-exams.org/templates/Rlogo/.

    Final comment: For a distribution table it would also be possible to include this directly as an HTML table in Moodle. For example, you could generate suitable Markdown or LaTeX code within the R code of the exercise.