diff --git a/.buildlibrary b/.buildlibrary index 15f74d3..1c88679 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,7 +1,8 @@ -ValidationKey: '4105710' +ValidationKey: '4182653' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' AcceptedNotes: ~ AutocreateReadme: yes allowLinterWarnings: yes +enforceVersionUpdate: no diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index fcd7136..f6ea5d4 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -1,5 +1,3 @@ -# Run CI for R using https://eddelbuettel.github.io/r-ci/ - name: check on: @@ -8,96 +6,53 @@ on: pull_request: branches: [main, master] -env: - USE_BSPM: "true" - _R_CHECK_FORCE_SUGGESTS_: "false" - NO_BINARY_INSTALL_R_PACKAGES: 'c("madrat", "magclass", "citation", "gms", "goxygen", "GDPuc", "roxygen2")' - jobs: check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - name: Bootstrap - run: | - sudo chown runner -R . - sudo locale-gen en_US.UTF-8 - sudo add-apt-repository -y ppa:ubuntugis/ppa - 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: | - # install packages from https://pik-piam.r-universe.dev and CRAN - echo ' - options(repos = c(universe = "https://pik-piam.r-universe.dev", - CRAN = "https://cloud.r-project.org")) - ' >> .Rprofile - cat .Rprofile - # modify bspm integration to never install binary builds of PIK CRAN packages - sudo sed -i '/bspm::enable()/d' /etc/R/Rprofile.site - # need double % because of printf, %s is replaced with "$NO_BINARY_INSTALL_R_PACKAGES" (see "env:" above) - printf ' - local({ - expr <- quote({ - if (!is.null(repos)) { - noBinaryInstallRPackages <- %s - 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@v2 - - name: Set up Pandoc - uses: r-lib/actions/setup-pandoc@v2 - - - name: Set up Python 3.9 - uses: actions/setup-python@v4 + - uses: r-lib/actions/setup-r@v2 with: - python-version: 3.9 + use-public-rspm: true + extra-repositories: "https://rse.pik-potsdam.de/r/packages" - - name: Cache R libraries - if: ${{ !env.ACT }} # skip when running locally via nektos/act - uses: pat-s/always-upload-cache@v3 + - uses: r-lib/actions/setup-r-dependencies@v2 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 libharfbuzz-dev libfribidi-dev - ./run.sh install_all - ./run.sh install_r_binary covr rstudioapi - ./run.sh install_r lucode2 + extra-packages: | + any::lucode2 + any::covr + any::madrat + any::magclass + any::citation + any::gms + any::goxygen + any::GDPuc + # piam packages also available on CRAN (madrat, magclass, citation, + # gms, goxygen, GDPuc) will usually have an outdated binary version + # available; by using extra-packages we get the newest version + + - uses: actions/setup-python@v5 + with: + python-version: 3.9 - 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: | - sudo sed -i '/ trace(utils::install.packages, expr, print = FALSE)/d' /etc/R/Rprofile.site - cat /etc/R/Rprofile.site - - name: Verify validation key shell: Rscript {0} run: lucode2:::validkey(stopIfInvalid = TRUE) + - name: Verify that lucode2::buildLibrary was successful + if: github.event_name == 'pull_request' + shell: Rscript {0} + run: lucode2:::isVersionUpdated() + - name: Checks shell: Rscript {0} run: | @@ -106,6 +61,8 @@ jobs: - name: Test coverage shell: Rscript {0} - run: covr::codecov(quiet = FALSE) + run: | + nonDummyTests <- setdiff(list.files("./tests/testthat/"), c("test-dummy.R", "_snaps")) + if(length(nonDummyTests) > 0) covr::codecov(quiet = FALSE) env: NOT_CRAN: "true" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9c3b069..243f46a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ exclude: '^tests/testthat/_snaps/.*$' repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-case-conflict - id: check-json @@ -15,7 +15,7 @@ repos: - id: mixed-line-ending - repo: https://github.com/lorenzwalthert/precommit - rev: v0.3.2.9013 + rev: v0.4.0 hooks: - id: parsable-R - id: deps-in-desc diff --git a/CITATION.cff b/CITATION.cff index ece337c..a38c779 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,8 +2,8 @@ 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' +version: 0.2.11 +date-released: '2024-04-10' 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 .' diff --git a/DESCRIPTION b/DESCRIPTION index 6ec30f1..3dc1423 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mrtutorial Title: Tutorial Package For Madrat Package Library -Version: 0.2.10 -Date: 2023-07-13 +Version: 0.2.11 +Date: 2024-04-10 Authors@R: person("David Meng-Chuen", "Chen", , "david.chen@pik-potsdam.de", role = c("aut", "cre")) Description: Example package of mr- world libraries, in conjunction with diff --git a/R/downloadTutorialWDI.R b/R/downloadTutorialWDI.R index 9c60a43..bff3baf 100644 --- a/R/downloadTutorialWDI.R +++ b/R/downloadTutorialWDI.R @@ -19,12 +19,13 @@ downloadTutorialWDI<-function(){ "NV.AGR.TOTL.CD") # Ag GDP current US$ wdi <- WDI(indicator = indicator,start= 1960, end = 2018) save(wdi,file = paste("WDI","rda",sep=".")) - + return(list(url = "https://data.worldbank.org/indicator/", doi = NULL, title = "World Bank Development Indicators", description = "GDP and Population indicators", author = NULL, + license = NULL, unit = NULL)) - + } diff --git a/R/imports.R b/R/imports.R index f00e622..318c0d5 100644 --- a/R/imports.R +++ b/R/imports.R @@ -1,4 +1,4 @@ # Generated by lucode2: do not edit by hand -#' @import magclass madrat +#' @import madrat magclass NULL diff --git a/R/readTutorialWDI.R b/R/readTutorialWDI.R index cb42ff2..85c7e95 100644 --- a/R/readTutorialWDI.R +++ b/R/readTutorialWDI.R @@ -22,20 +22,22 @@ #' @importFrom magclass as.magpie #' @importFrom rlang .data -readTutorialWDI<-function(subtype){ +readTutorialWDI<-function(subtype = "SP.POP.TOTL"){ load("WDI.rda") - #convert the iso2c to iso3c using madrat tool - wdi$iso2c <- toolCountry2isocode(wdi$iso2c) - + #clean up: remove other country ids, remove rows with NAs as country, + #pivot to long format and convert to magclass object wdi <- wdi %>% - dplyr::select(!.data$country) %>% - filter(!is.na(.data$iso2c)) %>% - pivot_longer(cols=3:6) %>% + dplyr::select(!c(.data$country, .data$iso2c)) %>% + filter(!is.na(.data$iso3c), .data$iso3c != "") %>% + pivot_longer(cols = c("NY.GDP.MKTP.CD", "SP.POP.TOTL", + "SL.AGR.EMPL.ZS", "NV.AGR.TOTL.CD"), + names_to = "variable") %>% as.magpie(spatial = 1, temporal = 2, replacement =".") - wdi <- wdi[,,subtype] + #select the subtype + wdi <- wdi[, , subtype] getNames(wdi) <- gsub("\\.", "_", getNames(wdi)) # Replacement of . with _ in dimension is also done automatically in as.magpie() diff --git a/README.md b/README.md index 5839f9a..b395537 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ # Tutorial Package For Madrat Package Library -R package **mrtutorial**, version **0.2.10** +R package **mrtutorial**, version **0.2.11** -[![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) +[![CRAN status](https://www.r-pkg.org/badges/version/mrtutorial)](https://cran.r-project.org/package=mrtutorial) [![R build status](https://github.com/caviddhen/mrtutorial/workflows/check/badge.svg)](https://github.com/caviddhen/mrtutorial/actions) [![codecov](https://codecov.io/gh/caviddhen/mrtutorial/branch/master/graph/badge.svg)](https://app.codecov.io/gh/caviddhen/mrtutorial) [![r-universe](https://pik-piam.r-universe.dev/badges/mrtutorial)](https://pik-piam.r-universe.dev/builds) ## Purpose and Functionality -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 . +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 . ## Installation @@ -38,7 +40,7 @@ In case of questions / problems please contact David Meng-Chuen Chen