Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed tests #173

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '6547240'
ValidationKey: '6567456'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
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: 'madrat: May All Data be Reproducible and Transparent (MADRaT) *'
version: 3.3.5
date-released: '2023-07-06'
version: 3.3.6
date-released: '2023-07-08'
abstract: Provides a framework which should improve reproducibility and transparency
in data processing. It provides functionality such as automatic meta data creation
and management, rudimentary quality management, data caching, work-flow management
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: madrat
Title: May All Data be Reproducible and Transparent (MADRaT) *
Version: 3.3.5
Date: 2023-07-06
Version: 3.3.6
Date: 2023-07-08
Authors@R: c(
person("Jan Philipp", "Dietrich", , "dietrich@pik-potsdam.de", role = c("aut", "cre")),
person("Lavinia", "Baumstark", , "lavinia@pik-potsdam.de", role = "aut"),
Expand Down
38 changes: 20 additions & 18 deletions R/metadataGFZ.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
#' metadataGFZ
#'
#' Function to extract metadata information of a data set hosted at GFZ dataservices
#'
#' Function to extract metadata information of a data set hosted at GFZ dataservices
#' (https://dataservices.gfz-potsdam.de/portal/).
#'
#'
#'
#'
#' @param doi DOI of a data set hosted at GFZ dataservices
#' @return a list with entries "license", "citation", "authors" and "year"
#' @author Jan Philipp Dietrich
#' @seealso \code{\link{toolstartmessage}}, \code{\link{vcat}}
#' @examples
#'
#' \dontrun{
#' metadataGFZ("10.5880/pik.2019.004")
#' }
#' @export

metadataGFZ <- function(doi) {
if (is.null(doi)) return(NULL)
if (!grepl("10.5880",doi, fixed = TRUE)) stop("DOI does not belong to a GFZ dataservice entry")
if (!grepl("http", doi)) doi <- paste0("http://doi.org/",doi)
if (!grepl("10.5880", doi, fixed = TRUE)) stop("DOI does not belong to a GFZ dataservice entry")
if (!grepl("http", doi)) doi <- paste0("http://doi.org/", doi)
file <- tempfile()
download.file(doi,file, quiet = TRUE)
status <- try(download.file(doi, file, quiet = TRUE))
if (inherits(status, "try-error")) {
download.file(doi, file, method = "wget", extra = "--no-check-certificate", quiet = TRUE)
}
x <- readLines(file)
unlink(file)
o <- list()
Expand All @@ -29,22 +31,22 @@ metadataGFZ <- function(doi) {
warning("Cannot extract citation, return NULL")
o$citation <- NULL
} else {
o$citation <- sub("^.*class=\"citationtext\">([^<]*).*$","\\1", o$citation)
o$authors <- strsplit(sub(" \\(.*$","",o$citation),"; ")[[1]]
o$citation <- sub("^.*class=\"citationtext\">([^<]*).*$", "\\1", o$citation)
o$authors <- strsplit(sub(" \\(.*$", "", o$citation), "; ")[[1]]
.person <- function(x) {
x <- strsplit(x,", ")[[1]]
return(person(x[2],x[1]))
x <- strsplit(x, ", ")[[1]]
return(person(x[2], x[1]))
}
o$authors <- do.call(c,lapply(o$authors,.person))
o$year <- sub("^.*\\((.*)\\).*$","\\1",o$citation)
o$authors <- do.call(c, lapply(o$authors, .person))
o$year <- sub("^.*\\((.*)\\).*$", "\\1", o$citation)
}
find_license <- grep("License:", x, fixed = TRUE)
if (length(find_license) != 1) {
findLicense <- grep("License:", x, fixed = TRUE)
if (length(findLicense) != 1) {
warning("Cannot extract license, return NULL")
o$license <- NULL
} else {
o$license <- x[find_license + 1]
o$license <- sub("^[^>]*>([^<]*).*$","\\1",o$license)
o$license <- x[findLicense + 1]
o$license <- sub("^[^>]*>([^<]*).*$", "\\1", o$license)
}
return(o)
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# May All Data be Reproducible and Transparent (MADRaT) *

R package **madrat**, version **3.3.5**
R package **madrat**, version **3.3.6**

[![CRAN status](https://www.r-pkg.org/badges/version/madrat)](https://cran.r-project.org/package=madrat) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1115490.svg)](https://doi.org/10.5281/zenodo.1115490) [![R build status](https://github.com/pik-piam/madrat/workflows/check/badge.svg)](https://github.com/pik-piam/madrat/actions) [![codecov](https://codecov.io/gh/pik-piam/madrat/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/madrat) [![r-universe](https://pik-piam.r-universe.dev/badges/madrat)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -55,7 +55,7 @@ In case of questions / problems please contact Jan Philipp Dietrich <dietrich@pi

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

Dietrich J, Baumstark L, Wirth S, Giannousakis A, Rodrigues R, Bodirsky B, Kreidenweis U, Klein D, Führlich P (2023). _madrat: May All Data be Reproducible and Transparent (MADRaT)_. doi: 10.5281/zenodo.1115490 (URL: https://doi.org/10.5281/zenodo.1115490), R package version 3.3.5, <URL: https://github.com/pik-piam/madrat>.
Dietrich J, Baumstark L, Wirth S, Giannousakis A, Rodrigues R, Bodirsky B, Kreidenweis U, Klein D, Führlich P (2023). _madrat: May All Data be Reproducible and Transparent (MADRaT)_. doi: 10.5281/zenodo.1115490 (URL: https://doi.org/10.5281/zenodo.1115490), R package version 3.3.6, <URL: https://github.com/pik-piam/madrat>.

A BibTeX entry for LaTeX users is

Expand All @@ -64,7 +64,7 @@ A BibTeX entry for LaTeX users is
title = {madrat: May All Data be Reproducible and Transparent (MADRaT)},
author = {Jan Philipp Dietrich and Lavinia Baumstark and Stephen Wirth and Anastasis Giannousakis and Renato Rodrigues and Benjamin Leon Bodirsky and Ulrich Kreidenweis and David Klein and Pascal Führlich},
year = {2023},
note = {R package version 3.3.5},
note = {R package version 3.3.6},
doi = {10.5281/zenodo.1115490},
url = {https://github.com/pik-piam/madrat},
}
Expand Down
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## CHANGES
* fixed msentropy-related error on r-revel machines on CRAN
* fixed msentropy-related error currently showing up on r-revel machines on CRAN

## Test environments
* local R installation, R 4.1.2
Expand Down
3 changes: 1 addition & 2 deletions man/metadataGFZ.Rd

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

1 change: 1 addition & 0 deletions tests/testthat/test-metadataGFZ.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
test_that("metadata can be extracted from GFZ dataservice", {
skip_on_cran()
skip("Currently SSL problems on remote server")
skip_if_offline("doi.org")
expect_silent({
m <- metadataGFZ("10.5880/pik.2019.004")
Expand Down
12 changes: 8 additions & 4 deletions tests/testthat/test-toolTimeAverage.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
p <- magclass::maxample("pop")
p[, , ] <- 1
getYears(p) <- 1900 + seq_len(nyears(p))
nc <- function(x) {
getComment(x) <- NULL
return(x)
}

test_that("Proper detection of time step completness", {
expect_equivalent(toolTimeAverage(p, averaging_range = 1, cut = FALSE), p)
expect_equivalent(nc(toolTimeAverage(p, averaging_range = 1, cut = FALSE)), nc(p))
})

test_that("Averaging works properly for trivial case", {
expect_equivalent(toolTimeAverage(p, averaging_range = 4, cut = FALSE), p)
expect_equivalent(nc(toolTimeAverage(p, averaging_range = 4, cut = FALSE)), nc(p))
})

test_that("Averaging works independent of time step length", {
p2 <- p3 <- magclass::maxample("pop")
getYears(p2) <- 1900 + seq_len(nyears(p2))
getYears(p3) <- 1900 + seq_len(nyears(p3)) * 5
expect_identical(toolTimeAverage(p2, averaging_range = 4, cut = FALSE),
setYears(toolTimeAverage(p3, averaging_range = 4, cut = FALSE), getYears(p2)))
expect_identical(nc(toolTimeAverage(p2, averaging_range = 4, cut = FALSE)),
nc(setYears(toolTimeAverage(p3, averaging_range = 4, cut = FALSE), getYears(p2))))
})

test_that("Error detection works", {
Expand Down
Loading