ropensci / tradestatistics

R package to access Open Trade Statistics API
https://docs.ropensci.org/tradestatistics
Apache License 2.0
76 stars 14 forks source link

tradestatistics R package not working #40

Closed Khumoyun803 closed 3 years ago

Khumoyun803 commented 3 years ago

Dear,

I needed a bulk bilateral data on ex/im, and wanted to install the tradestatistics package. The first problem I faced was the incompatibility of version of installed R and the package. Then I noticed it was archived, so I used remote library to install the package. However, after installation, when I tried to run the following basic command, it was not generating a data:

library(tradestatistics)

library(DT)

datatable(ots_create_tidy_data(years = 2016, reporters = "chl", partners = c("arg", "bol", "per")))

This is the returned output:

year reporter_iso reporter_fullname_english 1: 2016 chl Chile 2: 2016 chl Chile 3: 2016 chl Chile

But when I was extracting with the following code, it was working perfectly fine and generating the data:

read_from_ots <- function(p) {fromJSON(sprintf("https://api.tradestatistics.io/yrpc?y=2016&r=chl&p=%s", p))}

partners <- c("arg", "bol", "per")

ots_data <- map_df(partners, read_from_ots)

datatable(ots_data)

I think the tradestatistics package was not accessing an api properly. Thanks in advance for help!

pachadotdev commented 3 years ago

hi @Khumoyun803 I've just tested and it's working here, thanks for reporting provided I control the server and that you need bulk data, I can pass you a link where you can download all the data, without passing by the API first

pachadotdev commented 3 years ago

here's my output for the command you sent to me

> library(tradestatistics)
> ots_create_tidy_data(years = 2016, reporters = "chl", partners = c("arg", "bol", "per"))
Downloading data for the combination 2016, chl, arg...
Downloading data for the combination 2016, chl, bol...
Downloading data for the combination 2016, chl, per...
   year reporter_iso reporter_fullname_english trade_value_usd_exp trade_value_usd_imp
1: 2016          chl                     Chile         60717523953         59339757132
2: 2016          chl                     Chile         60717523953         59339757132
3: 2016          chl                     Chile         60717523953         59339757132
pachadotdev commented 3 years ago

I think that you were trying to access the YRP table, like this (the default is YR and ignores any partner argument)

> ots_create_tidy_data(years = 2016, reporters = "chl", partners = c("arg", "bol", "per"), table = "yrp")
Downloading data for the combination 2016, chl, arg...
Downloading data for the combination 2016, chl, bol...
Downloading data for the combination 2016, chl, per...
   year reporter_iso reporter_fullname_english partner_iso partner_fullname_english trade_value_usd_exp trade_value_usd_imp
1: 2016          chl                     Chile         arg                Argentina           738493479          2540642539
2: 2016          chl                     Chile         bol                  Bolivia          1207819680           119932338
3: 2016          chl                     Chile         per                     Peru          1550229354           997269330
Khumoyun803 commented 3 years ago

hi @Khumoyun803 I've just tested and it's working here, thanks for reporting provided I control the server and that you need bulk data, I can pass you a link where you can download all the data, without passing by the API first

Thank you for your reply @pachadotdev

It would be great if you could send a link for bulk download. I need disaggregated trade data for both export and import on a monthly basis. I would appreciate if you can provide data for most historical horizons since I want to implement Machine Learning methods to trade forecast.

pachadotdev commented 3 years ago

Hi @Khumoyun803 ! No problem. Please send me an email to mavargas11@uc.cl. Please note that the current API data has no imputation of any type, because I am using it to model.

pachadotdev commented 3 years ago

just to complete my answer, tradestatistics.io provides all the links to access the raw data and includes links that explain how to use rclone to download data from S3

Khumoyun803 commented 3 years ago

Thank you a lot