#' get the parterners code for get_comtrade fucntion
#' @param country: default=all
#' @return a data.frame
#' @author Li Guomin,2015-10-5
#' @export
#' @examples
#' get_p_code("ALL") # all countries
#' get_p_code("China")
get_p_code <- function(country){
#library(jsonlite)
# http://comtrade.un.org/data/cache/reporterAreas.json
trade_json <- "extdata/reporterAreas.json"
# read json to r object data.frame
trade_r <- jsonlite::fromJSON(trade_json,simplifyDataFrame = TRUE)
#head(trade_r)
if (country == "All") return(trade_r$results) else{
#trade_r is a list: more and results
result = trade_r$results
return(result[result$text==country,])
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.