Upgrade to Pro — share decks privately, control downloads, hide ads and more …

R で Github Repository をきれいにする

Hiroyuki Kuromiya
October 07, 2023
510

R で Github Repository をきれいにする

第109回R勉強会@東京(#TokyoR)
発表資料

Hiroyuki Kuromiya

October 07, 2023
Tweet

Transcript

  1. Rとのかかわり 主に論文を書くときに使っていた(データ分析、図の作成) 特に統計の専門家というわけではなく、標準的な?Rユーザ 割合は Python : R = 1:1 くらい

    アプリに組み込むときは Python だけど、単発の分析ならRみたいな感じ 博士号をとれたのもRのおかげと言っても過言ではない
  2. Github CLI を使って数えてみる % gh repo list --limit 100 |

    wc -l 72 --limit option をつけないとデフォルトで30個までしかとってこないので注意
  3. 2. Github CLIでレポジトリの削除 gh コマンドでレポジトリの削除ができる gh alias set repo-delete 'api

    -X DELETE "repos/$1"' gh repo-delete vilmibm/deleteme How to delete a repo using gh cli · Issue #2461 · cli/cli → でもこれだけ多いと手動でレポジトリをリストアップするのも大変 使っていないレポジトリを更新日時順とかでソート/フィルタリングしてほしい
  4. 3. Open Interpreter 最近流行りの自動コーディングツール % interpreter --fast Prompt: **Sort the

    github repository by last update date using gh command.** To sort the GitHub repositories by the last update date, we can use the gh command with the --sort option. The updated field can be used to sort the repositories by the date of the last update. Let's execute this command. gh repo list --limit 100 --sort updated
  5. 結果 I apologize for the confusion. It seems that the

    gh repo list command does not upport the --sort option. However, we can achieve the same result by using the gh api command to interact with the GitHub API directly. This will allow us to sort the repositories by the last update date. gh api コマンドを使えばできるっぽいがあまり複雑なシェルコマンドを打ちたくない(情 弱) → じゃあどうするか → 僕たちには R があるじゃないか
  6. 3. 元記事の方法だと private repository が取れないので これを使う my_repos = gh("GET /user/repos",

    visibility = "all", affiliation = "owner", before = "2022-12-01T", sort = "updated", page = 1, per_page = 100) これでレポジトリの更新日時でフィルタリングしたりソートしたりできる (dplyr::filter とか使う必要もなかった) 参考 Repositories - GitHub Docs
  7. 4. レポジトリを更新日時でフィルタリングして削除 # list of list から dataframe に変換 targeted_repos

    = purrr::map_dfr(my_repos, ~unlist(.x["name"])) repos_to_delete = targeted_repos$name # 削除するレポジトリを手動で調整 excluded_repos = c("important repo") to_delete = setdiff(repos_to_delete, excluded_repos) # レポジトリを削除 purrr::map(to_delete, ~gh("DELETE /repos/:owner/:repo", owner = my_username, repo = .x))