When I use content function, there is time print on console (0s). i would like to stop this message from printing on the console.
library(httr)
res <- GET("http://comtrade.un.org/api/get?type=C&freq=A&px=HS&ps=2013&r=842&p=0&rg=all&cc=TOTAL&fmt=csv")
httr::content(res, "parsed", encoding = "UTF-8", show_col_types = FALSE)
You could save the object to a variable and then it doesn't happen. Still not sure WHY it is happening though.
library(httr)
res <- GET("http://comtrade.un.org/api/get?type=C&freq=A&px=HS&ps=2013&r=842&p=0&rg=all&cc=TOTAL&fmt=csv")
datin <- httr::content(res, "parsed", encoding = "UTF-8", show_col_types = FALSE)
datin
#> # A tibble: 3 x 35
#> Classification Year Period `Period Desc.` `Aggregate Level` `Is Leaf Code`
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 H4 2013 2013 2013 0 0
#> 2 H4 2013 2013 2013 0 0
#> 3 H4 2013 2013 2013 0 0
#> # ... with 29 more variables: Trade Flow Code <dbl>, Trade Flow <chr>,
#> # Reporter Code <dbl>, Reporter <chr>, Reporter ISO <chr>,
#> # Partner Code <dbl>, Partner <chr>, Partner ISO <chr>,
#> # 2nd Partner Code <lgl>, 2nd Partner <lgl>, 2nd Partner ISO <lgl>,
#> # Customs Proc. Code <lgl>, Customs <lgl>, Mode of Transport Code <lgl>,
#> # Mode of Transport <lgl>, Commodity Code <chr>, Commodity <chr>,
#> # Qty Unit Code <dbl>, Qty Unit <chr>, Qty <lgl>, ...
Created on 2021-11-12 by the reprex package (v2.0.1)
StatSteph:
r>, Qty <lgl>,
i did what you said, but it keeps showing if you are running the code in a loop
Share a reproducible example so we can help a bit better.
Why reprex?
Getting unstuck is hard. Your first step here is usually to create a reprex, or reproducible example. The goal of a reprex is to package your code, and information about your problem so that others can run it and feel your pain. Then, hopefully, folks can more easily provide a solution.
What's in a Reproducible Example?
Parts of a reproducible example:
background information - Describe what you are trying to do. What have you already done?
complete set up - include any library() calls and data to reproduce your issue.
data for a reprex: Here's a discussion on setting up data for a reprex
make it run - include the minimal code required to reproduce your error on the data…
A minimal reproducible example consists of the following items:
A minimal dataset, necessary to reproduce the issue
The minimal runnable code necessary to reproduce the issue, which can be run
on the given dataset, and including the necessary information on the used packages.
Let's quickly go over each one of these with examples:
Minimal Dataset (Sample Data)
You need to provide a data frame that is small enough to be (reasonably) pasted on a post, but big enough to reproduce your issue.
Let's say, as an example, that you are working with the iris data frame
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.…
reproducible example
library(httr)
for (i in c(4, 8, 36)){
res <- GET(paste0("http://comtrade.un.org/api/get?type=C&freq=A&px=HS&ps=2013&r=", i, "&p=0&rg=all&cc=TOTAL&fmt=csv"))
x <- httr::content(res, "parsed", encoding = "UTF-8", show_col_types = FALSE)
}
system
Closed
December 3, 2021, 7:25pm
6
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.