From a09114f716d1b19a14b26eb0f1fb10f8772f0705 Mon Sep 17 00:00:00 2001 From: Baseer Ahmad Baheer Date: Thu, 13 Jul 2023 13:17:04 +0200 Subject: [PATCH 1/2] Adjusted the where value in toolGetMapping() --- .Rbuildignore | 4 ++ .buildlibrary | 2 +- .../{lucode2-check.yaml => check.yaml} | 41 ++++++++++++++--- .lintr | 2 + .pre-commit-config.yaml | 22 +++++++-- .zenodo.json | 10 ---- CITATION.cff | 15 ++++++ DESCRIPTION | 6 +-- Makefile | 46 +++++++++++++++++++ R/mrtutorial-package.R | 4 ++ R/spatialHeader.R | 2 +- README.md | 10 ++-- man/mrtutorial-package.Rd | 14 ++++++ tests/.lintr | 2 + 14 files changed, 150 insertions(+), 30 deletions(-) rename .github/workflows/{lucode2-check.yaml => check.yaml} (67%) create mode 100644 .lintr delete mode 100644 .zenodo.json create mode 100644 CITATION.cff create mode 100644 Makefile create mode 100644 R/mrtutorial-package.R create mode 100644 man/mrtutorial-package.Rd create mode 100644 tests/.lintr diff --git a/.Rbuildignore b/.Rbuildignore index 9d45404..fafd5f4 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,7 @@ ^\.github$ ^codecov\.yml$ ^workflow$ +^Makefile$ +^.lintr$ +^tests/.lintr$ +^.*CITATION.cff$ diff --git a/.buildlibrary b/.buildlibrary index 967703c..15f74d3 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '552682' +ValidationKey: '4105710' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/.github/workflows/lucode2-check.yaml b/.github/workflows/check.yaml similarity index 67% rename from .github/workflows/lucode2-check.yaml rename to .github/workflows/check.yaml index 1dc7677..fcd7136 100644 --- a/.github/workflows/lucode2-check.yaml +++ b/.github/workflows/check.yaml @@ -1,6 +1,6 @@ # Run CI for R using https://eddelbuettel.github.io/r-ci/ -name: lucode2-check +name: check on: push: @@ -11,14 +11,14 @@ on: env: USE_BSPM: "true" _R_CHECK_FORCE_SUGGESTS_: "false" - NO_BINARY_INSTALL_R_PACKAGES: 'c("madrat", "magclass", "citation", "gms", "goxygen")' + NO_BINARY_INSTALL_R_PACKAGES: 'c("madrat", "magclass", "citation", "gms", "goxygen", "GDPuc", "roxygen2")' jobs: - lucode2-check: + check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Bootstrap run: | @@ -28,6 +28,7 @@ jobs: curl -OLs https://eddelbuettel.github.io/r-ci/run.sh chmod 0755 run.sh ./run.sh bootstrap + rm -f bspm_*.tar.gz - name: Enable r-universe repo, modify bspm integration run: | @@ -48,19 +49,45 @@ jobs: pkgs <- c(bspm::install_sys(pkgs[!pkgs %%in%% noBinaryInstallRPackages]), pkgs[pkgs %%in%% noBinaryInstallRPackages]) } + type <- "source" }) trace(utils::install.packages, expr, print = FALSE) }) ' "$NO_BINARY_INSTALL_R_PACKAGES" | sudo tee --append /etc/R/Rprofile.site >/dev/null cat /etc/R/Rprofile.site - - uses: r-lib/actions/setup-pandoc@v1 + - name: Set up Pandoc + uses: r-lib/actions/setup-pandoc@v2 + + - name: Set up Python 3.9 + uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - name: Cache R libraries + if: ${{ !env.ACT }} # skip when running locally via nektos/act + uses: pat-s/always-upload-cache@v3 + with: + path: /usr/local/lib/R/ + key: 3-${{ runner.os }}-usr-local-lib-R-${{ hashFiles('DESCRIPTION') }} + restore-keys: | + 3-${{ runner.os }}-usr-local-lib-R- + + - name: Restore R library permissions + run: | + sudo chmod 2777 /usr/local/lib/R /usr/local/lib/R/site-library - name: Install dependencies run: | - ./run.sh install_aptget libhdf5-dev + ./run.sh install_aptget libhdf5-dev libharfbuzz-dev libfribidi-dev ./run.sh install_all - ./run.sh install_r lucode2 covr + ./run.sh install_r_binary covr rstudioapi + ./run.sh install_r lucode2 + + - name: Install python dependencies if applicable + run: | + [ -f requirements.txt ] && python -m pip install --upgrade pip wheel || true + [ -f requirements.txt ] && pip install -r requirements.txt || true - name: Remove bspm integration # to get rid of error when running install.packages run: | diff --git a/.lintr b/.lintr new file mode 100644 index 0000000..c02af8f --- /dev/null +++ b/.lintr @@ -0,0 +1,2 @@ +linters: lucode2::lintrRules() +encoding: "UTF-8" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2c63991..9c3b069 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,28 @@ +# testthat snapshots are machine-generated regression tests that +# have to be preserved exactly as they are +exclude: '^tests/testthat/_snaps/.*$' repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v4.4.0 hooks: - id: check-case-conflict - id: check-json - - id: check-yaml - id: check-merge-conflict + - id: check-yaml - id: fix-byte-order-marker - - id: end-of-file-fixer + - id: check-added-large-files + args: ['--maxkb=100'] + - id: mixed-line-ending + +- repo: https://github.com/lorenzwalthert/precommit + rev: v0.3.2.9013 + hooks: + - id: parsable-R + - id: deps-in-desc + args: [--allow_private_imports] + - id: no-browser-statement + - id: no-debug-statement + - id: readme-rmd-rendered + - id: use-tidy-description ci: autoupdate_schedule: quarterly diff --git a/.zenodo.json b/.zenodo.json deleted file mode 100644 index 80a31a3..0000000 --- a/.zenodo.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "title": "mrtutorial: Tutorial Package For Madrat Package Library", - "version": "0.2.9", - "description": "

