Problem Description
I'm writing questions for an online test (held through Moodle) using R's `exams` package. Some of these questions include CSV files that students need to read into R and analyse.
It'd be great if students could read their data into R simply using `read.csv(URL for the Moodle plug-in file)`, rather than having to read it in by downloading the data set by clicking the link to it within the question, saving it to a working directory, and then reading it into R from where they saved it.
Below is a MWE where I try to create a question where students could read a CSV file into R in the desired way.
````
#rmd file contents
```{r gen data, echo=FALSE, results='hide'}
x<-rnorm(20)
df<-data.frame(x)
write.csv(df,"dataset.csv",row.names=F)
```
Question
======
Downloading data set using URL: `read.csv("dataset.csv")`
Downloading via link: [click this link](dataset.csv)
Just adding a dummy question: Enter the number 1 ##ANSWER1##
Meta-information
================
extype: cloze
exclozetype: num
exsolution: 1
extitle: Testing dataset download using URL
exsection: Testing dataset download using URL
````
The screenshot below shows how the resulting question looks when exported into Moodle:
[![Data Set Question MWE][1]][1]
When one tries to read the CSV file into R by reading directly from the plug-in file URL (e.g. by entering `read.csv("https://moodlestack.otago.ac.nz/pluginfile.php/2497/question/questiontext/21614/1/129512/dataset.csv")`, in this example), what's read into R is HTML code (I think the instructions for downloading the file when a link to it is clicked). I've included below the first few lines of it.
[![CSV HTML][2]][2]
What we're obviously wanting is for only the CSV file data to be read in after entering `read.csv(URL)`. Is this going to be possible?
P.S. The reason for wanting this is that many of our 100-level students find the steps involved in reading a file into R to be difficult (most of our students have very limited quantitative and computer skills). We make them read files in the standard way in our assignments, but in the test where there's a higher grade, it'd be good if they didn't lose many the marks simply from not being able to read a file in (or being unable to fix errors that arise when doing so).
[1]: https://i.sstatic.net/HX0d0iOy.png
[2]: https://i.sstatic.net/fzzdJ4P6.png
AI-Generated Solution
Powered by LMSouq AI · GPT-4.1-mini
Analyzing problem and generating solution…
Was this solution helpful?