Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
svkucheryavski committed Jan 22, 2021
2 parents 21aa81e + 2dc9b17 commit a796daf
Show file tree
Hide file tree
Showing 28 changed files with 730 additions and 161 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
on:
push:
branches:
- main
- master
- develop
pull_request:
branches:
- main
- master
- develop

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-r@v1
with:
r-version: ${{ matrix.config.r }}

- 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}

- name: Cache R packages
if: runner.os != 'Windows'
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 system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.DS_Store
.lintr
.vscode/*
LICENSE

tests/plots/*.pdf
tests/plots/*.txt
Expand Down
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: mdatools
Title: Multivariate Data Analysis for Chemometrics
Version: 0.11.2
Date: 2020-10-22
Author: Sergey Kucheryavskiy
Version: 0.11.3
Date: 2021-01-21
Author: Sergey Kucheryavskiy (<https://orcid.org/0000-0002-3145-7244>)
Maintainer: Sergey Kucheryavskiy <[email protected]>
Description: Projection based methods for preprocessing,
exploring and analysis of multivariate data used in chemometrics.
Expand Down
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2016-2021 Sergey Kucheryavskiy

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export(ddmoments.param)
export(ddrobust.param)
export(ellipse)
export(employ)
export(eye)
export(fprintf)
export(getCalibrationData)
export(getConfusionMatrix)
Expand Down Expand Up @@ -233,6 +234,7 @@ export(pca)
export(pca.mvreplace)
export(pca.run)
export(pcares)
export(pcv)
export(pinv)
export(plotBars)
export(plotBiplot)
Expand Down Expand Up @@ -297,6 +299,7 @@ export(prep.alsbasecorr)
export(prep.autoscale)
export(prep.msc)
export(prep.norm)
export(prep.ref2km)
export(prep.savgol)
export(prep.snv)
export(prepCalData)
Expand Down
16 changes: 16 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
v.0.11.3
========

* added [Procrustes Cross-Validation method](https://doi.org/10.1021/acs.analchem.0c02175), `pcv()` (it is also available as a [separate project](https://github.com/svkucheryavski/pcv)).

* added Kubelka-Munk transformation for diffuse reflectance spectra (`prep.ref2km()`).

* fixed bug [#94](https://github.com/svkucheryavski/mdatools/issues/94) which caused wrong limits in PCA distance plot when outliers are present but excluded.

* fixed bug [#95](https://github.com/svkucheryavski/mdatools/issues/95) which lead to issues when PLS regression methods (e.g. `plotRMSE()`) are used for PLS-DA model object.

* added additional check that parameter `cgroup` for plotting functions is provided as a vector or as a factor to avoid confusion.

* added link to [YouTube channel](https://www.youtube.com/channel/UCox0H4utfMq4FIu2kymuyTA) with Chemometric course based on *mdatools* package.


v.0.11.2
========

Expand Down
25 changes: 17 additions & 8 deletions R/ldecomp.R
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,8 @@ ldecomp.getLimitsCoordinates <- function(Qlim, T2lim, ncomp, norm, log,
#' logical, show or not legend on the plot (if more than one result object)
#' @param legend.position
#' if legend must be shown, where it should be
#' @param show.excluded
#' logical, show or hide rows marked as excluded (attribute `exclrows`).
#' @param ...
#' other plot parameters (see \code{mdaplotg} for details)
#'
Expand All @@ -988,12 +990,18 @@ ldecomp.getLimitsCoordinates <- function(Qlim, T2lim, ncomp, norm, log,
ldecomp.plotResiduals <- function(res, Qlim, T2lim, ncomp, log = FALSE, norm = FALSE,
cgroup = NULL, xlim = NULL, ylim = NULL, show.limits = c(TRUE, TRUE),
lim.col = c("darkgray", "darkgray"), lim.lwd = c(1, 1), lim.lty = c(2, 3),
show.legend = TRUE, legend.position = "topright", ...) {
show.legend = TRUE, legend.position = "topright", show.excluded = FALSE, ...) {

getPlotLim <- function(lim, pd, ld, dim, show.limits) {
# return column with values either with or without excluded outliers
getValues <- function(x, dim) {
return(if (show.excluded) x[, dim] else mda.purgeRows(x)[, dim])
}

# compute limits fo axis depending on values and position of critical limits
getPlotLim <- function(lim, pd, ld, dim) {
if (!is.null(lim) || all(!show.limits)) return(lim)
limits <- if (show.limits[[2]]) ld$outliers else ld$extremes
return(c(0, max(sapply(pd, function(x) max(x[, dim])), limits[, dim])) * 1.05)
limits <- if (show.limits[[2]]) max(ld$outliers[, dim]) else max(ld$extremes[, dim])
return( c(0, max(sapply(pd, function(x) { max(c(getValues(x, dim), limits)) * 1.05}))) )
}

# check that show.limits is logical
Expand All @@ -1015,15 +1023,16 @@ ldecomp.plotResiduals <- function(res, Qlim, T2lim, ncomp, log = FALSE, norm = F

# get coordinates for critical limits
lim_data <- ldecomp.getLimitsCoordinates(Qlim, T2lim, ncomp = ncomp, norm = norm, log = log)
xlim <- getPlotLim(xlim, plot_data, lim_data, 1, show.limits)
ylim <- getPlotLim(ylim, plot_data, lim_data, 2, show.limits)
xlim <- getPlotLim(xlim, plot_data, lim_data, 1)
ylim <- getPlotLim(ylim, plot_data, lim_data, 2)

# make plot
if (length(plot_data) == 1) {
mdaplot(plot_data[[1]], type = "p", xlim = xlim, ylim = ylim, cgroup = cgroup, ...)
mdaplot(plot_data[[1]], type = "p", xlim = xlim, ylim = ylim, cgroup = cgroup,
show.excluded = show.excluded, ...)
} else {
mdaplotg(plot_data, type = "p", xlim = xlim, ylim = ylim, show.legend = show.legend,
legend.position = legend.position, ...)
show.excluded = show.excluded, legend.position = legend.position, ...)
}

# show critical limits
Expand Down
4 changes: 4 additions & 0 deletions R/mdaplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ mdaplot.getColors <- function(ngroups = NULL, cgroup = NULL, colmap = "default",
return(mdaplot.prepareColors(palette, ngroups, opacity))
}

if (!is.null(dim(cgroup))) {
stop("Parameter 'cgroup' should be a vector of values or a factor.")
}

# if cgroup is factor return vector with corresponding values
if (is.factor(cgroup)) {
ngroups <- length(attr(cgroup, "levels"))
Expand Down
Loading

0 comments on commit a796daf

Please sign in to comment.