dime-r-training icon indicating copy to clipboard operation
dime-r-training copied to clipboard

Evaluate the option of using `use_course`

Open luisesanmartin opened this issue 1 year ago • 3 comments

Reference: https://www.rdocumentation.org/packages/usethis/versions/1.3.0/topics/use_course

Could potentially avoid having participants looking for file paths or using path locations

luisesanmartin avatar Apr 26 '23 16:04 luisesanmartin

Reposted from Slack for trackability: We talked about potential using usethis::use_course() to set up the R environment for students. I can work up a proposal for this specific course, but wanted to share what I do for the SAIS course and see if people think this’ll work/have suggestions about it:

In the slides (to which the students have access through a link), I initially ask them to do the following:

  • Open RStudio.
  • Type in the following lines, replacing “YOURFILEPATHHERE” with a file path where these files will be saved.
    • For MacBook users, this could be “/Users/marc-andreafiorina/Desktop/”
    • For Windows users, this could be “C:/Users/marc-andreafiorina/Desktop/”
install.packages("usethis")
library(usethis)
usethis::use_course(
    "https://github.com/mfiorina/sais_r_course/archive/main.zip",
    destdir = "YOURFILEPATHHERE"
)

The use_course() function downloads the GitHub repo as a folder within the destination directory provided by the student, then asks them through interaction (type in “1” for yes, “2" for no into the console) whether they want to delete the .zip file, and then opens up a new RStudio environment with the correct .Rproj file already set up. In my course, the data is too big to be included in this step, so in the initial script I provide for the students to work through, they download the data into the project using the following code:

# This is session 1 so we're going to import the data from Dropbox:
  
  if(!(file.exists("data/final/wvs_values_norms_data.csv"))) { # Checks whether the data has been downloaded already
      usethis::use_zip(
          "https://www.dropbox.com/scl/fo/vnxjbqyq1g9z368coh1vq/h?rlkey=zc66o2ll7613b5e9ipp915ynk&dl=1"
      )
  }

The folder is called “data” so it effectively creates a “data” folder within their project with the correct data. We don’t have to do this if the data is loaded initially with the GitHub repo, which I think we want to do.

So for this course we could do the same instead of asking students to create their own .Rproj file. The benefit is consistency (it really really cut down on time I spent helping students set up), a possible drawback is that the students may not be as comfortable setting up their own RStudio environment outside of the course. I think it’s worth it as long as we also show them how to do it themselves initially, which is what I now do during the SAIS course.

mfiorina avatar Feb 23 '24 15:02 mfiorina

Suggested use for this course: Screen Shot 2024-02-23 at 10 42 24 AM

mfiorina avatar Feb 23 '24 15:02 mfiorina

Note after first attempt to use during course: I've discovered an option to automatically delete the .zip file. For some reason it isn't available for usethis::use_course(), but it is available for usethis::use_zip(), which does exactly the same thing.

The code would look like:

usethis::use_zip(
    "https://github.com/worldbank/dime-r-training/archive/main.zip",
    destdir = "FILEPATHHERE", cleanup = TRUE
)

mfiorina avatar Mar 06 '24 16:03 mfiorina