diff --git a/NAMESPACE b/NAMESPACE index d27b622..c656a67 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -38,13 +38,11 @@ importFrom(madrat,toolGetMapping) importFrom(madrat,toolNAreplace) importFrom(madrat,toolSplitSubtype) importFrom(madrat,toolSubtypeSelect) -importFrom(madrat,vcat) importFrom(magclass,"getCells<-") importFrom(magclass,"getComment<-") importFrom(magclass,"getItems<-") importFrom(magclass,"getNames<-") importFrom(magclass,"getRegions<-") -importFrom(magclass,"getSets<-") importFrom(magclass,"getYears<-") importFrom(magclass,add_columns) importFrom(magclass,add_dimension) diff --git a/R/calcValidIncome.R b/R/calcValidIncome.R index 63debb5..6f01185 100644 --- a/R/calcValidIncome.R +++ b/R/calcValidIncome.R @@ -3,17 +3,13 @@ #' Returns historical development of income and future projections of income dynamics #' #' -#' @param datasource To switch between historical values of James et al (default) or -#' with future projections for different scenarios (James_OECD_Nakicenovic) +#' @param datasource "WDI_SSPs", the only one option at the moment. #' @return list of magpie object with data and weight. Since intensive and extensive variables #' are mixed please keep the mixed_aggregation -#' @importFrom madrat vcat calcOutput -#' @importFrom magclass mbind add_dimension getSets getSets<- collapseNames getYears #' @author Florian Humpenoeder, Abhijeet Mishra, Kristine Karstens +calcValidIncome <- function(datasource = "WDI_SSPs") { -calcValidIncome <- function(datasource = "WDI-MI_SSPs-MI") { - - if (datasource == "WDI-MI_SSPs-MI") { + if (datasource == "WDI_SSPs") { .tmp <- function(x, nm) { getSets(x)[3] <- "scenario" @@ -64,10 +60,9 @@ calcValidIncome <- function(datasource = "WDI-MI_SSPs-MI") { stop("Given datasource currently not supported!") } - return(list(x = out, - weight = weight, - mixed_aggregation = TRUE, - unit = "(million) US Dollar 2017 equivalents in MER/yr, MER/cap/yr, PPP/yr, PPP/cap/yr", - description = "Income") - ) + list(x = out, + weight = weight, + mixed_aggregation = TRUE, + unit = "(million) US Dollar 2017 equivalents in MER/yr, MER/cap/yr, PPP/yr, PPP/cap/yr", + description = "Income") } diff --git a/R/calcValidPopulation.R b/R/calcValidPopulation.R index 3ae29c9..64a18f7 100644 --- a/R/calcValidPopulation.R +++ b/R/calcValidPopulation.R @@ -2,53 +2,31 @@ #' #' Returns historical development of population and future projections of population dynamics #' -#' -#' @param PopulationPast population past data source -#' @param PopulationFuture population future data source -#' @param TimeFromFindSet boolean deciding something +#' @param pastData population past data source +#' @param futureData population future data source #' @return list of magpie object with data and weight #' @author Florian Humpenoeder, Jan Philipp Dietrich, David Chen -#' @importFrom magclass getRegions -#' @import mrdrivers -calcValidPopulation <- function(PopulationPast = "WDI-UN_PopDiv-MI", - PopulationFuture = c("SSPs-UN_PopDiv-MI", - "SDPs-UN_PopDiv-MI", - "SSP2EU-UN_PopDiv-MI"), - TimeFromFindSet = TRUE) { - - past <- calcOutput("PopulationPast", - PopulationPast = PopulationPast, - aggregate = FALSE) - getNames(past) <- paste("historical", paste0(PopulationPast), "Population (million people)", sep = ".") - getSets(past)[3] <- "scenario.model.variable" +calcValidPopulation <- function(pastData = "WDI-UN_PopDiv-MI", futureData = "SSPs-UN_PopDiv") { - future <- NULL - for (i in 1:length(PopulationFuture)) { - tmp <- calcOutput("PopulationFuture", - PopulationFuture = PopulationFuture[i], - extension2150 = "bezier", - aggregate = FALSE) - future <- mbind(future, tmp) - } + past <- calcOutput("PopulationPast", pastData = pastData, aggregate = FALSE) + future <- calcOutput("PopulationFuture", futureData = futureData, aggregate = FALSE) - - getNames(future) <- paste(sub("^pop_", "", getNames(future)), - paste0(PopulationFuture, collapse = "_and_"), - "Population (million people)", - sep = ".") + getNames(past) <- paste("historical", pastData, "Population (million people)", sep = ".") + getNames(future) <- paste(getNames(future), futureData, "Population (million people)", sep = ".") + getSets(past)[3] <- "scenario.model.variable" getSets(future)[3] <- "scenario.model.variable" - out <- new.magpie(getRegions(past), - union(getYears(past), getYears(future)), - c(getNames(past), getNames(future)), + out <- new.magpie(cells_and_regions = getItems(past, 1), + years = union(getYears(past), getYears(future)), + names = c(getNames(past), getNames(future)), + sets = c("region", "year", "scenario.model.variable"), fill = NA) out[, getYears(past), getNames(past)] <- past out[, getYears(future), getNames(future)] <- future - getSets(out, fulldim = FALSE)[3] <- "scenario.model.variable" - return(list(x = out, weight = NULL, unit = "million", - description = paste0("Population data. Datasource for the Past: ", - PopulationPast, - ". Datasource for the Future: ", - paste0(PopulationFuture, collapse = ", ")))) + list(x = out, + weight = NULL, + unit = "million", + description = paste0("Population data. Datasource for the Past: ", pastData, ". Datasource for the Future: ", + futureData)) } diff --git a/man/calcValidIncome.Rd b/man/calcValidIncome.Rd index 21fa845..1e3ba16 100644 --- a/man/calcValidIncome.Rd +++ b/man/calcValidIncome.Rd @@ -4,11 +4,10 @@ \alias{calcValidIncome} \title{calcValidIncome} \usage{ -calcValidIncome(datasource = "WDI-MI_SSPs-MI") +calcValidIncome(datasource = "WDI_SSPs") } \arguments{ -\item{datasource}{To switch between historical values of James et al (default) or -with future projections for different scenarios (James_OECD_Nakicenovic)} +\item{datasource}{"WDI_SSPs", the only one option at the moment.} } \value{ list of magpie object with data and weight. Since intensive and extensive variables diff --git a/man/calcValidPopulation.Rd b/man/calcValidPopulation.Rd index 6924361..538de8b 100644 --- a/man/calcValidPopulation.Rd +++ b/man/calcValidPopulation.Rd @@ -5,17 +5,14 @@ \title{calcValidPopulation} \usage{ calcValidPopulation( - PopulationPast = "WDI-UN_PopDiv-MI", - PopulationFuture = c("SSPs-UN_PopDiv-MI", "SDPs-UN_PopDiv-MI", "SSP2EU-UN_PopDiv-MI"), - TimeFromFindSet = TRUE + pastData = "WDI-UN_PopDiv-MI", + futureData = "SSPs-UN_PopDiv" ) } \arguments{ -\item{PopulationPast}{population past data source} +\item{pastData}{population past data source} -\item{PopulationFuture}{population future data source} - -\item{TimeFromFindSet}{boolean deciding something} +\item{futureData}{population future data source} } \value{ list of magpie object with data and weight