rOpenGov / pxweb

R tools to access PX-WEB API
http://ropengov.github.io/pxweb
Other
69 stars 31 forks source link

"Do you want to download the data" doesn't download the data #264

Closed blackburnstat closed 8 months ago

blackburnstat commented 1 year ago

When using pxweb_interactive, the third question (after choosing the relevant elements of the chosen data cube) asks " Do you want to download the data?". But the data does not download. This is true when accessing w3.unece.org and api.scb.se. For info, my answers are Y, N, Y, Y, N.

MansMeg commented 1 year ago

Can you share the code you use?

blackburnstat commented 1 year ago

Sorry.

library(pxweb)
pxweb_interactive('w3.unece.org')
MansMeg commented 1 year ago

Great. Ill check when I have time.

pitkant commented 1 year ago

I was able to download data using the query printed in the console, for example:

# PXWEB query 
pxweb_query_list <- 
  list("Age"=c("GE.64"),
       "Sex"=c("GE.5"),
       "Country"=c("008","020","051","040"),
       "Year"=c("0","1","2","3"))

# Download data 
px_data <- 
  pxweb_get(url = "https://w3.unece.org/PXWeb2015/api/v1/en/STAT/30-GE/06-Health/001_en_GEHELifeExpect_r.px",
            query = pxweb_query_list)

# Convert to data.frame 
px_data_frame <- as.data.frame(px_data, column.name.type = "text", variable.value.type = "text")

I did get the following error message when turning the px_data object into a data.frame but it wasn't a breaking error:

Warning message:
In pxweb_as_data_frame.pxweb_data(x, row.names = row.names, optional = optional,  :
  NAs introduced by coercion

When assigning the results of pxweb_interactive to an object, I got a list of 3 with 1 element being the data:

output <- pxweb_interactive('w3.unece.org')

> output
$url
[1] "https://w3.unece.org/PXWeb2015/api/v1/en/STAT/10-CountryOverviews/01-Figures/ZZZ_en_CoSummary_r.px"

$query
PXWEB QUERY
query:
 [[1]] Indicator (item):
   c0000194
 [[2]] Country (item):
   008
 [[3]] Year (item):
   0

$data
  Country Year Area (square kilometres)
1 Albania 1990                    28748

(Might open another issue about this but it seems a bit illogical how pxweb_interactive prompts the user, especially on the first question. Maybe it would be better if the question was not of the form "do you want to do X AND Y" when the next question is anyway "do you want to do Y?" Answering no to the first question seems to affect only the next question about printing the query in json or as an R list)

o you want to print code to query and download data?
Enter your choice:
('esc' = Quit, 'y' = Yes, 'n' = No) 
1: n
Do you want to download the data?
Enter your choice:
('esc' = Quit, 'y' = Yes, 'n' = No) 
1: y
Do you want to return a the data as a data.frame?
Enter your choice:
('esc' = Quit, 'y' = Yes, 'n' = No) 
1: y
Do you want to print citation for the data?
Enter your choice:
('esc' = Quit, 'y' = Yes, 'n' = No) 
1: n
blackburnstat commented 1 year ago

@pitkant thanks. Yes, I can download the data using the printed query too. But if I recall correctly, until recently answering yes to question 2 would have the data downloaded in the first instance (as well as printing the code for future use).

MansMeg commented 1 year ago

It should dowload right away. I agree that we should probably make the question simpler by avoiding the AND part.

MansMeg commented 8 months ago

I guess this has been resolved. Otherwise, let me know.