-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreatr.R
47 lines (45 loc) · 973 Bytes
/
creatr.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
library(rvest)
create_R <- function(
url
){
page <- read_html(url)
titre <- page %>%
html_node("h1") %>%
html_text()
file_name <- gsub(".*\\/(w3css_[^.]*)\\.asp", "\\1", url)
pth <- fs::path(
"R",
file_name,
ext = "R"
)
fs::file_create(pth)
write_there <- function(x){
write(sprintf("#' %s", x), file = pth, append = TRUE)
}
write_there(titre)
write_there(" ")
write_there(
sprintf(
"Implementation of %s, as described in",
titre
)
)
write_there(sprintf(
"[%s](%s).", url, url
))
write_there(" ")
write_there("@return")
write_there("@export")
write_there(" ")
write_there("@examples")
write_there(" ")
write_there("TODO")
cli::cat_rule("done")
}
page <- read_html('https://www.w3schools.com/w3css/')
urls <- page %>%
html_nodes("a") %>%
html_attr("href") %>%
grep("^w3css_", ., value = TRUE) %>%
paste0("https://www.w3schools.com/w3css/", .)
purrr::map(urls, create_R)