Skip to content

Commit

Permalink
pkgdown.yaml and R-CMD-check.yaml scripts are commented out
Browse files Browse the repository at this point in the history
  • Loading branch information
aminuldu07 committed Oct 3, 2024
1 parent c8fd12e commit 328ff88
Show file tree
Hide file tree
Showing 8 changed files with 839 additions and 102 deletions.
98 changes: 49 additions & 49 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
# 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: [test1-09302024-11.48AM]
pull_request:
branches: [test1-09302024-11.48AM]

name: R-CMD-check.yaml

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

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

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
# on:
# push:
# branches: [test1-09302024-11.48AM]
# pull_request:
# branches: [test1-09302024-11.48AM]
#
# name: R-CMD-check.yaml
#
# permissions: read-all
#
# jobs:
# R-CMD-check:
# runs-on: ${{ matrix.config.os }}
#
# name: ${{ matrix.config.os }} (${{ matrix.config.r }})
#
# strategy:
# fail-fast: false
# matrix:
# config:
# - {os: macos-latest, r: 'release'}
# - {os: windows-latest, r: 'release'}
# - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
# - {os: ubuntu-latest, r: 'release'}
# - {os: ubuntu-latest, r: 'oldrel-1'}
#
# env:
# GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
# R_KEEP_PKG_SOURCE: yes
#
# steps:
# - uses: actions/checkout@v4
#
# - uses: r-lib/actions/setup-pandoc@v2
#
# - uses: r-lib/actions/setup-r@v2
# with:
# r-version: ${{ matrix.config.r }}
# http-user-agent: ${{ matrix.config.http-user-agent }}
# use-public-rspm: true
#
# - uses: r-lib/actions/setup-r-dependencies@v2
# with:
# extra-packages: any::rcmdcheck
#
# - uses: r-lib/actions/check-r-package@v2
# with:
# upload-snapshots: true
# build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'

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

name: pkgdown.yaml

permissions: read-all

jobs:
pkgdown:
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@v4

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

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

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
# on:
# push:
# branches: [main, master]
# pull_request:
# branches: [main, master]
# release:
# types: [published]
# workflow_dispatch:
#
# name: pkgdown.yaml
#
# permissions: read-all
#
# jobs:
# pkgdown:
# 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@v4
#
# - uses: r-lib/actions/setup-pandoc@v2
#
# - uses: r-lib/actions/setup-r@v2
# with:
# use-public-rspm: true
#
# - uses: r-lib/actions/setup-r-dependencies@v2
# with:
# extra-packages: any::pkgdown, local::.
# needs: website
#
# - name: Build site
# run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
# shell: Rscript {0}
#
# - name: Deploy to GitHub pages 🚀
# if: github.event_name != 'pull_request'
# uses: JamesIves/[email protected]
# with:
# clean: false
# branch: gh-pages
# folder: docs
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ Imports:
tidyr,
ggplot2,
matrixStats,
haven
haven,
tree,
plotrix
Suggests:
knitr,
rmarkdown,
Expand Down
70 changes: 70 additions & 0 deletions R/ReprTree.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#' Representative trees from ensembles
#'
#' This package implements the concept of representative trees from ensemble
#' tree-based learners introduced by Banerjee, et al, (2012). Representative trees
#' are, in some sense, trees in the ensemble which are on average the "closest" to
#' all the other trees in the ensemble. Several trees can be representative of the
#' ensemble in general. This package currently implements the d2 metric of tree closeness
#' (close in prediction) from Banerjee, et al.
#'
#' @name reprtree-package
#' @references M. Banerjee, Y. Ding and A-M Noone (2012) "Identifying representative
#' trees from ensembles". Statistics in Medicine, 31(15):1601-1616.
#' @import randomForest tree
#' @docType package
#' @name reprtree
#' @examples
#' library(reprtree)
#' rforest <- randomForest(Species~., data=iris)
#' reptree <- ReprTree(rforest, iris, metric='d2')
#' plot(reptree, index=1)
NULL


#' Identifying and extracting representative trees from a random forest
#'
#' This function takes a random forest object and data to run predictions on
#' and identifies representative trees based on the d0, d1 or d2 metric defined
#' in Banerjee, et al (2012). Currently only the d2 metric is implemented, using
#' either a euclidean distance (for numeric predictions) or a mismatch distance
#' (for categorical predictions). The average distance D(T) of each tree in the
#' set of trees in computed, and trees with the lowest D(T) value are extracted
#' and formatted to be compatible with the \code{\link{tree}} class. Trees can then
#' be visualized using \code{plot.tree} and \code{text.tree}, or using a custom
#' plot function (to be defined)
#'
#' @param rforest A randomForest object
#' @param newdata The data on which predictions will be computed
#' @param metric The metric to be used to evaluate distance between trees. Currently
#' only the d2 metric is implemented
#' @return A list object containing representations of the representative trees
#' conformable with the \code{tree} class. Names of the list give the indices
#' of the representative trees in the set of trees.
#' @import randomForest tree
#' @export
#' @references M. Banerjee, Y. Ding and A-M Noone (2012) "Identifying representative
#' trees from ensembles". Statistics in Medicine, 31(15):1601-1616.
#' @examples
#' library(randomForest)
#' library(tree)
#' rforest <- randomForest(Species~., data=iris)
#' reptree <- ReprTree(rforest, iris, metric='d2')
ReprTree <- function(rforest, newdata, metric='d2'){
if(metric!='d2') stop('invalid metric!')
require(randomForest)
print('Constructing distance matrix...')
preds <- predict2(rforest, newdata=newdata, predict.all=T)
preds.indiv <- preds$individual
d <- dist.fn(t(preds.indiv), method=ifelse(rforest$type=='classification',
'mismatch',
'euclidean'))
print('Finding representative trees...')
D <- colMeans(d)
index <- which(D==min(D))
trees <- lapply(as.list(index), function(i) getTree(rforest, i, labelVar=TRUE))
names(trees) <- as.character(index)
trees <- lapply(trees, as.tree, rforest)
out <- list(trees=trees,D = D)
class(out) <- c('reprtree','list')
return(out)
}
Loading

0 comments on commit 328ff88

Please sign in to comment.