File size: 713 Bytes
f2584cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# build the repository list

path <- "repos.json"

if (!fs::file_exists(path)) {
  repos <- gh::gh(
    "GET https://api.github.com/orgs/CRAN/repos",
    .limit = Inf,
    .progress = TRUE
  )
  jsonlite::write_json(repos, path)
} else {
  repos <- jsonlite::read_json(path)
}


fs::dir_create("CRAN")

download_repo <- purrr::insistently(function(repo) {
  repo_name <- as.character(repo$name)

  dest <- glue::glue("CRAN/{repo_name}.zip")
  if (fs::file_exists(dest)) {
    return()
  }

  gh::gh(
    "GET /repos/cran/{repo_name}/zipball",
    repo_name = repo_name,
    .destfile = dest
  )
})

library(future)
plan(multisession, workers = 6)
furrr::future_map(
  repos,
  download_repo,
  .progress = TRUE
)