diff --git a/.buildlibrary b/.buildlibrary index 27133bc7..7f8ae62f 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,8 +1,7 @@ -ValidationKey: '11447946' +ValidationKey: '11489376' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' AcceptedNotes: unable to verify current time AutocreateReadme: yes -UseGithubActions: yes allowLinterWarnings: yes diff --git a/.github/workflows/lucode2-check.yaml b/.github/workflows/lucode2-check.yaml new file mode 100644 index 00000000..7fd98b15 --- /dev/null +++ b/.github/workflows/lucode2-check.yaml @@ -0,0 +1,79 @@ +# Run CI for R using https://eddelbuettel.github.io/r-ci/ + +name: lucode2-check + +on: + push: + branches: [main, master] + 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")' + +jobs: + lucode2-check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Bootstrap + run: | + curl -OLs https://eddelbuettel.github.io/r-ci/run.sh + chmod 0755 run.sh + ./run.sh bootstrap + + - 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]) + } + }) + 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: Install dependencies + run: | + ./run.sh install_aptget libhdf5-dev + ./run.sh install_all + ./run.sh install_r lucode2 covr + + - 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: Checks + shell: Rscript {0} + run: | + options(crayon.enabled = TRUE) + lucode2::check(runLinter = FALSE) + + - name: Test coverage + shell: Rscript {0} + run: covr::codecov(quiet = FALSE) diff --git a/.github/workflows/test-buildlibrary.yaml b/.github/workflows/test-buildlibrary.yaml deleted file mode 100644 index 3626412c..00000000 --- a/.github/workflows/test-buildlibrary.yaml +++ /dev/null @@ -1,67 +0,0 @@ -on: - push: - branches: - - main - - master - pull_request: - branches: - - main - - master - -name: check - -jobs: - check: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@v1 - - - uses: r-lib/actions/setup-pandoc@v1 - - - name: Install dependencies - run: | - sudo apt-get install libcurl4-openssl-dev libgit2-dev libnetcdf-dev libudunits2-dev - - - name: Query dependencies - run: | - install.packages('remotes') - repos <- c("https://cloud.r-project.org","https://rse.pik-potsdam.de/r/packages/") - saveRDS(remotes::dev_package_deps(dependencies = TRUE, repos=repos), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") - shell: Rscript {0} - - - name: Cache R packages - uses: actions/cache@v2 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install R dependencies - run: | - repos <- c("https://cloud.r-project.org","https://rse.pik-potsdam.de/r/packages/") - install.packages(c("remotes"), repos=repos) - deps <- remotes::dev_package_deps(dependencies = TRUE, repos=repos) - missing <- deps[is.na(deps$available),] - if(dim(missing)[1]>0) { - if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") - BiocManager::install(missing$package) - } - remotes::install_deps(dependencies = TRUE, repos=repos) - remotes::install_cran(c("devtools","covr","lucode2"), repos=repos) - shell: Rscript {0} - - - name: Run tests - run: devtools::test(stop_on_failure = TRUE) - shell: Rscript {0} - - - name: Test coverage - run: covr::codecov(quiet = FALSE) - shell: Rscript {0} - - - name: Validation key - run: if(!lucode2:::validkey()$valid) stop("Invalid build key!") - shell: Rscript {0} - diff --git a/.zenodo.json b/.zenodo.json index 166a3edb..7621bfde 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -1,6 +1,6 @@ { "title": "magclass: Data Class and Tools for Handling Spatial-Temporal Data", - "version": "6.0.6", + "version": "6.0.8", "description": "