Example package of mr- world libraries, in conjunction with MAgPIE MADRat tutorial. For more information please see: https://github.com/magpiemodel/tutorials/tree/master/madrat .<\/p>", - "creators": [ - { - "name": "Chen, David Meng-Chuen" - } - ] -} diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 0000000..ece337c --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,15 @@ +cff-version: 1.2.0 +message: If you use this software, please cite it using the metadata from this file. +type: software +title: 'mrtutorial: Tutorial Package For Madrat Package Library' +version: 0.2.10 +date-released: '2023-07-13' +abstract: 'Example package of mr- world libraries, in conjunction with MAgPIE MADRat + tutorial. For more information please see: https://github.com/magpiemodel/tutorials/tree/master/madrat + .' +authors: +- family-names: Chen + given-names: David Meng-Chuen + email: david.chen@pik-potsdam.de +license: GPL-3.0 + diff --git a/DESCRIPTION b/DESCRIPTION index 88972da..9aa36f5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: mrtutorial Type: Package Title: Tutorial Package For Madrat Package Library -Date: 2022-03-07 -Version: 0.2.9 +Date: 2023-07-13 +Version: 0.2.10 Authors@R: person("David Meng-Chuen", "Chen", email = "david.chen@pik-potsdam.de", role = c("aut","cre")) Description: Example package of mr- world libraries, in conjunction with MAgPIE MADRat tutorial. For more information please see: https://github.com/magpiemodel/tutorials/tree/master/madrat . @@ -14,7 +14,7 @@ License: GPL-3 Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.3 Imports: WDI, countrycode, diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..38e857f --- /dev/null +++ b/Makefile @@ -0,0 +1,46 @@ +.PHONY: help build check test lint lint-all format format-all install docs +.DEFAULT_GOAL = help + +# extracts the help text and formats it nicely +HELP_PARSING = 'm <- readLines("Makefile");\ + m <- grep("\#\#", m, value=TRUE);\ + command <- sub("^([^ ]*) *\#\#(.*)", "\\1", m);\ + help <- sub("^([^ ]*) *\#\#(.*)", "\\2", m);\ + cat(sprintf("%-8s%s", command, help), sep="\n")' + +help: ## Show this help. + @Rscript -e $(HELP_PARSING) + +build: ## Build the package using lucode2::buildLibrary(). You can pass the + ## updateType with 'make build u=3' + Rscript -e 'lucode2::buildLibrary(updateType = "$(u)")' + +check: ## Build documentation and vignettes, run testthat tests, + ## and check if code etiquette is followed using lucode2::check(). + Rscript -e 'lucode2::check()' + +test: ## Run testthat tests + Rscript -e 'devtools::test(show_report = TRUE)' + +lint: ## Check if code etiquette is followed using lucode2::lint(). + ## Only checks files you changed. + Rscript -e 'lucode2::lint()' + +lint-all: ## Check if code etiquette is followed using lucode2::lint(). + ## Checks all files. + Rscript -e 'lucode2::lint(".")' + +format: ## Apply auto-formatting to changed files and lint afterwards. + Rscript -e 'lucode2::autoFormat()' + +format-all: ## Apply auto-formatting to all files and lint afterwards. + Rscript -e 'lucode2::autoFormat(files=list.files("./R", full.names = TRUE, pattern = "\\.R"))' + +install: ## Install the package locally via devtools::install() after + ## generating NAMESPACE and docs (see docs target). + Rscript -e 'roxygen2::roxygenize(); devtools::install(upgrade = "never")' + +docs: ## Generate the package documentation (man/*.Rd files) and + ## NAMESPACE via roxygen2::roxygenize(), view the generated + ## documentation with `?package::function`. + Rscript -e 'roxygen2::roxygenize()' diff --git a/R/mrtutorial-package.R b/R/mrtutorial-package.R new file mode 100644 index 0000000..e173e72 --- /dev/null +++ b/R/mrtutorial-package.R @@ -0,0 +1,4 @@ +# The package documentation is defined in this file. +# You can get it via `library(); ?`. +#' @docType package +"_PACKAGE" diff --git a/R/spatialHeader.R b/R/spatialHeader.R index e1c624a..c1abb50 100644 --- a/R/spatialHeader.R +++ b/R/spatialHeader.R @@ -26,7 +26,7 @@ spatialHeader <- function(mapping) { regionscode <- regionscode(map) reg <- as.character(map$RegionCode) names(reg) <- as.character(map$CountryCode) - iso <- toolGetMapping(type = "cell", name = "CountryToCellMapping.csv")$iso + iso <- toolGetMapping(type = "cell", name = "CountryToCellMapping.csv", where = "mappingfolder")$iso spatialHeader <- paste(reg[iso], seq_along(iso), sep = ".") return(spatialHeader) } diff --git a/README.md b/README.md index 3152d73..5839f9a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Tutorial Package For Madrat Package Library -R package **mrtutorial**, version **0.2.9** +R package **mrtutorial**, version **0.2.10** -[![CRAN status](https://www.r-pkg.org/badges/version/mrtutorial)](https://cran.r-project.org/package=mrtutorial) [![R build status](https://github.com/pik-piam/mrtutorial/workflows/check/badge.svg)](https://github.com/pik-piam/mrtutorial/actions) [![codecov](https://codecov.io/gh/pik-piam/mrtutorial/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrtutorial) [![r-universe](https://pik-piam.r-universe.dev/badges/mrtutorial)](https://pik-piam.r-universe.dev/ui#builds) +[![CRAN status](https://www.r-pkg.org/badges/version/mrtutorial)](https://cran.r-project.org/package=mrtutorial) [![R build status](https://github.com/whitehacker/mrtutorial/workflows/check/badge.svg)](https://github.com/whitehacker/mrtutorial/actions) [![codecov](https://codecov.io/gh/whitehacker/mrtutorial/branch/master/graph/badge.svg)](https://app.codecov.io/gh/whitehacker/mrtutorial) [![r-universe](https://pik-piam.r-universe.dev/badges/mrtutorial)](https://pik-piam.r-universe.dev/builds) ## Purpose and Functionality @@ -38,7 +38,7 @@ In case of questions / problems please contact David Meng-Chuen Chen Date: Thu, 13 Jul 2023 11:20:58 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- DESCRIPTION | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9aa36f5..5c021c5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,28 +1,30 @@ -Package: mrtutorial Type: Package +Package: mrtutorial Title: Tutorial Package For Madrat Package Library -Date: 2023-07-13 Version: 0.2.10 +Date: 2023-07-13 Authors@R: - person("David Meng-Chuen", "Chen", email = "david.chen@pik-potsdam.de", role = c("aut","cre")) -Description: Example package of mr- world libraries, in conjunction with MAgPIE MADRat tutorial. For more information please see: https://github.com/magpiemodel/tutorials/tree/master/madrat . + person("David Meng-Chuen", "Chen", , "david.chen@pik-potsdam.de", role = c("aut", "cre")) +Description: Example package of mr- world libraries, in conjunction with + MAgPIE MADRat tutorial. For more information please see: + https://github.com/magpiemodel/tutorials/tree/master/madrat . +License: GPL-3 Depends: - R(>= 2.10.0), - magclass(>= 3.17), - madrat(>= 2.11.3) -License: GPL-3 -Encoding: UTF-8 -LazyData: true -Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 + R (>= 2.10.0), + madrat (>= 2.11.3), + magclass (>= 3.17) Imports: WDI, countrycode, + dplyr, lucode2, - reshape2, magpiesets, - dplyr, - tidyr, - rlang + reshape2, + rlang, + tidyr Suggests: covr +Encoding: UTF-8 +LazyData: true +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.2.3