Skip to content

Commit

Permalink
*magclass* allowed for XLS reporting and return magpie object in writ…
Browse files Browse the repository at this point in the history
…e.reportProject.R
  • Loading branch information
piklev committed Sep 30, 2019
1 parent b845279 commit 35f6db4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: magclass
Type: Package
Title: Data Class and Tools for Handling Spatial-Temporal Data
Version: 5.0.0
Date: 2019-09-27
Version: 5.1.0
Date: 2019-09-30
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"),
Expand Down Expand Up @@ -40,12 +40,13 @@ Suggests:
data.tree,
units,
udunits2,
ncdf4
ncdf4,
xlsx
URL: https://github.com/pik-piam/magclass, https://doi.org/10.5281/zenodo.1158580
BugReports: https://github.com/pik-piam/magclass/issues
License: LGPL-3 | file LICENSE
LazyData: true
Encoding: UTF-8
RoxygenNote: 6.1.1
VignetteBuilder: knitr
ValidationKey: 9083000
ValidationKey: 9266190
17 changes: 16 additions & 1 deletion R/write.reportProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ write.reportProject <- function(mif,mapping,file=NULL,max_file_size=NULL,format=
getSets(tmp)<-c(getSets(tmp)[1:3],strsplit(names(map)[2],"[.]")[[1]][-1])
new_data[[n]][[m]] <- tmp

tmp<-setdiff(map[,names(map)[1],drop=FALSE],getNames(data[[n]][[m]]))
#Select names from mapping which are not NA
map_names = map[stats::complete.cases(map[names(map)[1]]),]
map_names = getElement(map_names,names(map)[1])
#Which names in the mapping are missing in the data
tmp <- setdiff(map_names,getNames(data[[n]][[m]]))
if (length(tmp) !=0) {
missingc <- c(missingc,tmp)
}
Expand Down Expand Up @@ -164,6 +168,16 @@ write.reportProject <- function(mif,mapping,file=NULL,max_file_size=NULL,format=

# save project reporting
if(format == "default") {
if (grepl("(xls$|xlsx$)",file)){

if (grepl("~",file)){
stop("the sign '~' is not always supported by function write.xlsx. Please change file path")
}
a <- write.report2(new_data,file=NULL)
a <- do.call(rbind,do.call(rbind,a))
xlsx::write.xlsx(as.data.frame(a), file = file, row.names = F,
sheetName = "DATA")
} else
write.report2(new_data,file=file,...)
} else if (format == "IAMC") {
a <- write.report2(new_data,file=NULL,...)
Expand Down Expand Up @@ -215,6 +229,7 @@ write.reportProject <- function(mif,mapping,file=NULL,max_file_size=NULL,format=
}
}
}
return(new_data)
}


0 comments on commit 35f6db4

Please sign in to comment.