usethis (version 1.5.1)

zip-utils: Download and unpack a ZIP file

Description

Functions to download and unpack a ZIP file into a local folder of files, with very intentional default behaviour. Useful in pedagogical settings or anytime you need a large audience to download a set of files quickly and actually be able to find them.

Usage

use_course(url, destdir = NULL)

use_zip(url, destdir = getwd(), cleanup = if (interactive()) NA else FALSE)

Arguments

url

Link to a ZIP file containing the materials. Various short forms are accepted, to reduce the typing burden in live settings:

* bit.ly or rstd.io shortlinks: "bit.ly/xxx-yyy-zzz" or "rstd.io/foofy"
* GitHub repo spec: "OWNER/REPO"

Function works well with DropBox folders and GitHub repos, but should work for ZIP files generally. See examples and use_course_details for more.

destdir

The new folder is stored here. If NULL, defaults to user's Desktop or some other conspicuous place.

cleanup

Whether to delete the original ZIP file after unpacking its contents. In an interactive setting, NA leads to a menu where user can approve the deletion (or decline).

Value

Path to the new directory holding the unpacked ZIP file, invisibly.

Functions

  • use_course: Designed with live workshops in mind. Includes intentional friction to highlight the download destination. Workflow:

    • User executes, e.g., use_course("bit.ly/xxx-yyy-zzz").

    • User is asked to notice and confirm the location of the new folder. Specify destdir to prevent this.

    • User is asked if they'd like to delete the ZIP file.

    • If new folder contains an .Rproj file, a new instance of RStudio is launched. Otherwise, the folder is opened in the file manager, e.g. Finder or File Explorer.

  • use_zip: More useful in day-to-day work. Downloads in current working directory, by default, and allows cleanup behaviour to be specified.

Examples

Run this code
# NOT RUN {
# download the source of usethis from GitHub, behind a bit.ly shortlink
use_course("bit.ly/usethis-shortlink-example")
use_course("http://bit.ly/usethis-shortlink-example")

## download the source of rematch2 package, from CRAN and GitHub
use_course("https://cran.r-project.org/bin/windows/contrib/3.4/rematch2_2.0.1.zip")

## from GitHub, 3 ways
use_course("r-lib/rematch2")
use_course("https://github.com/r-lib/rematch2/archive/master.zip")
use_course("https://api.github.com/repos/r-lib/rematch2/zipball/master")
# }

Run the code above in your browser using DataLab