Skip to content

Commit a577694

Browse files
authored
Merge pull request #8 from pik-piam/patch/minor-coding-style-improvements
Minor stylistic code changes to improve readability throughout the tutorial
2 parents e2c55ab + 00cee0d commit a577694

21 files changed

Lines changed: 70 additions & 72 deletions

.buildlibrary

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
ValidationKey: '4182653'
1+
ValidationKey: '4296180'
22
AcceptedWarnings:
33
- 'Warning: package ''.*'' was built under R version'
44
- 'Warning: namespace ''.*'' is not available and has been replaced'
55
AcceptedNotes: ~
66
AutocreateReadme: yes
77
allowLinterWarnings: yes
88
enforceVersionUpdate: no
9+
AutocreateCITATION: yes
10+
skipCoverage: no

.github/workflows/check.yaml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,24 @@ jobs:
2323
- uses: r-lib/actions/setup-r-dependencies@v2
2424
with:
2525
extra-packages: |
26-
any::lucode2
27-
any::covr
28-
any::madrat
29-
any::magclass
30-
any::citation
31-
any::gms
32-
any::goxygen
33-
any::GDPuc
26+
lucode2
27+
covr
28+
madrat
29+
magclass
30+
citation
31+
gms
32+
goxygen
33+
GDPuc
3434
# piam packages also available on CRAN (madrat, magclass, citation,
3535
# gms, goxygen, GDPuc) will usually have an outdated binary version
3636
# available; by using extra-packages we get the newest version
3737

38-
- uses: actions/setup-python@v5
39-
with:
40-
python-version: 3.9
41-
42-
- name: Install python dependencies if applicable
38+
- name: Run pre-commit checks
39+
shell: bash
4340
run: |
44-
[ -f requirements.txt ] && python -m pip install --upgrade pip wheel || true
45-
[ -f requirements.txt ] && pip install -r requirements.txt || true
41+
python -m pip install pre-commit
42+
python -m pip freeze --local
43+
pre-commit run --show-diff-on-failure --color=always --all-files
4644
4745
- name: Verify validation key
4846
shell: Rscript {0}
@@ -63,6 +61,6 @@ jobs:
6361
shell: Rscript {0}
6462
run: |
6563
nonDummyTests <- setdiff(list.files("./tests/testthat/"), c("test-dummy.R", "_snaps"))
66-
if(length(nonDummyTests) > 0) covr::codecov(quiet = FALSE)
64+
if(length(nonDummyTests) > 0 && !lucode2:::loadBuildLibraryConfig()[["skipCoverage"]]) covr::codecov(quiet = FALSE)
6765
env:
6866
NOT_CRAN: "true"

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exclude: '^tests/testthat/_snaps/.*$'
44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.5.0
6+
rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0
77
hooks:
88
- id: check-case-conflict
99
- id: check-json
@@ -15,7 +15,7 @@ repos:
1515
- id: mixed-line-ending
1616

1717
- repo: https://github.com/lorenzwalthert/precommit
18-
rev: v0.4.0
18+
rev: 3b70240796cdccbe1474b0176560281aaded97e6 # frozen: v0.4.3.9003
1919
hooks:
2020
- id: parsable-R
2121
- id: deps-in-desc
@@ -25,4 +25,4 @@ repos:
2525
- id: readme-rmd-rendered
2626
- id: use-tidy-description
2727
ci:
28-
autoupdate_schedule: quarterly
28+
autoupdate_schedule: weekly

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ cff-version: 1.2.0
22
message: If you use this software, please cite it using the metadata from this file.
33
type: software
44
title: 'mrtutorial: Tutorial Package For Madrat Package Library'
5-
version: 0.2.11
6-
date-released: '2024-04-10'
5+
version: 0.2.12
6+
date-released: '2025-06-26'
77
abstract: 'Example package of mr- world libraries, in conjunction with MAgPIE MADRat
88
tutorial. For more information please see: https://github.com/magpiemodel/tutorials/tree/master/madrat
99
.'

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Type: Package
22
Package: mrtutorial
33
Title: Tutorial Package For Madrat Package Library
4-
Version: 0.2.11
5-
Date: 2024-04-10
4+
Version: 0.2.12
5+
Date: 2025-06-26
66
Authors@R:
77
person("David Meng-Chuen", "Chen", , "david.chen@pik-potsdam.de", role = c("aut", "cre"))
88
Description: Example package of mr- world libraries, in conjunction with
@@ -26,4 +26,4 @@ Suggests:
2626
Encoding: UTF-8
2727
LazyData: true
2828
Roxygen: list(markdown = TRUE)
29-
RoxygenNote: 7.2.3
29+
RoxygenNote: 7.3.2

