From 23ad3e54461fab8d7dfe3eb68b670730d1261eb8 Mon Sep 17 00:00:00 2001 From: Mans Magnusson Date: Sat, 27 Jan 2024 15:49:25 +0100 Subject: [PATCH 1/6] Handle not on internet --- tests/testthat/test-pxweb_api_paths.R | 1 + tests/testthat/test-pxweb_as_dataframe.R | 1 + tests/testthat/test-pxweb_constructor.R | 3 +++ tests/testthat/test-pxweb_data_comments.R | 1 + tests/testthat/test-pxweb_get.R | 14 ++++++++++++++ tests/testthat/test-pxweb_interactive.R | 6 ++++++ tests/testthat/test-pxweb_query.R | 4 ++++ tests/testthat/test-pxweb_test_api.R | 1 + 8 files changed, 31 insertions(+) diff --git a/tests/testthat/test-pxweb_api_paths.R b/tests/testthat/test-pxweb_api_paths.R index 3e80737b..82451efb 100644 --- a/tests/testthat/test-pxweb_api_paths.R +++ b/tests/testthat/test-pxweb_api_paths.R @@ -5,6 +5,7 @@ context("pxweb_api_paths") test_that(desc = "Access api paths", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() url <- "https://api.scb.se/OV0104/v1/doris/sv/ssd/START/AM/AM0301/" expect_silent(scb <- pxweb(url)) diff --git a/tests/testthat/test-pxweb_as_dataframe.R b/tests/testthat/test-pxweb_as_dataframe.R index f68e9527..d5d044cb 100644 --- a/tests/testthat/test-pxweb_as_dataframe.R +++ b/tests/testthat/test-pxweb_as_dataframe.R @@ -5,6 +5,7 @@ context("pxweb conversions") test_that(desc = "Converting pxweb data to matrices and data.frames", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() # Move to url <- "https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0101/BE0101A/BefolkningNy" diff --git a/tests/testthat/test-pxweb_constructor.R b/tests/testthat/test-pxweb_constructor.R index f4267cf0..51c30f6a 100644 --- a/tests/testthat/test-pxweb_constructor.R +++ b/tests/testthat/test-pxweb_constructor.R @@ -5,6 +5,7 @@ context("pxweb") test_that(desc = "Constructor works as it should with Statistics Sweden", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() expect_silent(pxapi1 <- pxweb(url = "https://api.scb.se/OV0104/v1/doris/sv/ssd/START/ME/ME0104/ME0104C/ME0104T24")) expect_true(file.exists(pxapi1$paths$rda_file_path)) @@ -30,6 +31,7 @@ test_that(desc = "Constructor works as it should with Statistics Sweden", { test_that(desc = "Constructor works for erroneous urls", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() expect_silent(pxapi1 <- pxweb(url = "https://api.scb.se/OV0104/v1/doris/sv/ssd/START/ME/ME0104/ME0104C/ME0104T24")) @@ -50,6 +52,7 @@ test_that(desc = "Constructor works for erroneous urls", { test_that(desc = "Cache cleaner and print", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() expect_silent(pxapi1 <- pxweb(url = "https://api.scb.se/OV0104/v1/doris/sv/ssd/START/ME/ME0104/ME0104C/ME0104T24")) expect_silent(pxapi2 <- pxweb("https://statfin.stat.fi/PXWeb/api/v1/fi/StatFin/tym/tyonv/statfin_tyonv_pxt_001.px")) diff --git a/tests/testthat/test-pxweb_data_comments.R b/tests/testthat/test-pxweb_data_comments.R index a8f291e3..3315a0ac 100644 --- a/tests/testthat/test-pxweb_data_comments.R +++ b/tests/testthat/test-pxweb_data_comments.R @@ -5,6 +5,7 @@ context("pxweb_data_comments") test_that(desc = "test data comment structure", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() url <- "https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0101/BE0101A/BefolkningNy" json_query <- file.path(system.file(package = "pxweb"), "extdata", "examples", "json_query_example.json") diff --git a/tests/testthat/test-pxweb_get.R b/tests/testthat/test-pxweb_get.R index 35f3989d..0e0253b3 100644 --- a/tests/testthat/test-pxweb_get.R +++ b/tests/testthat/test-pxweb_get.R @@ -5,6 +5,7 @@ context("pxweb_get") test_that(desc = "Test to download px and sdmx", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() json_px_query <- readLines(test_path("test_data/test_query_px.json")) expect_silent(px_file_path1 <- @@ -37,6 +38,7 @@ test_that(desc = "Test to download px and sdmx", { test_that(desc = "Constructor works as it should with Statistics Sweden", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() url <- "https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0101/BE0101A/BefolkningNy" expect_silent(px_meta_data <- pxweb_get(url)) @@ -89,6 +91,7 @@ test_that(desc = "Constructor works as it should with Statistics Sweden", { test_that(desc = "Previous bugs", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() # This is a bug in the previous implementation of pxweb url <- "https://bank.stat.gl/api/v1/en/Greenland/BE/BE01" @@ -104,6 +107,7 @@ test_that(desc = "Previous bugs", { test_that(desc = "Test to download json-stat objects", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() # Test json-stat url <- "https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0101/BE0101A/BefolkningNy" @@ -126,6 +130,7 @@ test_that(desc = "Test to download json-stat objects", { test_that(desc = "Test pxweb_get_data", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() url <- "https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0101/BE0101A/BefolkningNy" json_query <- file.path(system.file(package = "pxweb"), "extdata", "examples", "json_query_example.json") @@ -138,6 +143,7 @@ test_that(desc = "Test pxweb_get_data", { test_that(desc = "Test http logger", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() url <- "https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0101/BE0101A/BefolkningNy" expect_silent(px <- pxweb(url)) @@ -154,6 +160,8 @@ test_that(desc = "Test http logger", { test_that(desc = "large variable call", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() + url <- "https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0001/BE0001G/BE0001ENamn10" json_query <- file.path(system.file(package = "pxweb"), "extdata", "examples", "json_query_last_names.json") expect_silent(px <- pxweb_get(url, query = pxweb_query(json_query))) @@ -163,6 +171,7 @@ test_that(desc = "large variable call", { test_that(desc = "Cite data", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() url <- "https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/BefolkningNy" json_query <- file.path(system.file(package = "pxweb"), "extdata", "examples", "json_query_example.json") @@ -175,6 +184,7 @@ test_that(desc = "Cite data", { test_that(desc = "Filter query error bug", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() url <- "http://data.ssb.no/api/v0/en/table/04861" json_query <- readLines(test_path("test_data/filter_query.json")) @@ -198,6 +208,7 @@ test_that(desc = "Filter query error bug", { test_that(desc = "a small big query", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() pxweb_query_list <- list( @@ -225,6 +236,7 @@ test_that(desc = "a small big query", { test_that(desc = "manually supplying a pxmdo", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() pxweb_query_list <- list( @@ -249,6 +261,7 @@ test_that(desc = "manually supplying a pxmdo", { test_that(desc = "return clear error message when missing values", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() pql <- list( "Tilltalsnamn" = c("20Agnes"), @@ -263,6 +276,7 @@ test_that(desc = "return clear error message when missing values", { test_that(desc = "Query with non-ascii characters work as well", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() pxweb_query_list <- list( diff --git a/tests/testthat/test-pxweb_interactive.R b/tests/testthat/test-pxweb_interactive.R index 99b3dd4b..e3082441 100644 --- a/tests/testthat/test-pxweb_interactive.R +++ b/tests/testthat/test-pxweb_interactive.R @@ -5,6 +5,7 @@ context("pxweb_interactive") test_that(desc = "Basic usage", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() expect_silent(pxe <- pxweb:::pxweb_explorer.character("https://api.scb.se/OV0104/v1/doris/sv/ssd/START/ME/ME0104/ME0104C/ME0104T24")) expect_output(pxweb:::print.pxweb_explorer(pxe), "/OV0104/v1/doris/sv/ssd/START/ME/ME0104/ME0104C/ME0104T24") @@ -29,6 +30,7 @@ test_that(desc = "Basic usage", { test_that(desc = "API catalogue usage", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() expect_silent(pxe_scb <- pxweb:::pxweb_explorer.character("api.scb.se")) expect_output(pxweb:::print.pxweb_explorer(pxe_scb), "v1") @@ -57,6 +59,7 @@ test_that(desc = "API catalogue usage", { test_that(desc = "Select all and eliminate", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() expect_silent(pxe <- pxweb:::pxweb_explorer.character("https://api.scb.se/OV0104/v1/doris/sv/ssd/START/ME/ME0104/ME0104C/ME0104T24")) expect_output(pxweb:::print.pxweb_explorer(pxe), "/OV0104/v1/doris/sv/ssd/START/ME/ME0104/ME0104C/ME0104T24") @@ -70,6 +73,7 @@ test_that(desc = "Select all and eliminate", { test_that(desc = "Select all and eliminate", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() expect_silent(pxe <- pxweb:::pxweb_explorer.character("https://api.scb.se/OV0104/v1/doris/sv/ssd/START/ME/ME0104/ME0104C/ME0104T24")) expect_output(pxe <- pxweb:::pxweb_interactive_input(pxe, test_input = "e")) @@ -108,6 +112,7 @@ test_that(desc = "Select all and eliminate", { test_that(desc = "Stat Iceland structure", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() expect_silent(pxe <- pxweb:::pxweb_explorer.NULL()) expect_output(pxe <- pxweb:::pxweb_interactive_input(pxe, test_input = "10")) @@ -124,6 +129,7 @@ test_that(desc = "Stat Iceland structure", { test_that(desc = "No value bug", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() url <- "http://px.hagstofa.is/pxen/api/v1/en/Efnahagur/utanrikisverslun/1_voruvidskipti/02_uttollskra/UTA02801.px" expect_silent(pxe <- pxweb:::pxweb_explorer.character(url)) diff --git a/tests/testthat/test-pxweb_query.R b/tests/testthat/test-pxweb_query.R index 77030059..f834f358 100644 --- a/tests/testthat/test-pxweb_query.R +++ b/tests/testthat/test-pxweb_query.R @@ -30,6 +30,7 @@ test_that(desc = "pxweb_query object", { test_that(desc = "split pxweb_query object", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() url <- "https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0101/BE0101A/BefolkningNy" dims <- list( @@ -85,6 +86,7 @@ test_that(desc = "split pxweb_query object", { test_that(desc = "split pxweb_query bug", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() url <- "http://px.hagstofa.is/pxis/api/v1/is/Efnahagur/utanrikisverslun/1_voruvidskipti/03_inntollskra/UTA03801.px" pxweb_query_list <- list( @@ -120,6 +122,8 @@ test_that(desc = "pxweb_query JSON parse error message", { test_that(desc = "mandatory variables are included automatically", { + skip_if_offline() + skip_on_cran() fp <- test_path(file.path("test_data", "pxm1_test.rda")) url <- "https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/BefolkningNy" diff --git a/tests/testthat/test-pxweb_test_api.R b/tests/testthat/test-pxweb_test_api.R index 6102e881..9eb0dd95 100644 --- a/tests/testthat/test-pxweb_test_api.R +++ b/tests/testthat/test-pxweb_test_api.R @@ -5,6 +5,7 @@ context("pxweb_test_api") test_that(desc = "Mixed node levels object", { # CRAN seem to run tests in parallel, hence API tests cannot be run on CRAN. skip_on_cran() + skip_if_offline() url <- "https://api.scb.se/OV0104/v1/doris/sv/ssd/START/AM/AM0301/" expect_output(res <- suppressWarnings(pxweb_test_api(url)), regexp = "4 node.+and 14 table") From d2475352fc772099e6944dfadc33e8477935ed84 Mon Sep 17 00:00:00 2001 From: Mans Magnusson Date: Sat, 27 Jan 2024 16:11:15 +0100 Subject: [PATCH 2/6] Updated vignette to run without internet --- vignettes/px_levels_example.rda | Bin 0 -> 427 bytes vignettes/px_meta_example.rda | Bin 0 -> 4202 bytes vignettes/pxd_example.rda | Bin 0 -> 4823 bytes vignettes/pxfp_example.rda | Bin 0 -> 167 bytes vignettes/pxjstat_example.rda | Bin 0 -> 834 bytes vignettes/pxweb.Rmd | 82 ++++++- vignettes/pxweb.html | 398 +++++++++++++++++--------------- 7 files changed, 284 insertions(+), 196 deletions(-) create mode 100644 vignettes/px_levels_example.rda create mode 100644 vignettes/px_meta_example.rda create mode 100644 vignettes/pxd_example.rda create mode 100644 vignettes/pxfp_example.rda create mode 100644 vignettes/pxjstat_example.rda diff --git a/vignettes/px_levels_example.rda b/vignettes/px_levels_example.rda new file mode 100644 index 0000000000000000000000000000000000000000..131cc76c28f1553787e41a365b5cb4437f161e4f GIT binary patch literal 427 zcmV;c0aX4UiwFP!000001HF_{Pr@(|$IBQopbr?oz`e^%Ta=&=J}BWy2og;2$rM&# zVe6KyL-_J&fq~mV7h^El(%bFslHdJ%*KPExrG5z^lt+3#hw=qwqQXnBY19$YHT980 zIx4EO=*{13KI3+vf-hE42x+TRS8q8Mc=o_Yu00i&7`GRxe>s_QG&-&q+DuxmfWZQM zK2}x*9Ohe+*$_x3!=M6e%z+6L0zSV2c;(Coa$Bo|0Tff3s(GP&RRdFl(jKngVXU4M zOhGV*2T`6LIW^0SEL|=;Ld>i z@kS)T*W46iy5X)K08q@-X8CBQf+gcHk1{3QjEcnc^q6H zI?R{gjzCU04Bb#jf3b>=w}9OID1CKb`s1|VbaU5ROfWMG{xJscDU}^p$VsNwxP?h1 zcZ-k%xYq_IO7wrhEq{%6m(**xoyB~a6nvj>Rpqx+{Aaf0Dj3=<*scO?JH_7ooe#GA VE~;m%>$)j`mY;~q&&@dn00028%w_-p literal 0 HcmV?d00001 diff --git a/vignettes/px_meta_example.rda b/vignettes/px_meta_example.rda new file mode 100644 index 0000000000000000000000000000000000000000..bd14a42306f59a4592187f85e1a23d952485e9a9 GIT binary patch literal 4202 zcmaLXc{CL6*8p%?E5=kpj4hSzOCmd2vJ+w~O^O)H$TE?TCfj6*WNDJM86)dh$5@9! z%8VszB0FWvGGkw7y#2oK@4SD$&$;J3=YGy}&OPUzdmqt+(@g&!mNmz30TYxI3B6rl zmLLR5_1mWqJzYU3ttmp*Zd}sVxdoSYy;#1nOIHpsvFO%O#zl-OZdmCyGdp9ZyMy=y zDaUtj?zY8Fs_$d&@--$O*x569We#R{&}#!|V@F3vO-G{UxTEGR@w!k^`DuixkMEkG z(&*IKqc6^_RR1Di+7elA{SCu$R0kJ+ov`fZp3N}4QUs?`Yu6#Pl^}y-K%`6A?Ybkd? z3wmP4gtH1*2%H3Yf-?IUyWoPONdLZ{7ywKCS2_$6Bx`TAA* zTX_O!SY7|YO9ab$2Uu{zW|ux^KG0qGT;5RWeO)Z*R2663B-5g%?u$1zl`k-oK%bGP zvY6;R4vLnQ{mLmtV1GzN2aA$Z1eIB&RuU=;L-fA`hHmPqk`|fPm;nf;{Jz7R9j>C0 z*CtpT)!1j8BV(0%I3`)eq$6_9GG{|s0Qh^V?4x%nLV$PAv!K8wCNCZsCoHRh0yf7A zu$3tEOZ3of~Po3u1HJ-yS-=meYZM8WGfu`QyF;t@YKO(Vc3AbK39}8=xGKG^_1ZnlH9INNWbq3Tp z+#&%QkC5D>Ie&{+>T&p-Q%pFM@%2@Y>ur_Gg1@7L)gKwBx?cnwvK|Grl7uSdC0Ttg zQvi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ExmL$X<~b&L#7r%zL^hNd|}jtMSGcHCfMfL*8}=;=|GF47|Xl; zzE0Abz;63K@m#ib^tTUWSGI58NAJA4j44TRplaVhd^OoQ@;z=npK6!wRID9I`}#MY zw4O6yWILm3N3g%nf5Tk(P7d`W`z=_0=oF+@P1`iMl^aO=Yp%pl1mR0kTc&I>G@5J% z#J0-}_>9W1X8_P6PPn|^GhAACf-L}K$qiTYBz#Qk23`k%9&o`6{GPEOx(AQ|P#_Py z%#(1~)SWO70QvF2>--3x|AsjL2*UICSc`P8Cl~(+!2tjYJ%xrzH0wfLa2aN=O0F!&#$hnajNIzqF4|`kYYuO^kcR3EEzyNf*p7gxtmY z$Rm=1Gv+ly_79@m1w7YS?V>r?Sm_cr*I4U9GZ$3m;!AuA%&%T)P=+_fV`m88xplz3 zUjKv7mEfuI*a?CZJEF#praf8#U(&8_pGchiUH49u@wd9DnviO2qnR=t}L zq82c}bmdqHo)?eB5n$Xp{~{ciU%PUw49CP{X9*;3ork@fzQli#UI`u*FE>u0=Emst za(ELdfe#B-{u`$VaoiZ|UJf7PZQ#SQ6?$d($9TDa(YTibLKFf%ELurcg1?QIn|h(AMG`BvMibexpJ(ohGvch~;wrb@IRD?FL4d>Q^(PAa<>+W=Gypv=%B}ywo64_{8TIPU{~O9Hrd3Fr ziqY}+b*973{|+svBmD-%wNa-MpGcI&bi0+(U|hT`juOp27CX?HM*PmPztapaL?d+CjRuVelxBSW#1384w)2y7LP=P5Pc+>9L6y z`98ex-cj>Yp?PKQ&86~+iLu4YF`>#P^6vhw2#1jh`$DQ!fVieM6Fh_*1|`&z!$Z-L ztskwbPIoUNJ4inx5pHTFz)*OY?dzW~I*hFAaq literal 0 HcmV?d00001 diff --git a/vignettes/pxfp_example.rda b/vignettes/pxfp_example.rda new file mode 100644 index 0000000000000000000000000000000000000000..f394d514b98f5a150caaaf470bdfa6594625f162 GIT binary patch literal 167 zcmV;Y09gMYiwFP!0000015J%V4uUWgL_bm%vhpJOi!G(>2?rpUurt_NG>X>Nn1;g} zyL2{h-fX6829^&w0Hi?D1kx;4$PRtGl>lTFB>@8KNMeJrk(mb zKdIZ1`*IHZhg%je7cIC`G-i5XkJ!Cu+v@q+RLHoILQrXHsVO@#rAB6osw&2k%0e;C VBo|ziI~(HH_XktVxPGhv002Z^Naz3n literal 0 HcmV?d00001 diff --git a/vignettes/pxjstat_example.rda b/vignettes/pxjstat_example.rda new file mode 100644 index 0000000000000000000000000000000000000000..56fd934f2f7e626b1ba4693b958fef6b2f21c47c GIT binary patch literal 834 zcmV-I1HJqoiwFP!000001GQG&ZqqOn&R8czul5L$uQy>k|GQ&@aZxl7E7C-@i~M-Q zBTcF}Z8y*)E_fzhU{AygAe^{Oj?;E%8oQ|K^Bwy;$LG)a`1;K1pY;vH*fx6GTgLW| zTpBx{hR6H9Vf3C!Vawlj(p%EH~1uw(YtPD*BI^SzI#bL=V^WsK3Dsi4A?79O= z`2E|85Ceu9u2IrO?|z;P-c=gf)tnA0*g6O3E!@)hzScYvJiAO8TI)r1*@ClVMca6T z<~+>Pn5jg;?3CypzG6wm&TT=0k`QFXPEMz6bZPs|r; z70wYF-2Kws(Ov3F=TDa3qdb!&r8vqHwkgqhBv>&EOKIs*ZF=|y6HHDPiGOH{;c4_C zpG?!*Bea=ln(^{po|WuHa*>oJSqFYRLF~ocvrefs|dcvNrA%}e9K)qpM@tFKj zOq}&iiHW;*mP&=EM(IPdxwNGgn+&SOCaY@kKjvUuRsVfauY=yU{s=yAz`ar3;2NMc zn5L;RxwP3R9%Zm3O-s|KH7JyD7Ci2Zv96Pi3f597ANiGY@Cxme zQsG+!57cMdv}SZ;>d*h4DW8))6OI~F2G@i&jYK|`PhZV-Do=4y@>rOsbC$G&A5ACn z1BE4v0-@GEru#S;V(-B54lw@QY*fA0UTH)WKQ1!1f{FVcYWnU93G(>;1SCQt_OkVXrk-bng~6xYzJc> z%Gkqz-Ljm(1#C8v*1&n2;=p&H?AShtl4E1do@2YNV*%N*D0Nl&EVHw&Y0*TVT5^zG z6|3B65 MFO=pr-en5_0M9R;QUCw| literal 0 HcmV?d00001 diff --git a/vignettes/pxweb.Rmd b/vignettes/pxweb.Rmd index 56af0781..ceb14683 100644 --- a/vignettes/pxweb.Rmd +++ b/vignettes/pxweb.Rmd @@ -12,6 +12,53 @@ vignette: > --- +```{r basecode, message=FALSE, eval=FALSE, echo=FALSE} +# Below are code to run to setup the data + +# Get PXWEB levels +px_levels <- pxweb_get("https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/") +px_levels +save(px_levels, file = "vignettes/px_levels_example.rda") + +# Get PXWEB metadata about a table +px_meta <- pxweb_get("https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/BefolkningNy") +px_meta +save(px_meta, file = "vignettes/px_meta_example.rda") + + +# Example Download +pxweb_query_list <- + list( + "Civilstand" = c("*"), # Use "*" to select all + "Kon" = c("1", "2"), + "ContentsCode" = c("BE0101N1"), + "Tid" = c("2015", "2016", "2017") + ) +pxq <- pxweb_query(pxweb_query_list) + +pxd <- pxweb_get( + "https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/BefolkningNy", + pxq +) +save(pxd, file = "vignettes/pxd_example.rda") + +pxq$response$format <- "json-stat" +pxjstat <- pxweb_get( + "https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/BefolkningNy", + pxq +) +save(pxjstat, file = "vignettes/pxjstat_example.rda") + +pxq$response$format <- "px" +pxfp <- pxweb_get( + "https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/BefolkningNy", + pxq +) +save(pxfp, file = "vignettes/pxfp_example.rda") + +``` + + This R package provides tools to access [PX-WEB API](https://www.scb.se/en/services/open-data-api/api-for-the-statistical-database/). Your [contributions](https://ropengov.org/community/) and [bug reports and other feedback](https://github.com/ropengov/pxweb) are @@ -123,20 +170,30 @@ Although, if the `pxweb` is installed again, it will overwrite the old API catal Under the hood, the pxweb package uses the `pxweb_get()` function to access data from the PXWEB API. It also keeps track of the API's time limits and splits big queries into optimal downloadable chunks. If we use `pxweb_get()` without a query, the function either returns a PXWEB LEVELS object or a PXWEB METADATA object. What is returned depends on if the URL points to a table in the API or not. Here is an example of a PXWEB LEVELS object. -```{r levels, message=FALSE, eval=TRUE} +```{r levels, message=FALSE, eval=FALSE} # Get PXWEB levels px_levels <- pxweb_get("https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/") px_levels ``` +```{r , message=FALSE, eval=TRUE, echo=FALSE} +load("px_levels_example.rda") +px_levels +``` And if we use `pxweb_get()` for a table, a PXWEB METADATA object is returned. -```{r meta, message=FALSE, eval=TRUE} +```{r meta, message=FALSE, eval=FALSE} # Get PXWEB metadata about a table px_meta <- pxweb_get("https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/BefolkningNy") px_meta ``` +```{r , message=FALSE, eval=TRUE, echo=FALSE} +load("px_meta_example.rda") +px_meta +``` + + ### Creating data queries To download data, we need both the URL to the table and a query specifying what parts of the table are of interest. An URL to a table is an URL that will return a metadata object if not a query is supplied. Creating a query can be done in three main ways. The first and most straightforward approach is to use `pxweb_interactive()` to explore the table URL and create a query interactively. @@ -234,7 +291,7 @@ pxweb_validate_query_with_metadata(pxq, px_meta) When we have the URL to a data table and a query, we can download the data with "`pxweb_get()` ". The function returns a `pxweb_data` object that contains the downloaded data. -```{r, message=FALSE, eval=TRUE} +```{r, message=FALSE, eval=FALSE} pxd <- pxweb_get( "https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/BefolkningNy", pxq @@ -242,9 +299,14 @@ pxd <- pxweb_get( pxd ``` +```{r , message=FALSE, eval=TRUE, echo=FALSE} +load("pxd_example.rda") +pxd +``` + If we instead want a JSON-stat object, we change the response format to JSON-stat, and we will get a JSON-stat object returned. -```{r, message=FALSE, eval=TRUE} +```{r, message=FALSE, eval=FALSE} pxq$response$format <- "json-stat" pxjstat <- pxweb_get( "https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/BefolkningNy", @@ -253,9 +315,14 @@ pxjstat <- pxweb_get( pxjstat ``` +```{r , message=FALSE, eval=TRUE, echo=FALSE} +load("pxjstat_example.rda") +pxjstat +``` + Some return formats return files. Then, these responses are stored in the R `tempdir()` folded, and the file paths are returned by `pxweb_get()`. Currently, `px` and `sdmx` formats can be downloaded as files, but file an issue if you need other response formats. -```{r, message=FALSE, eval=TRUE} +```{r, message=FALSE, eval=FALSE} pxq$response$format <- "px" pxfp <- pxweb_get( "https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/BefolkningNy", @@ -264,6 +331,11 @@ pxfp <- pxweb_get( pxfp ``` +```{r , message=FALSE, eval=TRUE, echo=FALSE} +load("pxfp_example.rda") +pxfp +``` + If the queries are large (contain more values than the PXWEB API maximum allowed values), the query is chunked into optimal chunks and is then downloaded sequentially. PXWEB data objects are then combined into one large PXWEB data object, while JSON-stat objects are returned as a list of JSON-stat objects, and other files are stored in `tempdir()` as separate files. For more advanced connections to the API, the `pxweb_advanced_get()` gives the flexibility to access the underlying HTTP calls using `httr` and log the HTTP calls for debugging. diff --git a/vignettes/pxweb.html b/vignettes/pxweb.html index 10a3fc78..79ab7849 100644 --- a/vignettes/pxweb.html +++ b/vignettes/pxweb.html @@ -12,7 +12,7 @@ - + PX-WEB API Interface for R @@ -31,23 +31,23 @@ +code{white-space: pre-wrap;} +span.smallcaps{font-variant: small-caps;} +span.underline{text-decoration: underline;} +div.column{display: inline-block; vertical-align: top; width: 50%;} +div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} +ul.task-list{list-style: none;} +