-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpackage_data.R
99 lines (91 loc) · 3.13 KB
/
package_data.R
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
## Script for acquiring details for packages listed in CRAN's Task Views
## Its filename starts with a dot so it's not uploaded to shinyapps.io
## Dependencies:
# install.packages(c("ctv", "tidyverse", "remotes"))
# remotes::install_github("metacran/crandb")
library(tidyverse)
library(ratelimitr)
message("Downloading CRAN Task Views...")
available_views <- ctv::available.views(repos = "https://cran.r-project.org/")
# Rename the list's elements:
names(available_views) <- available_views %>%
map(~ .$name) %>%
unlist
## For ui.R:
# cat(paste0(unlist(map(available_views, ~ .$topic)), "\" = \"", names(available_views), collapse = "\",\n\""))
## Extract package list for each view:
message("Extracting package list for each View...")
views <- available_views %>%
map(~ .$packagelist$name) %>%
map(~ data.frame(package = ., stringsAsFactors = FALSE)) %>%
bind_rows(.id = "view")
## Obtain licensing and other details for each package:
need_to_write <- FALSE
foo <- function(x) {
if (is.null(x)) {
return(NA)
} else if (x == "") {
return(NA)
} else {
return(x)
}
}
get_package_info <- limit_rate(crandb::package, rate(n = 5, period = 0.1))
if (file.exists("www/packages.csv")) {
message("Found existing data for packages...")
existing_data <- read.csv("www/packages.csv", stringsAsFactors = FALSE)
# Check if there have been any packages added to the task views that we
# do not already have details for:
missing_pkgs <- anti_join(views, existing_data, by = c("view", "package"))
if (nrow(missing_pkgs) > 0) {
message("Found packages in Task Views that are not in existing dataset...")
# Let's get those missing packages' details!
pkgs <- unique(missing_pkgs$package)
message("Acquiring licensing and other data...")
details <- map_dfr(pkgs, function(pkg) {
deets <- crandb::package(pkg)
return(tibble(
title = deets$Title,
license = foo(deets$License),
description = deets$Description,
url = foo(deets$URL),
authors = deets$Author
))
}, .id = "package")
details$package <- pkgs
packages <- missing_pkgs %>%
left_join(details, by = "package") %>%
rbind(existing_data, .) %>%
arrange(view, package)
need_to_write <- TRUE
} else {
message("No further actions need to be taken.")
}
} else {
pkgs <- unique(sort(views$package))
message("Acquiring licensing and other details for ", length(pkgs), " package(s)...")
pb <- progress::progress_bar$new(total = length(pkgs))
details <- map_dfr(pkgs, function(pkg) {
pb$tick()
deets <- crandb::package(pkg)
return(tibble(
title = deets$Title,
license = foo(deets$License),
description = deets$Description,
url = foo(deets$URL),
authors = deets$Author
))
}, .id = "package")
details$package <- pkgs
packages <- left_join(views, details, by = "package")
need_to_write <- TRUE
}
## Output:
if (need_to_write) {
message("Writing a CSV of package details...")
packages %>%
dplyr::arrange(view, package) %>%
dplyr::distinct(view, package, .keep_all = TRUE) %>%
write_csv("www/packages.csv")
}
message("Done.")