Skip to content

Commit

Permalink
Merge branch 'master' into JOSS
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannes Breier authored and Jannes Breier committed Nov 9, 2023
2 parents 308286f + cfad25c commit b23d34c
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '2307608'
ValidationKey: '2336684'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
92 changes: 21 additions & 71 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,92 +6,44 @@ 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

- 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
- name: Set up Pandoc
uses: r-lib/actions/setup-pandoc@v2
- 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@v4
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)
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/lorenzwalthert/precommit
rev: v0.3.2.9013
rev: v0.3.2.9019
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: 'lpjmlkit: Toolkit for Basic LPJmL Handling'
version: 1.1.8
date-released: '2023-07-18'
version: 1.1.9
date-released: '2023-10-06'
abstract: A collection of basic functions to facilitate the work with the Dynamic
Global Vegetation Model (DGVM) Lund-Potsdam-Jena managed Land (LPJmL) hosted at
the Potsdam Institute for Climate Impact Research (PIK). It provides functions for
Expand Down
86 changes: 86 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Contributing to lpjmlkit

Thank you for your interest in contributing to *lpjmlkit*, an open-source R
package for operating LPJmL and processing related data.
We currently prefer contributions in the form of bug reports, feature requests,
and suggestions of code improvements as issues in the
[lpjmlkit GitHub repository](https://github.com/PIK-LPJmL/lpjmlkit/issues).
If you want to contribute code, please follow the instructions below.
Please note that due to our current worflow information on the authorship of
code contributions may get lost.


## Getting Started

Before you start contributing to *lpjmlkit*, here are a few steps to get you
set up:

1. Fork the [lpjmlkit GitHub repository](https://github.com/PIK-LPJmL/lpjmlkit)
to your own GitHub account.
2. Clone your forked repository to your local machine.
```shell
git clone https://github.com/YourUsername/lpjmlkit.git
cd lpjmlkit
```
3. Install the package and its dependencies following the instructions in the
documentation.

Now you're ready to start making contributions!

## Contributing

To contribute to *lpjmlkit*, please follow these steps:

1. Check for existing issues in the
[**issue tracker**](https://github.com/PIK-LPJmL/lpjmlkit/issues) to see if your
contribution idea has already been discussed or reported.
2. If the issue doesn't already exist, create a **new issue** to discuss the
problem or feature you want to address. Be sure to provide as much detail as
possible to help others understand the context and purpose.
3. **Fork the repository** if you haven't already and create a **new branch**
for your contribution.
4. Make your changes in that new branch, following best practices and
adhering to the **coding style** of the project.
5. Write **unit tests** if applicable and ensure that all tests pass.
6. Submit a **pull request (PR)** referencing the issue you created earlier.
Describe your changes, and our team will review it as soon as possible.
7. All discussion threads of the PR need to be resolved before the PR can be merged.

Your contributions will be greatly appreciated and will help make *lpjmlkit*
even better.


## Code Quality
We use the the [**Advanced R Style Guide**](https://style.tidyverse.org/) for R
code.

Furthermore we use the following tools to ensure code quality:
* [**roxygen2**](https://roxygen2.r-lib.org/) for documentation.
* [**testthat**](https://testthat.r-lib.org/) for unit tests.
* [**lintr**](https://lintr.r-lib.org/) for static code analysis.

Please make sure that your code passes all tests and static code analysis before
submitting a pull request.

## Code of Conduct

Please note that by contributing to *lpjmlkit*, you are expected to adhere to
our Code of Conduct. We strive to maintain a welcoming and inclusive community,
and we expect respectful and considerate behavior from all contributors:
* **Be Respectful**: Treat all community members with respect and kindness.
* **Inclusivity**: Ensure that your language and actions are inclusive and
respectful of diversity.
* **Collaboration**: Encourage a collaborative and supportive atmosphere.

We do not tolerate:
* **Harassment**: Any form of harassment, trolling, or offensive behavior.
* **Discrimination**: Discrimination, derogatory comments, or exclusionary
practices.
* **Bullying**: Bullying or aggressive behavior towards others.

Reporting Incidents
If you witness or experience any violations, please report them to
[[email protected]](mailto:[email protected]).
All reports will be handled confidentially and promptly.

Thank you for being part of the *lpjmlkit* community!
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: lpjmlkit
Type: Package
Title: Toolkit for Basic LPJmL Handling
Version: 1.1.8
Version: 1.1.9
Authors@R: c(
person("Jannes", "Breier", , "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9055-6904")),
person("Sebastian","Ostberg", , "[email protected]", role = "aut", comment = c(ORCID = "0000-0002-2368-7015")),
Expand Down Expand Up @@ -54,4 +54,4 @@ Suggests:
sf
Config/testthat/edition: 3
VignetteBuilder: knitr
Date: 2023-07-18
Date: 2023-10-06
90 changes: 45 additions & 45 deletions R/LPJmLMetaData.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ LPJmLMetaData <- R6::R6Class( # nolint
cat(
paste0(spaces,
col_var(
paste0("$", print_fields)
paste0("$", print_fields)
),
" ",
to_char1,
Expand Down Expand Up @@ -106,13 +106,14 @@ LPJmLMetaData <- R6::R6Class( # nolint
)
cat("\n")

# Print information about subset if subsetted
cat(
paste0(
spaces,
col_var("$subset"),
" ",
# Color red if subset.
ifelse(self$subset, col_warn(self$subset), ""),
ifelse(self$subset, col_warn(self$subset), self$subset),
"\n"
)
)
Expand Down Expand Up @@ -170,7 +171,7 @@ LPJmLMetaData <- R6::R6Class( # nolint
# Update cell fields - distinguish between character -> LPJmL C index
# starting from 0 and numeric/integer -> R index starting from 1 -> -1.
if (!is.null(subset$cell) ||
!is.null(subset$lon) || !is.null(subset$lat)) {
!is.null(subset$lon) || !is.null(subset$lat)) {

# Subset of subset$cell, subset$lon or subset$lat always have to be
# accompanied by cell_dimnames.
Expand Down Expand Up @@ -276,39 +277,39 @@ LPJmLMetaData <- R6::R6Class( # nolint
"bigendian" = ifelse(x$endian == "big", TRUE, FALSE),
# "descr" = tolower(x$name), # nolint
"lastyear" = x$header[["firstyear"]] +
x$header[["timestep"]] *
(x$header[["nyear"]] - 1),
x$header[["timestep"]] *
(x$header[["nyear"]] - 1),
"name" = ifelse(is.null(x$name), "LPJDUMMY", x$name)
)) %>%
`[[<-`("order",
switch(as.character(.$order),
`1` = "cellyear",
`2` = "yearcell",
`3` = "cellindex",
`4` = "cellseq",
stop(
paste(
"Invalid order value", sQuote(.$order), "in header"
)
)
)
) %>%
switch(as.character(.$order),
`1` = "cellyear",
`2` = "yearcell",
`3` = "cellindex",
`4` = "cellseq",
stop(
paste(
"Invalid order value", sQuote(.$order), "in header"
)
)
)
) %>%
`[[<-`("datatype",
switch(as.character(.$datatype),
`0` = "byte",
`1` = "short",
`2` = "int",
`3` = "float",
`4` = "double",
stop(
paste(
"Invalid datatype value", sQuote(.$datatype),
"in header"
)
)
)
switch(as.character(.$datatype),
`0` = "byte",
`1` = "short",
`2` = "int",
`3` = "float",
`4` = "double",
stop(
paste(
"Invalid datatype value", sQuote(.$datatype),
"in header"
)
private$init_list(header_to_meta, additional_attributes)
)
)
)
private$init_list(header_to_meta, additional_attributes)

} else {
private$init_list(x, additional_attributes)
Expand Down Expand Up @@ -574,19 +575,19 @@ LPJmLMetaData <- R6::R6Class( # nolint
"filename"
) %>%

# Only append scalar if != 1
append(
ifelse(
!is.null(private$.scalar),
ifelse(private$.scalar == 1, "scalar", NA),
NA
)
) %>%
# Only append scalar if != 1
append(
ifelse(
!is.null(private$.scalar),
ifelse(private$.scalar == 1, "scalar", NA),
NA
)
) %>%

# Workaround to deal with NAs (NULL not possible in ifelse)
stats::na.omit() %>%
as.vector() %>%
return()
# Workaround to deal with NAs (NULL not possible in ifelse)
stats::na.omit() %>%
as.vector() %>%
return()
},

.sim_name = NULL,
Expand Down Expand Up @@ -681,8 +682,7 @@ LPJmLMetaData <- R6::R6Class( # nolint
"name",
"map",
"version",
"offset"
),
"offset"),

.dimension_map = list(space_format = c("cell", "lon_lat"),
time_format = c("time", "year_month_day"),
Expand Down
Loading

0 comments on commit b23d34c

Please sign in to comment.