R/calcAgGDP.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ calcAgGDP <- function(){
1818

1919
ag_gdp <- readSource("TutorialWDI", subtype="NV.AGR.TOTL.CD")
2020

21-
x <- ag_gdp/gdp
21+
x <- ag_gdp / gdp
2222
x <- collapseNames(x)
2323
getNames(x) <- "Ag_GDP_share"
2424

R/calcValidPopulation.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
calcValidPopulation <- function(datasource="WDI") {
1010

11-
if(datasource=="WDI"){
12-
11+
if (datasource == "WDI") {
1312
out <- readSource("TutorialWDI", "SP.POP.TOTL")
13+
} else {
14+
stop("No datasource of the given name.")
15+
}
1416

15-
} else { stop("No datasource of the given name.") }
16-
17-
getNames(out) <- "Population (million people)"
18-
getSets(out,fulldim = FALSE)[3] <- "variable"
17+
getNames(out) <- "Population (million people)"
18+
getSets(out, fulldim = FALSE)[3] <- "variable"
1919

2020
out <- add_dimension(out, dim=3.1, add="scenario", nm = "historical")
2121
out <- add_dimension(out, dim=3.2, add="model", nm = datasource)

R/convertTutorialWDI.R

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,25 @@
1717
#' @importFrom madrat toolCountryFill
1818

1919

20-
convertTutorialWDI<-function(x, subtype){
20+
convertTutorialWDI <- function(x, subtype) {
2121

2222
# change scale of absolute indicators, MAgPIE runs in Million scale for Pop and GDP drivers
23-
if (subtype %in% c("NY.GDP.MKTP.CD",
23+
if (subtype %in% c("NY.GDP.MKTP.CD",
2424
"SP.POP.TOTL",
25-
"NV.AGR.TOTL.CD")){
26-
27-
out <- x/1e6 } else
28-
29-
if (subtype == "SL.AGR.EMPL.ZS"){
30-
# don't change for percentage of ag employment
31-
32-
out <- x } else{
33-
34-
stop("subtype does not exist in the dataset!")}
25+
"NV.AGR.TOTL.CD")) {
26+
out <- x/1e6
27+
} else if (subtype == "SL.AGR.EMPL.ZS") {
28+
# don't change for percentage of ag employment
29+
out <- x
30+
} else {
31+
stop("subtype does not exist in the dataset!")
32+
}
3533

3634
# toolCountryFill fills in missing countries - 249 required for aggregation
35+
x <- toolCountryFill(out, fill = 0)
3736

38-
x<-toolCountryFill(out,fill = 0)
39-
40-
x[is.na(x)] <- 0 #remove NAs
41-
37+
#remove NAs
38+
x[is.na(x)] <- 0
4239

4340
return(x)
4441
}

R/downloadTutorialWDI.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#' Download WDI (World development indicators) data .rda file.
44
#'
55
#' @author David Chen
6-
#' @seealso \code{\link{downloadSource}} \code{\link{WDI}}
6+
#' @seealso \code{\link[madrat]{downloadSource}} \code{\link[WDI]{WDI}}
77
#' @examples
88
#'
99
#' \dontrun{ a <- downloadSource(type="TutorialWDI")
@@ -12,20 +12,20 @@
1212
#' @importFrom WDI WDI WDIcache WDIsearch
1313

1414

15-
downloadTutorialWDI<-function(){
15+
downloadTutorialWDI <- function() {
1616
indicator <- c("NY.GDP.MKTP.CD", # gdp PPP current US$
17-
"SP.POP.TOTL", # Total population
18-
"SL.AGR.EMPL.ZS", #Employment in agriculture as % of total employment
17+
"SP.POP.TOTL", # Total population
18+
"SL.AGR.EMPL.ZS", # Employment in agriculture as % of total employment
1919
"NV.AGR.TOTL.CD") # Ag GDP current US$
20-
wdi <- WDI(indicator = indicator,start= 1960, end = 2018)
21-
save(wdi,file = paste("WDI","rda",sep="."))
20+
wdi <- WDI(indicator = indicator, start = 1960, end = 2018)
21+
save(wdi, file = paste("WDI", "rda", sep = "."))
2222

2323
return(list(url = "https://data.worldbank.org/indicator/",
2424
doi = NULL,
2525
title = "World Bank Development Indicators",
2626
description = "GDP and Population indicators",
2727
author = NULL,
28-
license = NULL,
28+
license = NULL,
2929
unit = NULL))
3030

3131
}

R/fullTUTORIAL.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#' @param extra extra text to insert
99
#' @author David M Chen
1010
#' @seealso
11-
#' \code{\link{readSource}}, \code{\link{getCalculations}}, \code{\link{calcOutput}}
11+
#' \code{\link[madrat]{readSource}}, \code{\link[madrat]{getCalculations}}, \code{\link[madrat]{calcOutput}}
1212
#' @examples
1313
#' \dontrun{
1414
#' retrieveData("tutorial", rev = numeric_version("12"),

0 commit comments

Comments
 (0)