Skip to content

Instantly share code, notes, and snippets.

@beatrizmilz
Created February 21, 2022 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beatrizmilz/55f6bea74c245e4ceec7802dca79aed0 to your computer and use it in GitHub Desktop.
Save beatrizmilz/55f6bea74c245e4ceec7802dca79aed0 to your computer and use it in GitHub Desktop.
Função para fazer download de um Gist
list_user_gists <- function(user){
gists <- gh::gh("GET /users/{username}/gists",
username = user)
gists_df <- gists |>
purrr::map(unlist, recursive = TRUE) |>
purrr::map_dfr(tibble::enframe, .id = "id_gist") |>
tidyr::pivot_wider(id_cols = "id_gist") |>
janitor::clean_names() |>
dplyr::select(id,
url,
public,
created_at,
updated_at,
description,
owner_login)
gists_df
}
get_gist <- function(id_gist, path = "./"){
fs::dir_create(path)
gist <- gh::gh("GET /gists/{gist_id}",
gist_id = id_gist)
gist_content <- gist$files
name_file <- gist_content[[1]]$filename
path_file <- paste0(path, name_file)
content_file <- gist_content[[1]]$content
readr::write_lines(content_file, name_file)
rstudioapi::navigateToFile(path_file)
}
# Buscar gists da Beatriz
gists_bm <- list_user_gists("beatrizmilz")
dplyr::glimpse(gists_bm)
# > dplyr::glimpse(gists_bm)
# Rows: 8
# Columns: 7
# $ id <chr> "85686d5a4adb89f240b108edf556ece6", "69906dadb5093d…
# $ url <chr> "https://api.github.com/gists/85686d5a4adb89f240b10…
# $ public <chr> "TRUE", "TRUE", "FALSE", "TRUE", "TRUE", "TRUE", "T…
# $ created_at <chr> "2022-01-20T17:01:58Z", "2021-12-08T12:40:48Z", "20…
# $ updated_at <chr> "2022-01-20T17:02:12Z", "2021-12-08T12:42:36Z", "20…
# $ description <chr> "", "Código em R para buscar vídeos de um canal na …
# $ owner_login <chr> "beatrizmilz", "beatrizmilz", "beatrizmilz", "beatr…
# Buscar um gist da Beatriz por ID
# subset de um id
id_de_um_gist <- gists_bm |> dplyr::slice(1) |> dplyr::pull(1)
id_de_um_gist
# buscar o gist pelo ID
gist <- get_gist(id_de_um_gist )
# o arquivo será baixado e aberto no RStudio....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment