From b7537424d46ebef4e9e829b93890431b0cbc364f Mon Sep 17 00:00:00 2001 From: Alex Chubaty Date: Mon, 23 Jan 2023 23:06:36 -0700 Subject: [PATCH] updates, cleanup, R CMD check --- .github/workflows/R-CMD-check.yaml | 82 +++++++----------------------- DESCRIPTION | 7 +-- NAMESPACE | 2 +- R/bootstrapPercentChanges.R | 4 +- R/createDynamicLayersRSF.R | 3 +- R/createModObject.R | 2 +- R/createShrubHerbLayers.R | 3 +- R/createStaticLayersRSF.R | 3 +- R/defineStudyArea.R | 5 +- man/bootstrapPercentChanges.Rd | 2 +- man/createDynamicLayersRSF.Rd | 2 - man/defineStudyArea.Rd | 3 +- usefulFuns.Rproj | 3 ++ 13 files changed, 41 insertions(+), 80 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 475bade..a5d80cb 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -3,7 +3,6 @@ on: branches: - master - development - - LandWeb pull_request: branches: - master @@ -13,6 +12,7 @@ name: R-CMD-check jobs: R-CMD-check: + if: "!contains(github.event.commits[0].message, '[skip-ci]')" runs-on: ${{ matrix.config.os }} name: ${{ matrix.config.os }} (${{ matrix.config.r }}) @@ -21,81 +21,35 @@ jobs: fail-fast: false matrix: config: - - {os: macOS-latest, r: 'release'} - - {os: windows-latest, r: 'devel'} - - {os: windows-latest, r: 'release'} - - {os: windows-latest, r: '3.6'} - - {os: ubuntu-18.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest", http-user-agent: "R/4.0.0 (ubuntu-18.04) R (4.0.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" } - - {os: ubuntu-18.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"} - - {os: ubuntu-18.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"} + - {os: macOS-latest, nosuggests: false, r: 'release'} + - {os: windows-latest, nosuggests: false, r: 'devel'} + - {os: windows-latest, nosuggests: false, r: 'release'} + - {os: ubuntu-20.04, nosuggests: false, r: 'devel'} + - {os: ubuntu-20.04, nosuggests: false, r: 'release'} + - {os: ubuntu-20.04, nosuggests: true, r: 'release'} env: - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - RSPM: ${{ matrix.config.rspm }} + _R_CHECK_DEPENDS_ONLY_: ${{ matrix.config.nosuggests }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true steps: - uses: actions/checkout@v3 - - uses: r-lib/actions/setup-r@master + - 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 }} - - - uses: r-lib/actions/setup-pandoc@master - - - 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} + use-public-rspm: true - - name: Install additional dependencies - run: | - remotes::install_github('PredictiveEcology/Require@development') - remotes::install_github('PredictiveEcology/reproducible@development') - shell: Rscript {0} - - - name: Cache R packages - if: runner.os != 'Windows' - uses: actions/cache@v1 + - 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- - - - name: Install system dependencies - if: runner.os == 'Linux' - run: | - while read -r cmd - do - eval sudo $cmd - done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "18.04"), sep = "\n")') - sudo apt-get install -y hunspell-en-ca - - - name: Install dependencies - run: | - if (R.version$major < 4) { - remotes::install_cran("versions") - versions::install.versions("XML", "3.99-0.3") - } - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("rcmdcheck") - shell: Rscript {0} - - - name: Session info - run: | - options(width = 100) - pkgs <- installed.packages()[, "Package"] - sessioninfo::session_info(pkgs, include_base = TRUE) - shell: Rscript {0} + extra-packages: | + any::rcmdcheck + any::XML - - name: Check - env: - _R_CHECK_CRAN_INCOMING_: false - run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} + - uses: r-lib/actions/check-r-package@v2 - name: Show testthat output if: always() diff --git a/DESCRIPTION b/DESCRIPTION index 3e93102..6983208 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: usefulFuns Type: Package Title: Useful functions for my modules and packages -Version: 0.1.0 +Version: 0.1.1 Author: Tati Micheletti Maintainer: Tati Micheletti Description: A few functions and wrappers around useful code. @@ -10,7 +10,7 @@ Encoding: UTF-8 Language: en-CA LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.1 +RoxygenNote: 7.2.3 Depends: R (>= 3.6) Imports: @@ -33,8 +33,8 @@ Imports: raster, rasterVis, RColorBrewer, - remotes, reproducible, + Require, sp, sf, showtext, @@ -45,6 +45,7 @@ Imports: Suggests: covr, lintr, + remotes, spelling Remotes: achubaty/amc@development, diff --git a/NAMESPACE b/NAMESPACE index 7c0f4a3..1125c54 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -44,6 +44,7 @@ importFrom(LandR,prepInputsLCC) importFrom(LandR,sppColors) importFrom(LandR,vegTypeMapGenerator) importFrom(RColorBrewer,brewer.pal) +importFrom(Require,Require) importFrom(SpaDES.core,paddedFloatToChar) importFrom(SpaDES.tools,randomPolygon) importFrom(SpaDES.tools,rasterizeReduced) @@ -108,7 +109,6 @@ importFrom(raster,writeRaster) importFrom(raster,xyFromCell) importFrom(rasterVis,gplot) importFrom(reproducible,Cache) -importFrom(reproducible,Require) importFrom(reproducible,asPath) importFrom(reproducible,assessDataType) importFrom(reproducible,basename2) diff --git a/R/bootstrapPercentChanges.R b/R/bootstrapPercentChanges.R index 9c94e0b..67b8775 100644 --- a/R/bootstrapPercentChanges.R +++ b/R/bootstrapPercentChanges.R @@ -10,7 +10,7 @@ #' @param n numeric. Default is 100. How many iterations (random selection of `sampleSize` pixels) should be done? #' @param species character. Default is NULL. Which species should this function be ran ? #' @param useFuture logical. Should use \pkg{future} to parallelize? -#' Requires `future` and `future_apply`` packages. +#' Requires `future` and `future_apply` packages. #' #' @return list of significant species or scenarios with indication of increasing or decreasing #' @@ -38,7 +38,7 @@ bootstrapPercentChanges <- function(dataPath, n = 100, shp = NULL, species = NULL, useFuture = FALSE) { - if (class(shp) == "character") { + if (inherits(shp, "character")) { studyArea <- Cache(.prepStudyAreaForBirds, studyArea = shp, dataPath = reproducible::checkPath(file.path(dataPath, "birdRTMEdehzhieRAS"), diff --git a/R/createDynamicLayersRSF.R b/R/createDynamicLayersRSF.R index 235b1de..f24b45c 100644 --- a/R/createDynamicLayersRSF.R +++ b/R/createDynamicLayersRSF.R @@ -22,7 +22,8 @@ #' @export #' @importFrom data.table data.table setkey #' @importFrom raster raster projectRaster extract dropLayer stack nlayers extent -#' @importFrom reproducible prepInputs postProcess Require +#' @importFrom reproducible prepInputs postProcess +#' @importFrom Require Require #' @importFrom SpaDES.tools rasterizeReduced #' @include burnFromAge.R #' @include nameAndBringOn.R diff --git a/R/createModObject.R b/R/createModObject.R index 3a1347a..c441a15 100644 --- a/R/createModObject.R +++ b/R/createModObject.R @@ -41,7 +41,7 @@ createModObject <- function(data, sim = NULL, pathInput, currentTime, fun = read )) == 0) { stop(paste0("Please place the data in the input folder ", pathInput)) } - if (class(currentTime) != "numeric") { + if (inherits(currentTime, "numeric")) { stop("Current time needs to be numeric!") } dataName <- grepMulti( diff --git a/R/createShrubHerbLayers.R b/R/createShrubHerbLayers.R index 2033c0b..2057dff 100644 --- a/R/createShrubHerbLayers.R +++ b/R/createShrubHerbLayers.R @@ -14,7 +14,8 @@ utils::globalVariables(c("classesECCC", "ECCC_Description")) #' @export #' @importFrom data.table data.table setkey #' @importFrom raster raster setValues -#' @importFrom reproducible prepInputs postProcess Require +#' @importFrom reproducible prepInputs postProcess +#' @importFrom Require Require #' #' @rdname createShrubHerbLayers createShrubHerbLayers <- function(landCoverECCC, reclassLCC05, layerName, includeCrops = FALSE) { diff --git a/R/createStaticLayersRSF.R b/R/createStaticLayersRSF.R index e85df6c..a40706e 100644 --- a/R/createStaticLayersRSF.R +++ b/R/createStaticLayersRSF.R @@ -20,7 +20,8 @@ #' @export #' @importFrom data.table data.table setkey #' @importFrom raster dropLayer extent extract nlayers projectRaster raster reclassify stack -#' @importFrom reproducible prepInputs postProcess Require +#' @importFrom reproducible prepInputs postProcess +#' @importFrom Require Require #' @importFrom SpaDES.tools rasterizeReduced #' @include createShrubHerbLayers.R #' @include nameAndBringOn.R diff --git a/R/defineStudyArea.R b/R/defineStudyArea.R index 9051696..68185e5 100644 --- a/R/defineStudyArea.R +++ b/R/defineStudyArea.R @@ -22,12 +22,13 @@ utils::globalVariables(c("PRENAME")) #' @rdname defineStudyArea #' #' @examples +#' \donttest{ #' ## rp is the whole North American boreal region #' rp <- defineStudyArea(testArea = TRUE, specificTestArea = "boreal", mapSubset = NULL) #' #' ## Alberta #' rp <- defineStudyArea(testArea = TRUE, specificTestArea = "Alberta", mapSubset = NULL) -#' \dontrun{ +#' #' ## Alberta inside boreal extension #' rp <- defineStudyArea(testArea = TRUE, specificTestArea = "boreal", mapSubset = "Alberta") #' } @@ -57,7 +58,7 @@ defineStudyArea <- function(testArea = NULL, specificTestArea = NULL, mapSubset if (is.null(mapSubset)) { message(crayon::yellow("Test area is TRUE, specificTestArea is 'boreal', and mapSubset is NULL. Cropping and masking to the whole Boreal.")) rP <- reproducible::prepInputs( - url = "http://206.167.182.7/BAM/dataset/EnvironmentCanada/Brandt_boreal.zip", + url = "http://206.167.182.7/BAM/dataset/EnvironmentCanada/Brandt_boreal.zip", ## TODO: invalid URL destinationPath = destinationFolder ) } diff --git a/man/bootstrapPercentChanges.Rd b/man/bootstrapPercentChanges.Rd index b0c2740..c4176a9 100644 --- a/man/bootstrapPercentChanges.Rd +++ b/man/bootstrapPercentChanges.Rd @@ -31,7 +31,7 @@ Needs to match the rasters. Default is NULL (i.e. the whole raster is only one a \item{species}{character. Default is NULL. Which species should this function be ran ?} \item{useFuture}{logical. Should use \pkg{future} to parallelize? -Requires \code{future} and `future_apply`` packages.} +Requires \code{future} and \code{future_apply} packages.} } \value{ list of significant species or scenarios with indication of increasing or decreasing diff --git a/man/createDynamicLayersRSF.Rd b/man/createDynamicLayersRSF.Rd index f4dc564..c57a34e 100644 --- a/man/createDynamicLayersRSF.Rd +++ b/man/createDynamicLayersRSF.Rd @@ -90,7 +90,5 @@ created in the current function to be passed for the model prediction.} Intended for use within a SpaDES module. } \author{ -Tati Micheletti - Tati Micheletti } diff --git a/man/defineStudyArea.Rd b/man/defineStudyArea.Rd index c3185e1..7f40bcd 100644 --- a/man/defineStudyArea.Rd +++ b/man/defineStudyArea.Rd @@ -30,12 +30,13 @@ Downloads, reprojects, crops and masks to specific areas in Canada such as: boreal, random areas, provinces and territories, or any of the last in the boreal. } \examples{ +\donttest{ ## rp is the whole North American boreal region rp <- defineStudyArea(testArea = TRUE, specificTestArea = "boreal", mapSubset = NULL) ## Alberta rp <- defineStudyArea(testArea = TRUE, specificTestArea = "Alberta", mapSubset = NULL) -\dontrun{ + ## Alberta inside boreal extension rp <- defineStudyArea(testArea = TRUE, specificTestArea = "boreal", mapSubset = "Alberta") } diff --git a/usefulFuns.Rproj b/usefulFuns.Rproj index e5c3f7c..ae64a63 100644 --- a/usefulFuns.Rproj +++ b/usefulFuns.Rproj @@ -20,3 +20,6 @@ PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source PackageCheckArgs: --as-cran PackageRoxygenize: rd,collate,namespace,vignette + +QuitChildProcessesOnExit: Yes +DisableExecuteRprofile: Yes