Skip to content

Commit dcc058a

Browse files
authoredOct 9, 2021
Merge pull request #232 from rOpenGov/development
Development
2 parents 6cfcdda + dbe7ff1 commit dcc058a

12 files changed

+61
-95
lines changed
 

‎DESCRIPTION

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
Package: pxweb
22
Type: Package
33
Title: R Interface to PXWEB APIs
4-
Version: 0.11.0
5-
Date: 2021-07-07
4+
Version: 0.12.0
5+
Date: 2021-10-09
66
Encoding: UTF-8
77
Authors@R: c(
88
person("Mans", "Magnusson", email = "mons.magnusson@gmail.com", role = c("aut", "cre")),
99
person("Markus", "Kainu", role = "aut"),
1010
person("Janne", "Huovari", role = "aut"),
1111
person("Leo", "Lahti", role = "aut", comment = c(ORCID = "0000-0001-5537-637X")),
12-
person("Jan", "Bruusgaard", role = "ctb"),
13-
person("Øyvind", "Langsrud", role = "ctb"),
1412
person("Love" , "Hansson", role = "ctb"),
1513
person("Eydun", "Nielsen", role = "ctb"),
1614
person("Bo", "Werth", role = "ctb"),

‎NAMESPACE

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ S3method(pxweb_query,json)
2020
S3method(pxweb_query,list)
2121
S3method(pxweb_query,pxweb_explorer)
2222
S3method(pxweb_query,pxweb_query)
23-
export(ApiData)
24-
export(MakeUrl)
2523
export(api_catalogue)
2624
export(api_parameters)
2725
export(base_url)

‎R/defunct_functions.R

-25
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,7 @@
55
#' Call the functions to get information on new functions to use.
66
#'
77
#' @param url Defunct argument.
8-
#' @param urlToData Defunct argument.
98
#' @param ... Defunct argument.
10-
#' @param getDataByGET Defunct argument.
11-
#' @param returnMetaData Defunct argument.
12-
#' @param returnMetaValues Defunct argument.
13-
#' @param returnMetaFrames Defunct argument.
14-
#' @param returnApiQuery Defunct argument.
15-
#' @param defaultJSONquery Defunct argument.
16-
#' @param verbosePrint Defunct argument.
17-
#' @param use_factors Defunct argument.
18-
#' @param urlType Defunct argument.
19-
#' @param id Defunct argument.
209
#' @param api Defunct argument.
2110
#' @param version Defunct argument.
2211
#' @param language Defunct argument.
@@ -48,20 +37,6 @@ api_parameters <- function(url = NULL) {
4837
.Defunct(new = "pxweb_api_catalogue")
4938
}
5039

51-
#' @rdname api_catalogue
52-
#' @export
53-
ApiData <- function(urlToData, ..., getDataByGET = FALSE, returnMetaData = FALSE, returnMetaValues = FALSE,
54-
returnMetaFrames = FALSE, returnApiQuery = FALSE,
55-
defaultJSONquery = c(1,-2, -1), verbosePrint = FALSE,
56-
use_factors=FALSE, urlType="SSB") {
57-
.Defunct(new = "pxweb_advanced_get")
58-
}
59-
60-
#' @rdname api_catalogue
61-
#' @export
62-
MakeUrl <- function(id,urlType="SSB",getDataByGET = FALSE){
63-
.Defunct(new = "pxweb")
64-
}
6540

6641
#' @rdname api_catalogue
6742
#' @export

‎R/pxweb_as_data_frame.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ pxweb_as_data_frame.pxweb_levels <- function(x, optional = FALSE, ..., stringsAs
9999

100100
df <- list()
101101
for(i in seq_along(x)){
102-
df[[i]] <- as.data.frame(x[[i]], optional = optional, ..., stringsAsFactors = FALSE)
103-
if(x[[i]]$type == "l") {
102+
df[[i]] <- as.data.frame(x[[i]], optional = optional, stringsAsFactors = FALSE)
103+
if(x[[i]]$type %in% c("l", "h")) {
104104
df[[i]]$updated <- NA
105105
}
106106
}

‎R/pxweb_interactive.R

+38-13
Original file line numberDiff line numberDiff line change
@@ -318,44 +318,54 @@ print_bar <- function(){
318318
#' @rdname pxweb_explorer
319319
#' @keywords internal
320320
pxe_print_choices <- function(x){
321+
checkmate::assert_class(x, "pxweb_explorer")
321322
obj <- pxe_pxobj_at_position(x)
322323
show_no <- x$print_no_of_choices
323324

324325
if(pxe_position_is_metadata(x)){
325326
mddims <- pxweb_metadata_dim(pxe_pxobj_at_position(x))
326327
md_pos <- pxe_metadata_path(x, as_vector = TRUE)
327-
no_choices <- unname(mddims[md_pos[length(md_pos)]])
328+
no_rows_to_print <- unname(mddims[md_pos[length(md_pos)]])
329+
choices_idx <- 1:no_rows_to_print
328330
} else {
329-
no_choices <- length(obj)
331+
choices_df <- pxweb_levels_choices_df(obj)
332+
no_rows_to_print <- nrow(choices_df)
333+
choices_idx <- choices_df$choice_idx
330334
}
331335

332-
if(x$print_all_choices | no_choices <= show_no * 2){
333-
print_idx <- 1:no_choices
336+
if(x$print_all_choices | no_rows_to_print <= show_no * 2){
337+
print_idx <- 1:no_rows_to_print
334338
} else {
335-
print_idx <- c(1:show_no, NA, (no_choices - show_no + 1):no_choices)
339+
print_idx <- c(1:show_no, NA, (no_rows_to_print - show_no + 1):no_rows_to_print)
336340
}
337341

338342
print_idx_char <- as.character(print_idx)
339-
print_idx_char_nmax <- max(nchar(print_idx_char), na.rm = TRUE)
340-
print_idx_char <- str_pad(print_idx_char, print_idx_char_nmax )
343+
choice_idx_char <- as.character(choices_idx)
344+
choice_idx_char_nmax <- max(nchar(choice_idx_char), na.rm = TRUE)
345+
choice_idx_char <- str_pad(choice_idx_char, choice_idx_char_nmax )
341346

342347
for(i in seq_along(print_idx)){
343348
if(is.na(print_idx[i])) {
344349
cat("\n")
345350
next
346351
}
352+
347353
if(pxe_position_is_metadata(x)){
348354
if(x$show_id){
349355
cat(" [", print_idx_char[i], " ] : ", obj$variables[[length(md_pos)]]$valueTexts[print_idx[i]], " (", obj$variables[[length(md_pos)]]$values[print_idx[i]] ,")", "\n", sep = "")
350356
} else {
351357
cat(" [", print_idx_char[i], " ] : ", obj$variables[[length(md_pos)]]$valueTexts[print_idx[i]], "\n", sep = "")
352358
}
353359
} else {
354-
if(x$show_id){
355-
cat(" [", print_idx_char[i], " ] : ", obj[[print_idx[i]]]$text, " (", obj[[print_idx[i]]]$id ,")", "\n", sep = "")
360+
if(obj[[print_idx[i]]]$type == "h") {
361+
txt <- paste("\n", paste(rep(" ", nchar(print_idx_char[i]) + 2 + 6), collapse = ""), collapse = "")
356362
} else {
357-
cat(" [", print_idx_char[i], " ] : ", obj[[print_idx[i]]]$text, " \n", sep = "")
363+
txt <- paste0(" [", choice_idx_char[print_idx[i]], " ] : ")
358364
}
365+
txt <- paste0(txt, obj[[print_idx[i]]]$text)
366+
if(x$show_id) txt <- paste0(txt, " (", obj[[print_idx[i]]]$id ,")")
367+
txt <- paste0(txt, "\n")
368+
cat(txt)
359369
}
360370
}
361371
}
@@ -416,7 +426,9 @@ pxe_handle_input.numeric <- function(user_input, pxe){
416426
} else if(pxe_position_is_api_catalogue(pxe)) {
417427
pxe <- pxweb_explorer(obj[[user_input]]$id)
418428
} else {
419-
new_pos <- obj[[user_input]]$id
429+
cdf <- pxweb_levels_choices_df(obj)
430+
choice_input <- which(cdf$choice_idx == user_input)
431+
new_pos <- obj[[choice_input]]$id
420432
pxe <- pxe_add_position(pxe, new_pos)
421433
}
422434
assert_pxweb_explorer(pxe)
@@ -657,7 +669,7 @@ pxe_allowed_input.pxweb_explorer <- function(x){
657669
}
658670
}
659671

660-
if(!x$print_all_choices & pxe_position_choice_size(x) > x$print_no_of_choices*2){
672+
if(!x$print_all_choices & pxe_position_print_size(x) > x$print_no_of_choices*2){
661673
input_df$allowed[input_df$code == "a"] <- TRUE
662674
}
663675

@@ -811,13 +823,26 @@ pxe_position_is_api_catalogue <- function(x) {
811823
#' @param x a \code{pxweb_explorer} object to check.
812824
#' @keywords internal
813825
pxe_position_choice_size <- function(x) {
826+
if(pxe_position_is_metadata(x)){
827+
cs <- pxe_position_print_size(x)
828+
} else {
829+
obj <- pxe_pxobj_at_position(x)
830+
choices_df <- pxweb_levels_choices_df(obj)
831+
cs <- max(choices_df$choice_idx, na.rm = TRUE)
832+
}
833+
cs
834+
}
835+
836+
#' @rdname pxe_position_choice_size
837+
#' @keywords internal
838+
pxe_position_print_size <- function(x) {
814839
if(pxe_position_is_metadata(x)){
815840
md <- pxe_pxobj_at_position(x)
816841
md <- pxweb_metadata_dim(md)
817842
mdpos <- length(pxe_metadata_path(x, as_vector = TRUE))
818843
cs <- unname(md[mdpos])
819844
} else {
820-
cs <-length(pxe_pxobj_at_position(x))
845+
cs <- length(pxe_pxobj_at_position(x))
821846
}
822847
cs
823848
}

‎R/pxweb_levels.R

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ assert_pxweb_levels <- function(x){
2525
for(i in seq_along(x)){
2626
checkmate::assert_names(names(x[[i]]), must.include = c("id", "type", "text"), .var.name = paste0("names(x[[", i, "]])"))
2727
checkmate::assert_string(x[[i]]$id, .var.name = paste0("x[[", i, "]]$id"))
28-
checkmate::assert_choice(x[[i]]$type, choices = c("l", "t"), .var.name = paste0("x[[", i, "]]$type"))
28+
checkmate::assert_choice(x[[i]]$type, choices = c("l", "t", "h"), .var.name = paste0("x[[", i, "]]$type"))
2929
checkmate::assert_string(x[[i]]$text, .var.name = paste0("x[[", i, "]]$id"))
3030
}
3131
}
@@ -39,3 +39,12 @@ print.pxweb_levels <- function(x, ...){
3939
}
4040
}
4141

42+
#' @keywords internal
43+
pxweb_levels_choices_df <- function(x){
44+
checkmate::assert_class(x, "pxweb_levels")
45+
df <- pxweb_as_data_frame.pxweb_levels(x)
46+
df$is_choice <- ifelse(df$type %in% c("t", "l"), yes = TRUE, no = FALSE)
47+
df$choice_idx <- cumsum(df$is_choice)
48+
df$choice_idx[!df$is_choice] <- NA
49+
df
50+
}

‎README.Rmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ See [TROUBLESHOOTING.md](https://github.com/rOpenGov/pxweb/blob/master/TROUBLESH
8585
You are welcome to contact us:
8686

8787
* [Submit suggestions and bug reports](https://github.com/ropengov/pxweb/issues) (provide the output of `sessionInfo()` and `packageVersion("pxweb")`)
88-
* [Send a pull request](https://github.com/ropengov/pxweb/)
88+
* [Send a pull request](https://github.com/ropengov/pxweb)
8989
* [Star us on the Github page](https://github.com/ropengov/pxweb)
9090
* [Join the discussion in Gitter](https://gitter.im/rOpenGov/pxweb)
9191

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ You are welcome to contact us:
7575
- [Submit suggestions and bug
7676
reports](https://github.com/ropengov/pxweb/issues) (provide the
7777
output of `sessionInfo()` and `packageVersion("pxweb")`)
78-
- [Send a pull request](https://github.com/ropengov/pxweb/)
78+
- [Send a pull request](https://github.com/ropengov/pxweb)
7979
- [Star us on the Github page](https://github.com/ropengov/pxweb)
8080
- [Join the discussion in Gitter](https://gitter.im/rOpenGov/pxweb)
8181

‎inst/extdata/api.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
"citation" : {
245245
"organization" : "State Statistical Office of the Republic of Macedonia",
246246
"address" : "Skopje, Macedonia"},
247-
"url" : "http://makstat.stat.gov.mk/PXWeb/api/[version]/[lang]/MakStat/",
247+
"url" : "https://makstat.stat.gov.mk/PXWeb/api/[version]/[lang]/MakStat/",
248248
"version": ["v1"],
249249
"lang": ["en", "mk"],
250250
"calls_per_period": 30,
@@ -333,7 +333,7 @@
333333
"lang": ["en"],
334334
"calls_per_period": 10,
335335
"period_in_seconds": 10,
336-
"max_values_to_download" : 1000
336+
"max_values_to_download" : 100000
337337
},
338338

339339
"www.grande-region.lu": {

‎man/api_catalogue.Rd

+2-42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/pxe_position_choice_size.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/testthat/test-defunct.R

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ test_that(desc="Assert defunct errors",{
1111
expect_error(api_catalogue(), class = "defunctError")
1212
expect_error(update_pxweb_apis(), class = "defunctError")
1313
expect_error(api_parameters(), class = "defunctError")
14-
expect_error(ApiData(), class = "defunctError")
15-
expect_error(MakeUrl(), class = "defunctError")
1614
expect_error(base_url(), class = "defunctError")
1715
expect_error(get_pxweb_data(), class = "defunctError")
1816
expect_error(get_pxweb_dims(), class = "defunctError")

0 commit comments

Comments
 (0)
Please sign in to comment.