R/get_p_code.R

Defines functions get_p_code

Documented in get_p_code

#' 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,])
	}
}
Gabegit/gmdata documentation built on May 6, 2019, 5:32 p.m.