zip-utils: Download and unpack a ZIP file

Description Usage Arguments Value Functions Examples

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. The underlying helpers are documented in use_course_details.

Usage

1
2
3
4
5
6
7
use_course(url, destdir = getOption("usethis.destdir"))

use_zip(
  url,
  destdir = getwd(),
  cleanup = if (rlang::is_interactive()) NA else FALSE
)

Arguments

url

Link to a ZIP file containing the materials. To reduce the chance of typos in live settings, these shorter forms are accepted:

* GitHub repo spec: "OWNER/REPO". Equivalent to
  `https://github.com/OWNER/REPO/DEFAULT_BRANCH.zip`.
* bit.ly or rstd.io shortlinks: "bit.ly/xxx-yyy-zzz" or "rstd.io/foofy".
  The instructor must then arrange for the shortlink to point to a valid
  download URL for the target ZIP file. The helper
  [create_download_url()] helps to create such URLs for GitHub, DropBox,
  and Google Drive.
destdir

The new folder is stored here. If NULL, defaults to user's Desktop or some other conspicuous place. You can also set a default location using the option usethis.destdir, e.g. options(usethis.destdir = "a/good/dir"), perhaps saved to your .Rprofile with edit_r_profile()

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## 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
use_course("https://cran.r-project.org/bin/windows/contrib/3.4/rematch2_2.0.1.zip")

# download the source of rematch2 package from GitHub, 4 ways
use_course("r-lib/rematch2")
use_course("https://api.github.com/repos/r-lib/rematch2/zipball/HEAD")
use_course("https://api.github.com/repos/r-lib/rematch2/zipball/master")
use_course("https://github.com/r-lib/rematch2/archive/master.zip")

## End(Not run)

usethis documentation built on Oct. 17, 2021, 1:06 a.m.