Skip to content

Commit

Permalink
update for workshop 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
David Chen committed Apr 10, 2024
1 parent 08317b7 commit a474bb9
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 101 deletions.
3 changes: 2 additions & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -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
103 changes: 30 additions & 73 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Run CI for R using https://eddelbuettel.github.io/r-ci/

name: check

on:
Expand All @@ -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: |
Expand All @@ -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"
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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
.'
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre"))
Description: Example package of mr- world libraries, in conjunction with
Expand Down
5 changes: 3 additions & 2 deletions R/downloadTutorialWDI.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))

}
2 changes: 1 addition & 1 deletion R/imports.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by lucode2: do not edit by hand

#' @import magclass madrat
#' @import madrat magclass
NULL
18 changes: 10 additions & 8 deletions R/readTutorialWDI.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -38,15 +40,15 @@ In case of questions / problems please contact David Meng-Chuen Chen <david.chen

To cite package **mrtutorial** in publications use:

Chen D (2023). _mrtutorial: Tutorial Package For Madrat Package Library_. R package version 0.2.10.
Chen D (2024). _mrtutorial: Tutorial Package For Madrat Package Library_. R package version 0.2.11.

A BibTeX entry for LaTeX users is

```latex
@Manual{,
title = {mrtutorial: Tutorial Package For Madrat Package Library},
author = {David Meng-Chuen Chen},
year = {2023},
note = {R package version 0.2.10},
year = {2024},
note = {R package version 0.2.11},
}
```
7 changes: 4 additions & 3 deletions man/fullTUTORIAL.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/readTutorialWDI.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a474bb9

Please sign in to comment.