forked from pik-piam/mrtutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadTutorialWDI.R
More file actions
36 lines (33 loc) · 1.36 KB
/
Copy pathreadTutorialWDI.R
File metadata and controls
36 lines (33 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#' Read WDI
#'
#' Read-in WDI (World development indicators) data .rda file as magclass
#' object.
#'
#'
#' @param subtype Type of WDI data that should be read. Please use the
#' worldbank indicator abbreviation. Available types are e.g.: \itemize{ \item
#' \code{SP.POP.TOTL}: Population, total \item \code{NY.GDP.MKTP.PP.KD}: GDP,
#' PPP (constant 2011 international Dollar) \item \code{NY.GDP.MKTP.PP.CD}:
#' GDP, PPP (current international Dollar) \item \code{NY.GDP.MKTP.CD}: GDP MER
#' (current USDollar) \item \code{NY.GDP.MKTP.KD}: GDP MER (constant 2005
#' USDollar) \item \code{NY.GDP.MKTP.KN}: GDP LCU (constant LCU)
#' \item \code{SP.URB.TOTL.IN.ZS}: Urban population (peccentage of total)
#' \item \code{ NV.AGR.TOTL.CD}: GDP (current USD)}
#' @return magpie object of the WDI data
#' @author David Chen
#' @seealso \code{\link{readSource}} \code{\link{downloadTutorialWDI}}
#' @examples
#'
#' \dontrun{ a <- readSource(type="WDI",subtype="SP.POP.TOTL")
#' }
#' @importFrom reshape2 melt
#' @importFrom magclass as.magpie
readTutorialWDI<-function(subtype){
load("WDI.rda")
wdi$country <- NULL
wdi <- as.magpie(melt(wdi,id.vars = c("iso2c","year")),
spatial=1,temporal=2,tidy=TRUE,replacement =".")
wdi <- wdi[,,subtype]
getNames(wdi) <- gsub("\\.", "_", getNames(wdi)) ## Replace . with _
return(wdi)
}