From 358f35ee52a4e36e43ea32afd488fb5513ead33a Mon Sep 17 00:00:00 2001
From: "Jentsch, Helge Marc Ole" <helge.marc.ole.jentsch@uni-hamburg.de>
Date: Thu, 18 Mar 2021 23:04:38 +0100
Subject: [PATCH] 21-03-18 Update: - AUX: Update of Citations

Signed-off-by: Jentsch, Helge Marc Ole <helge.marc.ole.jentsch@uni-hamburg.de>
---
 DESCRIPTION   |  2 +-
 NAMESPACE     |  1 +
 R/auxiliary.R | 50 ++++++++++++++++++++++++++++++++++++++++++--------
 3 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index c0f1278..1a3ded9 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -39,7 +39,7 @@ Suggests: knitr, testthat, usethis, rmarkdown
 VignetteBuilder: knitr
 SystemRequirements: Tested with at least 4 GB RAM.
 NeedsCompilation: no
-Packaged: 2021-03-18 13:46:36 UTC; helge
+Packaged: 2021-03-18 22:01:05 UTC; helge
 Author: Helge Jentsch [aut, cre],
   Maria Bobrowski [aut],
   Johannes Weidinger [aut],
diff --git a/NAMESPACE b/NAMESPACE
index bded690..7556526 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -21,6 +21,7 @@ import(raster)
 import(sf)
 import(sp)
 import(stringr)
+importFrom(RefManageR,ReadBib)
 importFrom(RefManageR,ReadCrossRef)
 importFrom(RefManageR,WriteBib)
 importFrom(utils,download.file)
diff --git a/R/auxiliary.R b/R/auxiliary.R
index 9387b7b..3d0d35b 100644
--- a/R/auxiliary.R
+++ b/R/auxiliary.R
@@ -380,7 +380,9 @@ stacking.downloaded.data <- function(stack.save.location = "./",
 #'@note DISCLAIMER: No warranty or liability! The citations are provided without any warranty of any kind whatsoever, either expressed or implied, including warranties of merchantability and fitness for a particular purpose. The author should not be responsible for any incomplete citation of datasets or climate data products downloaded through this package.
 #'
 #'@importFrom RefManageR ReadCrossRef
+#'@importFrom RefManageR ReadBib
 #'@importFrom RefManageR WriteBib
+#'@importFrom utils download.file
 #'
 #'@export
 save.citation <- function(save.location = "./",
@@ -392,25 +394,57 @@ save.citation <- function(save.location = "./",
   save.location <- paste0(normalizePath(save.location, winslash = "/"), "/")
 
   if(dataSetName == "Chelsa"){
+    print("Please regard 'https://chelsa-climate.org/downloads/' for correct citations.")
     if(!file.exists(paste0(save.location, "chelsa_citation.bib"))){
+      # citation_  <- RefManageR::ReadCrossRef("")
+
       citation_paper <- RefManageR::ReadCrossRef("10.1038/sdata.2017.122")
+      citation_CHELSA_cmip5_ts <- RefManageR::ReadCrossRef("10.1038/s41597-020-00587-y")
+      citation_PBCOR <- RefManageR::ReadCrossRef("10.1175/JCLI-D-19-0332.1")
+
+      # Data
       citation_data <- RefManageR::ReadCrossRef("10.5061/dryad.kd1d4")
-      print(citation_paper)
-      print(citation_data)
-      RefManageR::WriteBib(bib = c(citation_paper, citation_data), file = paste0(save.location, "chelsa_citation.bib"))
+      utils::download.file("https://www.envidat.ch/dataset/eur11/export/bibtex.bib",
+                           destfile = paste0(tempdir(),"/bib_chelsa.bib"), quiet = T)
+      citation_EUR11 <- RefManageR::ReadBib(paste0(tempdir(),"/bib_chelsa.bib"))
+      unlink(x = paste0(tempdir(),"/bib_chelsa.bib"))
+      utils::download.file("https://www.envidat.ch/dataset/chelsacruts/export/bibtex.bib",
+                           destfile = paste0(tempdir(),"/bib_chelsa.bib"), quiet = T)
+      citation_CHELSAcruts_data   <- RefManageR::ReadBib(paste0(tempdir(),"/bib_chelsa.bib"))
+      unlink(x = paste0(tempdir(),"/bib_chelsa.bib"))
+      utils::download.file("https://www.envidat.ch/dataset/chelsa_cmip5_ts/export/bibtex.bib",
+                           destfile = paste0(tempdir(),"/bib_chelsa.bib"), quiet = T)
+      citation_CHELSA_cmip5_ts_data  <-  RefManageR::ReadBib(paste0(tempdir(),"/bib_chelsa.bib"))
+      unlink(x = paste0(tempdir(),"/bib_chelsa.bib"))
+
+      # Old versions
+      citation_Version1.0  <- RefManageR::ReadCrossRef("10.1594/WDCC/CHELSA_v1")
+      citation_Version1.1  <- RefManageR::ReadCrossRef("10.1594/WDCC/CHELSA_v1_1")
+
+      eval(parse(text = paste0("print(c(", paste(ls(pattern = "citation_"), collapse = ","),"))")))
+      eval(parse(text = paste0("RefManageR::WriteBib(bib = c(",
+                               paste(ls(pattern = "citation_"), collapse = ","),
+                               "), file = paste0(save.location, 'chelsa_citation.bib'))")))
     }
   }
   if (dataSetName == "WorldClim1.4") {
+    print("Please regard 'www.worldclim.org' for correct citations.")
     if(!file.exists(paste0(save.location, "Worldclim14_citation.bib"))){
-      citation <- RefManageR::ReadCrossRef("10.1002/joc.1276")
-      RefManageR::WriteBib(bib = citation, file = paste0(save.location, "Worldclim14_citation.bib"))
+      citation_WC14 <- RefManageR::ReadCrossRef("10.1002/joc.1276")
+      # citation_  <- RefManageR::ReadCrossRef("")
+      print(citation_WC14)
+      RefManageR::WriteBib(bib = citation_WC14, file = paste0(save.location, "Worldclim14_citation.bib"))
     }
   }
   if (dataSetName == "WorldClim2.1") {
+    print("Please regard 'www.worldclim.org' for correct citations.")
     if(!file.exists(paste0(save.location, "WorldClim21_citation.bib"))){
-      citation <- RefManageR::ReadCrossRef("10.1002/joc.5086")
-      print(citation)
-      RefManageR::WriteBib(bib = citation, file = paste0(save.location, "WorldClim21_citation.bib"))
+      citation_WC21_hist_Clim_Monthly <- RefManageR::ReadCrossRef("10.1002/joc.5086")
+      citation_WC21_CRUTS403 <- RefManageR::ReadCrossRef("10.1002/joc.3711")
+
+      print(c(citation_WC21_hist_Clim_Monthly, citation_WC21_CRUTS403))
+      RefManageR::WriteBib(bib = c(citation_WC21_hist_Clim_Monthly, citation_WC21_CRUTS403),
+                           file = paste0(save.location, "WorldClim21_citation.bib"))
     }
   }
 }
-- 
GitLab