Skip to content

Commit

Permalink
type: <fix> message: <minor fixes>
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmoy28 committed Oct 25, 2023
1 parent 15a94c3 commit db03816
Show file tree
Hide file tree
Showing 15 changed files with 196 additions and 126 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
Expand All @@ -29,7 +29,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

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

Expand Down
62 changes: 31 additions & 31 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
# 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:
push:
branches:
- main
- master
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
runs-on: macOS-latest
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

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

- uses: r-lib/actions/setup-pandoc@v1

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Restore R package cache
uses: actions/cache@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
extra-packages: any::pkgdown, local::.
needs: website

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
install.packages("pkgdown", type = "binary")
- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Install package
run: R CMD INSTALL .

- name: Deploy package
run: |
git config --local user.email "actions@github.com"
git config --local user.name "GitHub Actions"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'
- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.4.1
with:
clean: false
branch: gh-pages
folder: docs
79 changes: 79 additions & 0 deletions .github/workflows/pr-commands.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# 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 "$GITHUB_ACTOR@users.noreply.github.com"
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 "$GITHUB_ACTOR@users.noreply.github.com"
git add \*.R
git commit -m 'Style'
- uses: r-lib/actions/pr-push@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
60 changes: 31 additions & 29 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
# 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:
push:
branches:
- main
- master
branches: [main, master]
pull_request:
branches:
- main
- master
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: macOS-latest
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

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

- uses: r-lib/actions/setup-pandoc@v1
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Query dependencies
- name: Test coverage
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
)
shell: Rscript {0}

- name: Restore R package cache
uses: actions/cache@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install dependencies
- name: Show testthat output
if: always()
run: |
install.packages(c("remotes"))
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("covr")
shell: Rscript {0}
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Test coverage
run: covr::codecov(type = 'all')
shell: Rscript {0}
- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
6 changes: 3 additions & 3 deletions R/center_mlm.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' @export
#'
#' @examples
#' center_mlm(iris,ends_with('Length',group = 'Species')
#' center_mlm(iris,dplyr::ends_with('Length'),group = 'Species')
#'
center_mlm = function(data,cols,group,keep_original = TRUE){
data_names = names(data)
Expand All @@ -20,7 +20,7 @@ center_mlm = function(data,cols,group,keep_original = TRUE){
group_name = data %>% dplyr::select(!!enquo(group)) %>% names()

mean_data = data %>%
dplyr::group_by(across(!!group)) %>%
dplyr::group_by(dplyr::across(!!group)) %>%
dplyr::summarise(dplyr::across(!!cols,~mean(.,na.rm = T))) %>%
dplyr::mutate(dplyr::across(!!cols, function(x) { (x - mean(x,na.rm = TRUE))})) %>%
dplyr::ungroup() %>%
Expand All @@ -37,7 +37,7 @@ center_mlm = function(data,cols,group,keep_original = TRUE){
}

return_data = dplyr::full_join(centered_data,mean_data,by = group_name) %>%
dplyr::select(c(all_of(data_names),dplyr::ends_with('group_c'),dplyr::ends_with('_mean'),dplyr::everything()))
dplyr::select(c(dplyr::all_of(data_names),dplyr::ends_with('group_c'),dplyr::ends_with('_mean'),dplyr::everything()))


return(return_data)
Expand Down
27 changes: 8 additions & 19 deletions R/dummy_coding.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,21 @@
#' @export
#'
#' @examples
#' effect_coding(iris,Species)
#' Dummy Coding
#'
#' @param data data.frame object
#' @param cols vector or tidyselect syntax or helpers. column(s) that need to be re-coded
#'
#' @return
#' return a data.frame with factors being effect coded
#' @export
#'
#' @examples
#' dummy_coding(iris,Species)
#'
dummy_coding <- function(data,cols) {
cols_names = data %>% select(!!enquo(cols)) %>% names()
cols_names = data %>%dplyr::select(!!enquo(cols)) %>% names()
return_df = data
for (group in cols_names) {
group_name = data %>% select(!!enquo(group)) %>% names()
distinct_group = data %>% distinct(across(!!enquo(group))) %>% pull(.) %>% as.character()
distinct_group_num = data %>% distinct(across(!!enquo(group))) %>% nrow()
contrasts_df = data.frame(contr.treatment(distinct_group_num,base = distinct_group_num))
group_name = data %>%dplyr::select(!!enquo(group)) %>% names()
distinct_group = data %>% dplyr::distinct(dplyr::across(!!enquo(group))) %>%dplyr::pull(.) %>% as.character()
distinct_group_num = data %>% dplyr::distinct(dplyr::across(!!enquo(group))) %>% nrow()
contrasts_df = data.frame(stats::contr.treatment(distinct_group_num,base = distinct_group_num))
colnames(contrasts_df) = paste0(group_name,'_',distinct_group[1:nrow(contrasts_df)-1],'_dum')
dummy_coded_df = contrasts_df %>%
mutate(group = distinct_group) %>%
rename(!!enquo(group):=group)
return_df = full_join(return_df,dummy_coded_df)
dplyr::mutate(group = distinct_group) %>%
dplyr::rename(!!enquo(group):=group)
return_df =dplyr::full_join(return_df,dummy_coded_df)
}
return(return_df)
}
Expand Down
17 changes: 9 additions & 8 deletions R/effect_coding.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#'
#' @examples
#' effect_coding(iris,Species)
#'
effect_coding = function(data,cols,factor = TRUE){
if (factor == TRUE) {
names = data %>% dplyr::select(!!enquo(cols)) %>% colnames(.)
Expand All @@ -18,18 +19,18 @@ effect_coding = function(data,cols,factor = TRUE){
}
return(return_df)
} else if(factor == FALSE){
cols_names = data %>% select(!!enquo(cols)) %>% names()
cols_names = data %>%dplyr::select(!!enquo(cols)) %>% names()
return_df = data
for (group in cols_names) {
group_name = data %>% select(!!enquo(group)) %>% names()
distinct_group = data %>% distinct(across(!!enquo(group))) %>% pull(.) %>% as.character()
distinct_group_num = data %>% distinct(across(!!enquo(group))) %>% nrow()
contrasts_df = data.frame(contr.sum(distinct_group_num))
group_name = data %>% dplyr::select(!!enquo(group)) %>% names()
distinct_group = data %>% dplyr::distinct(dplyr::across(!!enquo(group))) %>%dplyr::pull(.) %>% as.character()
distinct_group_num = data %>% dplyr::distinct(dplyr::across(!!enquo(group))) %>% nrow()
contrasts_df = data.frame(stats::contr.sum(distinct_group_num))
colnames(contrasts_df) = paste0(group_name,'_',distinct_group[1:nrow(contrasts_df)-1],'_eff')
dummy_coded_df = contrasts_df %>%
mutate(group = distinct_group) %>%
rename(!!enquo(group):=group)
return_df = full_join(return_df,dummy_coded_df)
dplyr::mutate(group = distinct_group) %>%
dplyr::rename(!!enquo(group):=group)
return_df =dplyr::full_join(return_df,dummy_coded_df)
}
return(return_df)

Expand Down

0 comments on commit db03816

Please sign in to comment.