Skip to content

Commit

Permalink
Merge pull request #400 from olivroy/patch-1
Browse files Browse the repository at this point in the history
Update gh action + document with roxygen2 + replace `T` -> `TRUE`, `F` by `FALSE` to satisfy R CMD CHECK
  • Loading branch information
florianhartig authored Jun 28, 2024
2 parents 862c344 + 0c8c061 commit a3ca960
Show file tree
Hide file tree
Showing 33 changed files with 132 additions and 179 deletions.
107 changes: 30 additions & 77 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
# 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
- GitAction

branches: [main, master, GitAction]
pull_request:
branches:
- main
- master
branches: [main, master]

name: R-CMD-check

Expand All @@ -24,85 +18,44 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: windows-latest, r: 'oldrel'}

# - {os: macOS-latest, r: 'devel'}
- {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"}
- {os: windows-latest, r: 'devel'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

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

steps:

- uses: actions/checkout@v3

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

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

- uses: r-lib/actions/setup-tinytex@v2
- run: tlmgr --version

- name: Query dependencies
run: |
setwd("DHARMa")
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
- uses: r-lib/actions/setup-r@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: |
cd DHARMa
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- name: Install dependencies
run: |
setwd("DHARMa")
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check_II
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
CI: true
run: |
rcmdcheck::rcmdcheck("DHARMa", args = c("--no-multiarch", "--no-manual"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
CI: true
run: |
rcmdcheck::rcmdcheck("DHARMa", args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check
working-directory: DHARMa
# second check with different rcmdcheck arguments.
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
working-directory: DHARMa
args: 'c("--no-multiarch", "--no-manual")'

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
- uses: r-lib/actions/check-r-package@v2
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
upload-snapshots: true
working-directory: DHARMa
8 changes: 4 additions & 4 deletions DHARMa/R/DHARMa.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ outliers <- function(object, lowerQuantile = 0, upperQuantile = 1, return = c("i
#' @note Either scaled residuals or (simulatedResponse AND observed response) have to be provided
#' @example inst/examples/createDharmaHelp.R
#' @export
createDHARMa <- function(simulatedResponse , observedResponse , fittedPredictedResponse = NULL, integerResponse = F, seed = 123, method = c("PIT", "traditional"), rotation = NULL){
createDHARMa <- function(simulatedResponse , observedResponse , fittedPredictedResponse = NULL, integerResponse = FALSE, seed = 123, method = c("PIT", "traditional"), rotation = NULL){

randomState <-getRandomState(seed)
on.exit({randomState$restoreCurrent()})
Expand Down Expand Up @@ -142,7 +142,7 @@ createDHARMa <- function(simulatedResponse , observedResponse , fittedPredictedR
#' @return an object of class DHARMa
#' @keywords internal
ensureDHARMa <- function(simulationOutput,
convert = F){
convert = FALSE){

if(inherits(simulationOutput, "DHARMa")){
return(simulationOutput)
Expand All @@ -152,8 +152,8 @@ ensureDHARMa <- function(simulationOutput,
else {

if (class(simulationOutput)[1] %in% getPossibleModels()){
if (convert == "Model" | convert == T) return(simulateResiduals(simulationOutput))
} else if(is.vector(simulationOutput, mode = "numeric") & convert == T) {
if (convert == "Model" | convert == TRUE) return(simulateResiduals(simulationOutput))
} else if(is.vector(simulationOutput, mode = "numeric") & convert == TRUE) {
out = list()
out$scaledResiduals = simulationOutput
out$nObs = length(out$scaledResiduals)
Expand Down
2 changes: 1 addition & 1 deletion DHARMa/R/createData.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' @param hasNA should an NA be added to the environmental predictor (for test purposes)
#' @export
#' @example /inst/examples/createDataHelp.R
createData <- function(sampleSize = 100, intercept = 0, fixedEffects = 1, quadraticFixedEffects = NULL, numGroups = 10, randomEffectVariance = 1, overdispersion = 0, family = poisson(), scale = 1, cor = 0, roundPoissonVariance = NULL, pZeroInflation = 0, binomialTrials = 1, temporalAutocorrelation = 0, spatialAutocorrelation =0, factorResponse = F, replicates=1, hasNA = F){
createData <- function(sampleSize = 100, intercept = 0, fixedEffects = 1, quadraticFixedEffects = NULL, numGroups = 10, randomEffectVariance = 1, overdispersion = 0, family = poisson(), scale = 1, cor = 0, roundPoissonVariance = NULL, pZeroInflation = 0, binomialTrials = 1, temporalAutocorrelation = 0, spatialAutocorrelation =0, factorResponse = FALSE, replicates=1, hasNA = FALSE){

nPredictors = length(fixedEffects)

Expand Down
36 changes: 18 additions & 18 deletions DHARMa/R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#'
#' @param x an object of class DHARMa with simulated residuals created by \code{\link{simulateResiduals}}
#' @param ... further options for \code{\link{plotResiduals}}. Consider in particular parameters quantreg, rank and asFactor. xlab, ylab and main cannot be changed when using plot.DHARMa, but can be changed when using plotResiduals.
#' @param title The title for both panels (plotted via mtext, outer = T)
#' @param title The title for both panels (plotted via mtext, outer = TRUE)
#'
#' @details The function creates a plot with two panels. The left panel is a uniform qq plot (calling \code{\link{plotQQunif}}), and the right panel shows residuals against predicted values (calling \code{\link{plotResiduals}}), with outliers highlighted in red.
#'
Expand All @@ -31,7 +31,7 @@ plot.DHARMa <- function(x, title = "DHARMa residual", ...){
plotQQunif(x)
plotResiduals(x, ...)

mtext(title, outer = T)
mtext(title, outer = TRUE)
}


Expand All @@ -57,7 +57,7 @@ hist.DHARMa <- function(x,
cex.main = 1,
...){

x = ensureDHARMa(x, convert = T)
x = ensureDHARMa(x, convert = TRUE)

val = x$scaledResiduals
val[val == 0] = -0.01
Expand Down Expand Up @@ -97,7 +97,7 @@ plotSimulatedResiduals <- function(simulationOutput, ...){
#' @seealso \code{\link{plotSimulatedResiduals}}, \code{\link{plotResiduals}}
#' @example inst/examples/plotsHelp.R
#' @export
plotQQunif <- function(simulationOutput, testUniformity = T, testOutliers = T, testDispersion = T, ...){
plotQQunif <- function(simulationOutput, testUniformity = TRUE, testOutliers = TRUE, testDispersion = TRUE, ...){

a <- list(...)
a$pch = checkDots("pch", 2, ...)
Expand All @@ -114,7 +114,7 @@ plotQQunif <- function(simulationOutput, testUniformity = T, testOutliers = T, t
do.call(gap::qqunif, append(list(simulationOutput$scaledResiduals), a))

if(testUniformity == TRUE){
temp = testUniformity(simulationOutput, plot = F)
temp = testUniformity(simulationOutput, plot = FALSE)
legend("topleft",
c(paste("KS test: p=", round(temp$p.value, digits = 5)),
paste("Deviation ", ifelse(temp$p.value < 0.05, "significant", "n.s."))),
Expand All @@ -123,7 +123,7 @@ plotQQunif <- function(simulationOutput, testUniformity = T, testOutliers = T, t
}

if(testOutliers == TRUE){
temp = testOutliers(simulationOutput, plot = F)
temp = testOutliers(simulationOutput, plot = FALSE)
legend("bottomright",
c(paste("Outlier test: p=", round(temp$p.value, digits = 5)),
paste("Deviation ", ifelse(temp$p.value < 0.05, "significant", "n.s."))),
Expand All @@ -132,7 +132,7 @@ plotQQunif <- function(simulationOutput, testUniformity = T, testOutliers = T, t
}

if(testDispersion == TRUE){
temp = testDispersion(simulationOutput, plot = F)
temp = testDispersion(simulationOutput, plot = FALSE)
legend("center",
c(paste("Dispersion test: p=", round(temp$p.value, digits = 5)),
paste("Deviation ", ifelse(temp$p.value < 0.05, "significant", "n.s."))),
Expand Down Expand Up @@ -175,7 +175,7 @@ plotQQunif <- function(simulationOutput, testUniformity = T, testOutliers = T, t
#' @seealso \code{\link{plotQQunif}}, \code{\link{testQuantiles}}, \code{\link{testOutliers}}
#' @example inst/examples/plotsHelp.R
#' @export
plotResiduals <- function(simulationOutput, form = NULL, quantreg = NULL, rank = T, asFactor = NULL, smoothScatter = NULL, quantiles = c(0.25, 0.5, 0.75), absoluteDeviation = FALSE, ...){
plotResiduals <- function(simulationOutput, form = NULL, quantreg = NULL, rank = TRUE, asFactor = NULL, smoothScatter = NULL, quantiles = c(0.25, 0.5, 0.75), absoluteDeviation = FALSE, ...){


##### Checks #####
Expand All @@ -185,12 +185,12 @@ plotResiduals <- function(simulationOutput, form = NULL, quantreg = NULL, rank =
a$ylab = checkDots("ylab", yAxis , ...)
a$xlab = checkDots("xlab", ifelse(is.null(form), "Model predictions",
gsub(".*[$]","",deparse(substitute(form)))), ...)
if(rank == T) a$xlab = paste(a$xlab, "(rank transformed)")
if(rank == TRUE) a$xlab = paste(a$xlab, "(rank transformed)")

simulationOutput = ensureDHARMa(simulationOutput, convert = T)
simulationOutput = ensureDHARMa(simulationOutput, convert = TRUE)
res = simulationOutput$scaledResiduals

if(absoluteDeviation == T){
if(absoluteDeviation == TRUE){
res = 2 * abs(res - 0.5)
}

Expand All @@ -202,7 +202,7 @@ plotResiduals <- function(simulationOutput, form = NULL, quantreg = NULL, rank =

if(!is.factor(pred)){

if (rank == T){
if (rank == TRUE){
pred = rank(pred, ties.method = "average")
pred = pred / max(pred)
a$xlim = checkDots("xlim", c(0,1), ...)
Expand Down Expand Up @@ -256,16 +256,16 @@ plotResiduals <- function(simulationOutput, form = NULL, quantreg = NULL, rank =
out = NULL

if(is.numeric(pred)){
if(quantreg == F){
if(quantreg == FALSE){
title(main = main, cex.main = 1)
abline(h = quantiles, col = "black", lwd = 0.5, lty = 2)
try({
lines(smooth.spline(pred, res, df = 10), lty = 2, lwd = 2, col = "red")
abline(h = 0.5, col = "red", lwd = 2)
}, silent = T)
}, silent = TRUE)
}else{

out = testQuantiles(res, pred, quantiles = quantiles, plot = F)
out = testQuantiles(res, pred, quantiles = quantiles, plot = FALSE)


if(any(out$pvals < 0.05, na.rm = TRUE)){
Expand Down Expand Up @@ -293,7 +293,7 @@ plotResiduals <- function(simulationOutput, form = NULL, quantreg = NULL, rank =
abline(h = quantiles[i], col = lineCol, lwd = 0.5, lty = 2)
polygon(c(out$predictions$pred, rev(out$predictions$pred)),
c(out$predictions[,2*i] - out$predictions[,2*i+1], rev(out$predictions[,2*i] + out$predictions[,2*i+1])),
col = "#00000020", border = F)
col = "#00000020", border = FALSE)
lines(out$predictions$pred, out$predictions[,2*i], col = lineCol, lwd = 2)
}

Expand Down Expand Up @@ -358,15 +358,15 @@ plotConventionalResiduals <- function(fittedModel){
plot(predict(fittedModel), resid(fittedModel, type = "deviance"), main = "Deviance" , ylab = "Residual", xlab = "Predicted")
plot(predict(fittedModel), resid(fittedModel, type = "pearson") , main = "Pearson", ylab = "Residual", xlab = "Predicted")
plot(predict(fittedModel), resid(fittedModel, type = "response") , main = "Raw residuals" , ylab = "Residual", xlab = "Predicted")
mtext("Conventional residual plots", outer = T)
mtext("Conventional residual plots", outer = TRUE)
}




#
#
# if(quantreg == F){
# if(quantreg == FALSE){
#
# lines(smooth.spline(simulationOutput$fittedPredictedResponse, simulationOutput$scaledResiduals, df = 10), lty = 2, lwd = 2, col = "red")
#
Expand Down
2 changes: 1 addition & 1 deletion DHARMa/R/random.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ getRandomState <- function(seed = NULL){

current = mget(".Random.seed", envir = .GlobalEnv, ifnotfound = list(NULL))[[1]]

if(!is.null(seed) && is.logical(seed) && seed == F){
if(!is.null(seed) && is.logical(seed) && seed == FALSE){
restoreCurrent <- function(){}
}else{
restoreCurrent <- function(){
Expand Down
Loading

0 comments on commit a3ca960

Please sign in to comment.