Skip to content

Instantly share code, notes, and snippets.

@jthomasmock
Created February 26, 2023 17:20

Revisions

  1. jthomasmock revised this gist Feb 26, 2023. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions unique-categories.R
    Original file line number Diff line number Diff line change
    @@ -20,3 +20,5 @@ all_tags[all_tags != "All"] |>
    ```

    # Gist URL https://gist.github.com/10e217dab119bccb7df8d6d0aa483dab

    # Code image at: ![](https://i.imgur.com/jAQJlNS.png)
  2. jthomasmock revised this gist Feb 26, 2023. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion unique-categories.R
    Original file line number Diff line number Diff line change
    @@ -17,4 +17,6 @@ all_tags <- sapply(seq_len(length_tags), function(x){

    all_tags[all_tags != "All"] |>
    write_lines(here::here("_data/unique_categories.txt"))
    ```
    ```

    # Gist URL https://gist.github.com/10e217dab119bccb7df8d6d0aa483dab
  3. jthomasmock created this gist Feb 26, 2023.
    20 changes: 20 additions & 0 deletions unique-categories.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    ```{r write-tags}
    #| echo: false

    library(rvest)
    library(xml2)

    raw_html <- read_html(here::here("_site/index.html"))

    length_tags <- raw_html |>
    html_nodes("#quarto-margin-sidebar > div > div") |>
    length()

    all_tags <- sapply(seq_len(length_tags), function(x){
    html_nodes(raw_html, xpath = glue::glue('//*[@id="quarto-margin-sidebar"]/div/div[{x}]/text()')) |>
    html_text(trim = TRUE)
    })

    all_tags[all_tags != "All"] |>
    write_lines(here::here("_data/unique_categories.txt"))
    ```