Skip to content

Commit

Permalink
Merge pull request #87 from jasenfinch/devel
Browse files Browse the repository at this point in the history
v0.14.10
  • Loading branch information
jasenfinch committed Feb 1, 2022
2 parents 80181f5 + e082d1c commit 5b3a032
Show file tree
Hide file tree
Showing 303 changed files with 592 additions and 29,307 deletions.
26 changes: 2 additions & 24 deletions .github/workflows/R-CMD-check.yaml
Expand Up @@ -22,7 +22,7 @@ jobs:
- {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'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -43,26 +43,4 @@ jobs:
with:
extra-packages: rcmdcheck

- name: Check
env:
_R_CHECK_CRAN_INCOMING_: false
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Test coverage
run: covr::codecov()
shell: Rscript {0}

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
- uses: r-lib/actions/check-r-package@v1
35 changes: 35 additions & 0 deletions .github/workflows/pkgdown.yaml
@@ -0,0 +1,35 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2

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

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

- uses: r-lib/actions/setup-r-dependencies@v1
with:
extra-packages: pkgdown
needs: website

- name: Deploy package
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'
30 changes: 30 additions & 0 deletions .github/workflows/test-coverage.yaml
@@ -0,0 +1,30 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/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]

name: test-coverage

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

steps:
- uses: actions/checkout@v2

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

- uses: r-lib/actions/setup-r-dependencies@v1
with:
extra-packages: covr

- name: Test coverage
run: covr::codecov()
shell: Rscript {0}
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@ doc
Meta
/doc/
/Meta/
docs
4 changes: 3 additions & 1 deletion DESCRIPTION
@@ -1,6 +1,6 @@
Package: metabolyseR
Title: Methods for Pre-Treatment, Data Mining and Correlation Analyses of Metabolomics Data
Version: 0.14.9
Version: 0.14.10
Authors@R: person("Jasen", "Finch", email = "jsf9@aber.ac.uk", role = c("aut", "cre"))
Description: A tool kit for pre-treatment, modelling, feature selection and correlation analyses of metabolomics data.
URL: https://jasenfinch.github.io/metabolyseR
Expand Down Expand Up @@ -76,6 +76,7 @@ Collate: allClasses.R
plotting.R
plotUnsupervisedRF.R
pre-treatment.R
predict.R
QC.R
reexports.R
remove.R
Expand All @@ -85,6 +86,7 @@ Collate: allClasses.R
show-method.R
split.R
transform.R
tune.R
univariate.R
modelling-accessors.R
VignetteBuilder: knitr
Expand Down
8 changes: 8 additions & 0 deletions NAMESPACE
Expand Up @@ -48,6 +48,7 @@ export(metabolyse)
export(metrics)
export(modellingMethods)
export(modellingParameters)
export(mtry)
export(nFeatures)
export(nSamples)
export(occupancy)
Expand All @@ -73,6 +74,7 @@ export(preTreated)
export(preTreatmentElements)
export(preTreatmentMethods)
export(preTreatmentParameters)
export(predict)
export(proximity)
export(randomForest)
export(raw)
Expand All @@ -97,6 +99,7 @@ export(transformSQRT)
export(transformTICnorm)
export(transformVast)
export(ttest)
export(tune)
export(type)
exportClasses(Analysis)
exportClasses(AnalysisData)
Expand Down Expand Up @@ -137,6 +140,7 @@ importFrom(dplyr,mutate_if)
importFrom(dplyr,n)
importFrom(dplyr,relocate)
importFrom(dplyr,rename)
importFrom(dplyr,rename_with)
importFrom(dplyr,rowwise)
importFrom(dplyr,select)
importFrom(dplyr,select_if)
Expand All @@ -147,6 +151,7 @@ importFrom(e1071,naiveBayes)
importFrom(forestControl,fpr_fs)
importFrom(furrr,furrr_options)
importFrom(furrr,future_map)
importFrom(furrr,future_map2)
importFrom(future,plan)
importFrom(ggdendro,dendro_data)
importFrom(ggplot2,aes)
Expand Down Expand Up @@ -210,6 +215,7 @@ importFrom(patchwork,wrap_plots)
importFrom(purrr,map)
importFrom(purrr,map_chr)
importFrom(purrr,map_dbl)
importFrom(purrr,map_depth)
importFrom(purrr,map_df)
importFrom(purrr,map_lgl)
importFrom(purrr,walk)
Expand All @@ -231,6 +237,7 @@ importFrom(stats,runif)
importFrom(stats,sd)
importFrom(stringr,str_c)
importFrom(stringr,str_extract)
importFrom(stringr,str_remove)
importFrom(stringr,str_remove_all)
importFrom(stringr,str_replace_all)
importFrom(stringr,str_split)
Expand All @@ -241,6 +248,7 @@ importFrom(tibble,deframe)
importFrom(tibble,rowid_to_column)
importFrom(tibble,tibble)
importFrom(tidyr,drop_na)
importFrom(tidyr,expand_grid)
importFrom(tidyr,gather)
importFrom(tidyr,spread)
importFrom(tidyselect,all_of)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
@@ -1,3 +1,11 @@
# metabolyseR 0.14.10