Data class for increased interoperability working with spatial-\n temporal data together with corresponding functions and methods (conversions,\n basic calculations and basic data manipulation). The class distinguishes\n between spatial, temporal and other dimensions to facilitate the development\n and interoperability of tools build for it. Additional features are name-based\n addressing of data and internal consistency checks (e.g. checking for the right\n data order in calculations).<\/p>", "creators": [ { diff --git a/DESCRIPTION b/DESCRIPTION index 0a451bfb..055693ab 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: magclass Type: Package Title: Data Class and Tools for Handling Spatial-Temporal Data -Version: 6.0.6 -Date: 2021-09-21 +Version: 6.0.8 +Date: 2021-09-27 Authors@R: c(person("Jan Philipp", "Dietrich", email = "dietrich@pik-potsdam.de", role = c("aut","cre")), person("Benjamin Leon", "Bodirsky", email = "bodirsky@pik-potsdam.de", role = "aut"), person("Markus", "Bonsch", role = "aut"), @@ -51,5 +51,5 @@ BugReports: https://github.com/pik-piam/magclass/issues License: LGPL-3 | file LICENSE LazyData: true Encoding: UTF-8 -RoxygenNote: 7.1.1 +RoxygenNote: 7.1.2 VignetteBuilder: knitr diff --git a/R/write.magpie.R b/R/write.magpie.R index 06d72015..82e57e25 100644 --- a/R/write.magpie.R +++ b/R/write.magpie.R @@ -80,7 +80,7 @@ #' [ sets | Set names with \\n as delimiter | character | 1*nchar_sets Byte] \cr #' [ metadata | serialized metadata information (currently not in use) | bytes | 1*nbyte_metadata Byte] \cr #' -#' @author Jan Philipp Dietrich, Stephen Bi +#' @author Jan Philipp Dietrich, Stephen Bi, Florian Humpenoeder #' @seealso \code{"\linkS4class{magpie}"}, #' \code{\link{read.magpie}},\code{\link{mbind}} #' @examples @@ -197,15 +197,26 @@ write.magpie <- function(x, file_name, file_folder = "", file_type = NULL, appen varnames <- getItems(x, dim = 3) zunit <- ifelse(all(isYear(getYears(x))), "years", "") if (is.null(varnames)) varnames <- "Variable" + if (is.null(comment)) { + unit <- "not specified" + } else { + indicators <- substring(text = comment, first = 1, last = regexpr(pattern = ": ", text = comment) - 1) + units <- substring(text = comment, first = (regexpr(pattern = ": ", text = comment) + 2)) + if (!any(indicators == "unit")) { + unit <- "not specified" + } else { + unit <- units[which(indicators == "unit")] + } + } raster::writeRaster(.sub(rx, varnames[1]), filename = filePath, format = "CDF", overwrite = TRUE, - compression = 9, zname = "Time", zunit = zunit, varname = varnames[1], ...) + compression = 9, zname = "Time", zunit = zunit, varname = varnames[1], varunit = unit, ...) nc <- ncdf4::nc_open(filePath, write = TRUE) if (zunit == "years") { ncdf4::ncvar_put(nc, "Time", getYears(x, as.integer = TRUE)) } if (length(varnames) > 1) { for (i in varnames[-1]) { - nc <- ncdf4::ncvar_add(nc, ncdf4::ncvar_def(i, "", nc$dim, compression = 9)) + nc <- ncdf4::ncvar_add(nc, ncdf4::ncvar_def(i, unit, nc$dim, compression = 9)) ncdf4::ncvar_put(nc, i, aperm(as.array(.sub(rx, i)), c(2, 1, 3))) } } diff --git a/README.md b/README.md index c566ccec..cca98e23 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Data Class and Tools for Handling Spatial-Temporal Data -R package **magclass**, version **6.0.6** +R package **magclass**, version **6.0.8** -[![CRAN status](https://www.r-pkg.org/badges/version/magclass)](https://cran.r-project.org/package=magclass) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1158580.svg)](https://doi.org/10.5281/zenodo.1158580) [![R build status](https://github.com/pik-piam/magclass/workflows/check/badge.svg)](https://github.com/pik-piam/magclass/actions) [![codecov](https://codecov.io/gh/pik-piam/magclass/branch/master/graph/badge.svg)](https://codecov.io/gh/pik-piam/magclass) [![r-universe](https://pik-piam.r-universe.dev/badges/magclass)](https://pik-piam.r-universe.dev/ui#builds) +[![CRAN status](https://www.r-pkg.org/badges/version/magclass)](https://cran.r-project.org/package=magclass) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1158580.svg)](https://doi.org/10.5281/zenodo.1158580) [![R build status](https://github.com/pik-piam/magclass/workflows/check/badge.svg)](https://github.com/pik-piam/magclass/actions) [![codecov](https://codecov.io/gh/pik-piam/magclass/branch/master/graph/badge.svg)](https://codecov.io/gh/pik-piam/magclass) [![r-universe](https://pik-piam.r-universe.dev/badges/magclass)](https://pik-piam.r-universe.dev/ui#builds) ## Purpose and Functionality @@ -55,7 +55,7 @@ In case of questions / problems please contact Jan Philipp Dietrich . +Dietrich J, Bodirsky B, Bonsch M, Humpenoeder F, Bi S, Karstens K, Leip D (2021). _magclass: Data Class and Tools for Handling Spatial-Temporal Data_. doi: 10.5281/zenodo.1158580 (URL: https://doi.org/10.5281/zenodo.1158580), R package version 6.0.8, . A BibTeX entry for LaTeX users is @@ -64,7 +64,7 @@ A BibTeX entry for LaTeX users is title = {magclass: Data Class and Tools for Handling Spatial-Temporal Data}, author = {Jan Philipp Dietrich and Benjamin Leon Bodirsky and Markus Bonsch and Florian Humpenoeder and Stephen Bi and Kristine Karstens and Debbora Leip}, year = {2021}, - note = {R package version 6.0.6}, + note = {R package version 6.0.8}, doi = {10.5281/zenodo.1158580}, url = {https://github.com/pik-piam/magclass}, } diff --git a/man/write.magpie.Rd b/man/write.magpie.Rd index 3c7b97b1..311e6150 100644 --- a/man/write.magpie.Rd +++ b/man/write.magpie.Rd @@ -117,5 +117,5 @@ read.magpie/write.magpie functions in other languages): \cr \cr \code{\link{read.magpie}},\code{\link{mbind}} } \author{ -Jan Philipp Dietrich, Stephen Bi +Jan Philipp Dietrich, Stephen Bi, Florian Humpenoeder }