Loading 02_code/240922_MM_OECD_Download_Test.R +41 −6 Original line number Diff line number Diff line readsdmx__read_sdmx <- function (path, destfile = tempfile(fileext = ".xml"), quiet = TRUE, method = "libcurl", mode = "w", ...) { path <- url url "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/QNA/all?format=SDMX-ML" url <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/QNA/all?format=SDMX-ML" destfile <- tempfile(fileext = ".xml") quiet <- TRUE method <- "libcurl" mode <- "w" if (readsdmx:::is_url(path)) { if (!capabilities("libcurl") && method == "libcurl"){ method <- "auto" Loading @@ -22,6 +18,45 @@ readsdmx__read_sdmx <- function (path, destfile = tempfile(fileext = ".xml"), qu } stopifnot(file.exists(path)) path <- normalizePath(path) d <- read_sdmx_(path) d <- readsdmx:::read_sdmx_(path) as.data.frame(d, stringsAsFactors = FALSE) } url <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/QNA/all?format=SDMX-ML" destfile <- tempfile(fileext = ".xml") method <- "libcurl" df <- download.file(url, destfile, method = method, quiet = TRUE) stopifnot(df == 0L) # Read and inspect the first few lines of the downloaded file file_content <- readLines(destfile, n = 10) print(file_content) # Install and load jsonlite package if necessary # install.packages("jsonlite") library(jsonlite) url <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/QNA/all?format=SDMX-ML" destfile <- tempfile(fileext = ".json") # Change file extension to .json # Download the file df <- download.file(url, destfile, method = "libcurl", quiet = TRUE) stopifnot(df == 0L) # Read and parse the JSON file json_data <- fromJSON(destfile) print(json_data) # Inspect the data structure str(json_data$data) url <- "https://sdmx.oecd.org/public/rest/data/OECD.SDD.NAD,DSD_NAMAIN1@DF_QNA_EXPENDITURE_GROWTH_OECD/?format=jsondata" Loading
02_code/240922_MM_OECD_Download_Test.R +41 −6 Original line number Diff line number Diff line readsdmx__read_sdmx <- function (path, destfile = tempfile(fileext = ".xml"), quiet = TRUE, method = "libcurl", mode = "w", ...) { path <- url url "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/QNA/all?format=SDMX-ML" url <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/QNA/all?format=SDMX-ML" destfile <- tempfile(fileext = ".xml") quiet <- TRUE method <- "libcurl" mode <- "w" if (readsdmx:::is_url(path)) { if (!capabilities("libcurl") && method == "libcurl"){ method <- "auto" Loading @@ -22,6 +18,45 @@ readsdmx__read_sdmx <- function (path, destfile = tempfile(fileext = ".xml"), qu } stopifnot(file.exists(path)) path <- normalizePath(path) d <- read_sdmx_(path) d <- readsdmx:::read_sdmx_(path) as.data.frame(d, stringsAsFactors = FALSE) } url <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/QNA/all?format=SDMX-ML" destfile <- tempfile(fileext = ".xml") method <- "libcurl" df <- download.file(url, destfile, method = method, quiet = TRUE) stopifnot(df == 0L) # Read and inspect the first few lines of the downloaded file file_content <- readLines(destfile, n = 10) print(file_content) # Install and load jsonlite package if necessary # install.packages("jsonlite") library(jsonlite) url <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/QNA/all?format=SDMX-ML" destfile <- tempfile(fileext = ".json") # Change file extension to .json # Download the file df <- download.file(url, destfile, method = "libcurl", quiet = TRUE) stopifnot(df == 0L) # Read and parse the JSON file json_data <- fromJSON(destfile) print(json_data) # Inspect the data structure str(json_data$data) url <- "https://sdmx.oecd.org/public/rest/data/OECD.SDD.NAD,DSD_NAMAIN1@DF_QNA_EXPENDITURE_GROWTH_OECD/?format=jsondata"