Best practices for distributing/using files in learnr tutorials

What are best practices for distributing and using files with learnr tutorials?

For example, I have a file, test.csv, which I want to use to teach students about read_csv(). First, what is the best way to ensure that students have a copy of that file? Second, what is the best way to ensure that students can "see" that file for a specific exercise code chunk?

UPDATE: Not sure on the best answer. I decided to stick all such files in inst/www, following the discussion here. Then, I can refer to those files --- consider "test_1.csv" --- with code in the tutorial like:

cat(readLines(paste0(system.file("www/", package = "primer.tutorials"), 
                     "test_1.csv")), sep = "\n")

Can't say I like this, but it works.

The second use case is to put a copy of the file in the working directory of the current question. I do that with a setup chunk which looks like:

file.copy(paste0(system.file("www/", package = "primer.tutorials"), 
                 "test_1.csv"), ".")

Again, it works. But is it really the best way?

Hi, when you open the r-code in folder A and it would be better to put the dataset in folder A as well.
why? I think before you setwd() the default setting of working directory of the dataset is in the folder where the r-code is.

or another way, making the habit of setting the working directory also recommended.

This topic was automatically closed after 45 days. 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.