Skip to content

Commit

Permalink
add PR commands + dictionary check
Browse files Browse the repository at this point in the history
  • Loading branch information
tanho63 authored Dec 19, 2023
1 parent 7dfa7e0 commit 2cdf849
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 36 deletions.
131 changes: 131 additions & 0 deletions .github/workflows/pr-commands.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
issue_comment:
types: [created]

name: Commands

jobs:
document:
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/document') }}
name: document
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/pr-fetch@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::roxygen2
needs: pr-document

- name: Document
run: roxygen2::roxygenise()
shell: Rscript {0}

- name: commit
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git add man/\* NAMESPACE
git commit -m 'Document'
- uses: r-lib/actions/pr-push@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

style:
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/style') }}
name: style
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/pr-fetch@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: r-lib/actions/setup-r@v2

- name: Install dependencies
run: install.packages("styler")
shell: Rscript {0}

- name: Style
run: styler::style_pkg()
shell: Rscript {0}

- name: commit
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git add \*.R
git commit -m 'Style'
- uses: r-lib/actions/pr-push@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

rebuild-data-dictionary:
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/rebuild-dictionary') }}
name: rebuild-data-dictionary
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
NFLVERSE_GH_TOKEN: ${{ secrets.NFLVERSE_GH_TOKEN }}
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/pr-fetch@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: r-lib/actions/setup-r@v2

- uses: r-lib/actions/setup-r-dependencies@v2
with:
cache-version: 1
extra-packages: |
any::usethis
any::dplyr
any::data.table
any::tidyr
any::stringr
any::tibble
any::here
any::skimr
any::waldo
- name: Rebuild Dictionaries
run: |
Rscript data-raw/build_data_dictionaries.R
Rscript data-raw/build_teamplayer_mappings.R
shell: bash

- name: Check Dictionaries
run: |
Rscript data-raw/dictionary_check.R
shell: bash

- name: Commit
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git add data
git commit -m 'rebuild dictionaries'
- uses: r-lib/actions/pr-push@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
72 changes: 37 additions & 35 deletions data-raw/build_teamplayer_mappings.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library(nflreadr)
library(tidyverse)
library(dplyr)
library(tidyr)
library(usethis)

player_name_mapping <- read.csv("data-raw/clean_player_names.csv") |>
Expand All @@ -11,40 +12,41 @@ player_name_mapping <- read.csv("data-raw/clean_player_names.csv") |>
usethis::use_data(player_name_mapping, overwrite = TRUE)

teams <- csv_from_url("https://github.com/nflverse/nfldata/raw/master/data/teams.csv") %>%
select(team,nfl,espn,pfr,pfflabel,fo) %>%
pivot_longer(-team,names_to = NULL, values_to = "alternate") %>%
distinct() %>%
filter(alternate!="") %>%
bind_rows(
tribble(~team,~alternate,
"GB","GBP",
"KC","KCC",
"LV","LVR",
"NE","NEP",
"NO","NOS",
"LAC","SDC",
"TB","TBB",
"WAS","WFT",
"LV","OAK",
"LA","STL",
"LA","SL",
"STL","SL",
"LAC","SD",
"SD","SDC",
"AFC", "AFC",
"NFC", "NFC",
"NFL", "NFL"
)
dplyr::select(team,nfl, espn, pfr, pfflabel, fo) %>%
dplyr::pivot_longer(-team, names_to = NULL, values_to = "alternate") %>%
dplyr::distinct() %>%
dplyr::filter(alternate!="") %>%
dplyr::bind_rows(
tibble::tribble(
~team,~alternate,
"GB","GBP",
"KC","KCC",
"LV","LVR",
"NE","NEP",
"NO","NOS",
"LAC","SDC",
"TB","TBB",
"WAS","WFT",
"LV","OAK",
"LA","STL",
"LA","SL",
"STL","SL",
"LAC","SD",
"SD","SDC",
"AFC", "AFC",
"NFC", "NFC",
"NFL", "NFL"
)
) %>%
arrange(alternate)
dplyr::arrange(alternate)

team_abbr_mapping <- teams %>%
filter(!team %in% c("OAK","STL","SD")) %>%
select(alternate,team) %>%
deframe()
dplyr::filter(!team %in% c("OAK","STL","SD")) %>%
dplyr::select(alternate,team) %>%
tibble::deframe()

team_abbr_mapping_norelocate <- teams %>%
filter(
dplyr::filter(
!(team == "LV" & alternate %in% c("OAK")),
!(team == "LAC" & alternate %in% c("SD","SDG","SDC")),
!(team == "LA" & alternate %in% c("STL","SL")),
Expand All @@ -53,10 +55,10 @@ team_abbr_mapping_norelocate <- teams %>%
!(team == "OAK" & alternate %in% c("LV","LVR","RAI")),
!(team == "SD" & alternate %in% c("LAC","LACH"))
) %>%
arrange(alternate) %>%
select(alternate,team) %>%
deframe()
dplyr::arrange(alternate) %>%
dplyr::select(alternate,team) %>%
tibble::deframe()

use_data(team_abbr_mapping, overwrite = TRUE)
use_data(team_abbr_mapping_norelocate, overwrite = TRUE)
usethis::use_data(team_abbr_mapping, overwrite = TRUE)
usethis::use_data(team_abbr_mapping_norelocate, overwrite = TRUE)

5 changes: 4 additions & 1 deletion data-raw/dictionary_check.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# data dictionary checking
devtools::load_all()
library(tidyverse)
library(dplyr)
library(skimr)
library(waldo)
library(data.table)

dict_check <- function(df,dict){
actual_vars <- df |>
Expand Down

0 comments on commit 2cdf849

Please sign in to comment.