Use external datafile in `learnr` exercise

I am trying to write a learnr tutorial in which one of the exercises is to import an SPSS dataset. From the learnr documentation:

There are three ways authors can include files for use in exercises:

  1. Store the files in a data/ directory in the same directory as the
    tutorial.

  2. Use the setup chunk to download or write the files to a data/
    directory.

  3. Use the tutorial.data_dir global option or the TUTORIAL_DATA_DIR
    environment variables to specify a path to a data directory.

Following method #1 above, I have created a "data" directory within the directory that contains my .rmd file:

> list.files()
[1] "data"          "filemgmt.html" "filemgmt.Rmd" 
> 

And the directory contains a file named "frm_wide.sav":

> list.files(path="./data", pattern="frm_wide.sav")
[1] "frm_wide.sav"
> 

Now, when I run the filemgmt.Rmd, I get an error because the file is not found:

enter image description here

What I am doing wrong?

What version of learnr are you using? Most likely, you're using the CRAN version of leanr, but this feature is currently only available in the version on GitHub:

# install.packages("remotes")
remotes::install_github("rstudio/learnr")

Right you are! Installed learnr from github, it's working now.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.