* Added the method [`predict()`](https://jasenfinch.github.io/metabolyseR/reference/predict.html) for the [`RandomForest`](https://jasenfinch.github.io/metabolyseR/reference/RandomForest-class.html) S4 class to predict model response values.

* Added the method [`mtry()`](https://jasenfinch.github.io/metabolyseR/reference/modelling-accessors.html) for the [`AnalysisData`](https://jasenfinch.github.io/metabolyseR/reference/AnalysisData-class.html) S4 class to return the default `mtry` random forest parameter for a given response variable.

* Added the method [`tune()`]() for the [`AnalysisData`](https://jasenfinch.github.io/metabolyseR/reference/tune.html) S4 class to tune the random forest parameters `mtry` and `ntree` for a given response variable.

# metabolyseR 0.14.9

* Suppressed name repair console message encountered during random forest permutation testing.
Expand Down
40 changes: 39 additions & 1 deletion R/modelling-accessors.R
Expand Up @@ -9,6 +9,7 @@
#' @param ... arguments to parse to method for specific class
#' @section Methods:
#' * `binaryComparisons`: Return a vector of all possible binary comparisons for a given sample information column.
#' * `mtry`: Return the default `mtry` random forest parameter value for a given sample information column.
#' * `type`: Return the type of random forest analysis.
#' * `response`: Return the response variable name used for a random forest analysis.
#' * `metrics`: Retrieve the model performance metrics for a random forest analysis
Expand All @@ -21,9 +22,12 @@
#'
#' d <- analysisData(abr1$neg[,200:300],abr1$fact)
#'
#' ## Return possible binary comparisons for the 'day' column
#' ## Return possible binary comparisons for the `day` response column
#' binaryComparisons(d,cls = 'day')
#'
#' ## Return the default random forest `mtry` parameter for the `day` response column
#' mtry(d,cls = 'day')
#'
#' ## Perform random forest analysis
#' rf_analysis <- randomForest(d,cls = 'day')
#'
Expand Down Expand Up @@ -70,6 +74,40 @@ setMethod('binaryComparisons',signature = 'AnalysisData',
#' @rdname modelling-accessors
#' @export

setGeneric("mtry", function(x,cls = 'class')
standardGeneric("mtry"))

#' @rdname modelling-accessors

setMethod('mtry',signature = 'AnalysisData',
function(x,cls = 'class'){

if (is.null(cls)){
rf_type <- 'classification'
} else {
response <- x %>%
clsExtract(cls = cls)

rf_type <- ifelse(is.numeric(response),
'regression',
'classification')
}

n_features <- nFeatures(x)

mtry <- switch(rf_type,
regression = n_features/3,
classification = sqrt(n_features)) %>%
floor() %>%
c(.,1) %>%
max()

return(mtry)
})

#' @rdname modelling-accessors
#' @export

setGeneric("type", function(x)
standardGeneric("type"))

Expand Down
4 changes: 2 additions & 2 deletions R/nlda.R
Expand Up @@ -3,7 +3,7 @@
setGeneric('nlda',function(x,cls = 'class',prior = NULL,scale = FALSE,comprank = FALSE,...)
standardGeneric('nlda'))

#' @importFrom e1071 naiveBayes
#' @importFrom e1071 naiveBayes
#' @importFrom stats cov predict
#' @importFrom methods as

Expand Down Expand Up @@ -135,7 +135,7 @@ setMethod('nlda',signature = 'AnalysisData',
dimnames(xmeans)[[2]] <- colnames(x)

nbmod <- naiveBayes(data.frame(x),cl)
prob <- predict(nbmod,data.frame(x),type="raw")
prob <- stats::predict(nbmod,data.frame(x),type="raw")
pred <- apply(prob,1,which.max)
pred <- factor(levels(cl)[pred], levels = levels(cl))

Expand Down

0 comments on commit 5b3a032

Please sign in to comment.