Movatterモバイル変換


[0]ホーム

URL:


Type:Package
Title:R Interface to PXWEB APIs
Version:0.17.0
Date:2024-01-28
Description:Generic interface for the PX-Web/PC-Axis API. The PX-Web/PC-Axis API is used by organizations such as Statistics Sweden and Statistics Finland to disseminate data. The R package can interact with all PX-Web/PC-Axis APIs to fetch information about the data hierarchy, extract metadata and extract and parse statistics to R data.frame format. PX-Web is a solution to disseminate PC-Axis data files in dynamic tables on the web. Since 2013 PX-Web contains an API to disseminate PC-Axis files.
License:BSD_2_clause + file LICENSE
URL:https://github.com/rOpenGov/pxweb/,https://ropengov.github.io/pxweb/,https://github.com/rOpenGov/pxweb
BugReports:https://github.com/rOpenGov/pxweb/issues
Depends:R (≥ 3.5.0)
Imports:checkmate, curl, httr (≥ 1.1), jsonlite
Suggests:digest, httptest, knitr, remotes, rmarkdown, testthat (≥0.11), xml2
VignetteBuilder:knitr
Encoding:UTF-8
RoxygenNote:7.2.3
X-schema.org-isPartOf:http://ropengov.org/
X-schema.org-keywords:ropengov
NeedsCompilation:no
Packaged:2024-01-28 12:57:36 UTC; manma760
Author:Mans MagnussonORCID iD [aut, cre], Markus Kainu [aut], Janne Huovari [aut], Leo LahtiORCID iD [aut], Love Hansson [ctb], Eydun Nielsen [ctb], Bo Werth [ctb], Thomas Runarsson [ctb], Torbjörn Lindquist [ctb], Palmar Thorsteinsson [ctb], Pyry Kantanen [ctb], Sebastian Ankargren [ctb]
Maintainer:Mans Magnusson <mons.magnusson@gmail.com>
Repository:CRAN
Date/Publication:2024-01-29 08:50:02 UTC

Interface to PX-WEB APIs from R

Description

PXWEB is a common web API used by many European Statistical agencies to disseminate official statistics.The pxweb package facilitates connections and usage of these APIs.

References

The decription of the PXWEB API here:https://www.scb.se/en/About-us/about-the-website-and-terms-of-use/open-data-api/The official home page of PXWEB can be found here:https://www.scb.se/en/services/statistical-programs-for-px-files/px-web/


Add default values to pxe

Description

Add default values to pxe

Usage

add_pxe_defaults(pxe)

Arguments

pxe

apxweb_explorer object


Defunct functions

Description

These function has as from version 0.10.0 become defunct.Call the functions to get information on new functions to use.

Usage

api_catalogue()update_pxweb_apis()api_parameters(url = NULL)base_url(api, version = NULL, language = NULL)get_pxweb_data(url, dims, clean = FALSE, encoding = NULL)get_pxweb_dims(node, verbose = TRUE)get_pxweb_levels(baseURL, descriptions = FALSE, quiet = FALSE, ...)get_pxweb_metadata(  path = NULL,  node = NULL,  topnodes = NULL,  quiet = TRUE,  baseURL = NULL,  ...)pxweb_apicheckForLevels(url)

Arguments

url

Defunct argument.

api

Defunct argument.

version

Defunct argument.

language

Defunct argument.

dims

Defunct argument.

clean

Defunct argument.

encoding

Defunct argument.

node

Defunct argument.

verbose

Defunct argument.

baseURL

Defunct argument.

descriptions

Defunct argument.

quiet

Defunct argument.

...

Defunct argument.

path

Defunct argument.

topnodes

Defunct argument.

Format

An object of classlist of length 1.


Assert that x is a correctpxweb_database_list object.

Description

Assert that x is a correctpxweb_database_list object.

Usage

as_pxweb_levels(x)

Arguments

x

an object to check.


Assert that the url structure is correct

Description

Assert that theurl slot in thepxweb object is correct.

Usage

assert_pxweb(x)

Arguments

x

a object to assert


Assert apxweb_api_catalogue object

Description

Assert apxweb_api_catalogue object

Usage

assert_pxweb_api_catalogue(x)

Arguments

x

an object to assert is apxweb_api_catalogue_entry.


Assert that the rda_file_path is correct

Description

Assert that therda_file_path slot in thepxweb object is correct.

Usage

assert_pxweb_calls(x)

Arguments

x

a object to assert


Assert that the config slot is correct

Description

Assert that theconfig slot in thepxweb object is correct.

Usage

assert_pxweb_config(x)

Arguments

x

a object to assert


Assert that x is a correctpxweb_data object.

Description

Assert that x is a correctpxweb_data object.

Usage

assert_pxweb_data(x)

Arguments

x

an object to check.


Assert that x is a correctpxweb_data_comments object.

Description

Assert that x is a correctpxweb_data_comments object.

Usage

assert_pxweb_data_comments(x)

Arguments

x

an object to check.


Assert that x is a correctpxweb_data_jsonstat object.Assert a json-stat version 1.0 or later object

Description

Assert that x is a correctpxweb_data_jsonstat object.Assert a json-stat version 1.0 or later object

Usage

assert_pxweb_data_jsonstat(x)

Arguments

x

an object to check.


Assert that x is a correctpxweb_database_list object.

Description

Assert that x is a correctpxweb_database_list object.

Usage

assert_pxweb_database_list(x)

Arguments

x

an object to check.


Assert apxweb_input_allowed object

Description

Assert apxweb_input_allowed object

Usage

assert_pxweb_input_allowed(x)## S3 method for class 'pxweb_input_allowed'print(x, ...)

Arguments

x

an object to assert.


Assert that x is a correctpxweb_levels object.

Description

Assert that x is a correctpxweb_levels object.

Usage

assert_pxweb_levels(x)

Arguments

x

an object to check.


Assert that x is a correctpxweb_metadata object.

Description

Assert that x is a correctpxweb_metadata object.

Usage

assert_pxweb_metadata(x)

Arguments

x

an object to check.


Assert a pxweb_query object

Description

Assert a pxweb_query object

Usage

assert_pxweb_query(x, check_response_format = TRUE)

Arguments

x

an object to assert conferms to the structure of an pxweb_query object.


Assert that the rda_file_path is correct

Description

Assert that therda_file_path slot in thepxweb object is correct.

Usage

assert_pxweb_rda_file_path(x)

Arguments

x

a object to assert


Assert that the url structure is correct

Description

Assert that theurl slot in thepxweb object is correct.

Usage

assert_pxweb_url(x)

Arguments

x

a object to assert


Assert that a given pxweb query can be split

Description

Assert that a given pxweb query can be split

Usage

assert_query_can_be_split_to_batches(pxq, pxmd, mxv)

Arguments

pxq

a [pxweb_query] object

pxmd

a [pxweb_metadata] object

mxv

maximum batch size


Build or get the tmp_rda_file_path from an url or pxweb_api_s3 object

Description

Build or get the tmp_rda_file_path from an url or pxweb_api_s3 object

Usage

build_pxweb_rda_file_path(x)## S3 method for class 'character'build_pxweb_rda_file_path(x)## S3 method for class 'url'build_pxweb_rda_file_path(x)## S3 method for class 'pxweb'build_pxweb_rda_file_path(x)## S3 method for class 'list'build_pxweb_rda_file_path(x)

Arguments

x

object to create tmp_file_path for.

Details

The hostname is used to


Build the url to a PXWEB api

Description

Build the url to a PXWEB api

Usage

build_pxweb_url(x)## S3 method for class 'list'build_pxweb_url(x)## S3 method for class 'character'build_pxweb_url(x)## S3 method for class 'pxweb'build_pxweb_url(x)## S3 method for class 'pxweb_api_catalogue_entry'build_pxweb_url(x)

Build the url to get the config from a PXWEB api

Description

Build the url to get the config from a PXWEB api

Usage

## S3 method for class 'url'build_pxweb_url(x)build_pxweb_config_url(x)## S3 method for class 'list'build_pxweb_config_url(x)## S3 method for class 'pxweb'build_pxweb_config_url(x)## S3 method for class 'url'build_pxweb_config_url(x)

Generate batch permutations

Description

Generate batch permutations

Usage

generate_permutations(x)

Arguments

x

a vector with elements to permute

Details

Generates permutations of dim. If more than 6 dim (highly unlikely) a sample of 1000 combinationsis drawn. Otherwise all possible permutations are returned.


http_was_redirected

Description

http_was_redirected

Usage

http_was_redirected(r)

Arguments

r

an httr response object, e.g. from a call to httr::GET()

Value

list with slotswas_redirected,redirected_from andredirected_to

References

Function in large parts taken fromhttps://petermeissner.de/blog/2018/11/07/using-httr-to-detect-redirects/.

Examples

## Not run: r <- httr::GET("http://httpbin.org/redirect/2")pxweb:::http_was_redirected(r)## End(Not run)

Check if a response is a pxweb config response

Description

Check if a response is a pxweb config response

Usage

is_pxweb_config_response(x)

Arguments

x

a response object


Parse a character string or throws error if it fails

Description

Parse a character string or throws error if it fails

Usage

parse_url_or_fail(x)

Arguments

x

a character element to parse


Generate permutations of dimensions to find optimal no of batches

Description

Generate permutations of dimensions to find optimal no of batches

Usage

permutations(n, r, v = 1:n, set = TRUE, repeats.allowed = FALSE)

Arguments

n

Seegtools::permutations.

r

Seegtools::permutations.

v

Seegtools::permutations.

set

Seegtools::permutations.

repeats.allowed

Seegtools::permutations.

Details

Taken from gtools to minimize dependencies. See permutationsof the gtools packages for details


Print a catalogue entry

Description

Print a catalogue entry

Usage

## S3 method for class 'pxweb_api_catalogue_entry'print(x, ...)

Arguments

x

an object used to select a method.

...

further arguments passed to or from other methods.


Convert a pxweb data objects values to valuetext

Description

Convert a pxweb data objects values to valuetext

Usage

pxd_values_to_valuetexts(x, variable_code, variable_vector)

Arguments

x

apxweb_data object

variable_code

the variable name of the variable to convert. NOTE! Need to be the variable code.

variable_vector

the vector with the variables to convert.


Defines allowed input for a position in apxweb_explorer or character object.

Description

Defines allowed input for a position in apxweb_explorer or character object.

Usage

pxe_allowed_input(x)pxe_allowed_input_df()## S3 method for class 'pxweb_explorer'pxe_allowed_input(x)## S3 method for class 'character'pxe_allowed_input(x)## S3 method for class 'pxweb_explorer'pxe_allowed_input(x)

Arguments

x

a object to get allowed input for.


Move in thepxweb_explorer position

Description

Move in thepxweb_explorer position

Usage

pxe_back_position(pxe)pxe_add_position(pxe, new_pos)

Arguments

pxe

apxweb_explorer object.

new_pos

add a new position.

Details

pxe_back_position moves back one position andpxe_add_position moves forward, based on user choice.


Get the url to a table

Description

Get the url to a table

Usage

pxe_data_url(x)

Arguments

x

apxweb_explorer object


Handle a user input for apxweb_explorer object.

Description

Handle a user input for apxweb_explorer object.

Usage

pxe_handle_input(user_input, pxe)## S3 method for class 'numeric'pxe_handle_input(user_input, pxe)## S3 method for class 'character'pxe_handle_input(user_input, pxe)

Arguments

user_input

an (allowed) user input to handle.

pxe

apxweb_explorer object to get user input for.

See Also

pxe_allowed_input()


Get (allowed) inputs for apxweb_input_allowed object.

Description

Get (allowed) inputs for apxweb_input_allowed object.

Usage

pxe_input(allowed_input, title = NULL, test_input = NULL)pxe_parse_input(user_input, allowed_input)

Arguments

allowed_input

apxweb_input_allowed.

title

Print (using cat()) before ask for the allowed choices.

test_input

supplying a test input (for testing only)

Details

It handles input and checks if the input is allowed.


Ask to download and download data

Description

Ask to download and download data

Usage

pxe_interactive_get_data(pxe, test_input = NULL)

Arguments

pxe

apxweb_explorer object with full query

test_input

a test input for testing the function.Since two question, supply a vector of length two.


Get and set pxe_metadata_coices

Description

Get and set pxe_metadata_coices

Usage

pxe_metadata_choices(x)pxe_metadata_choices(x) <- value

Arguments

x

apxweb_explorer object

value

an object to set as pxe_metadata_choice


Get the meta data variable names from apxweb_explorer object.

Description

Get the meta data variable names from apxweb_explorer object.

Usage

pxe_metadata_variable_names(x)

Arguments

x

apxweb_explorer object


How many choices has the current position?

Description

How many choices has the current position?

Usage

pxe_position_choice_size(x)pxe_position_print_size(x)

Arguments

x

apxweb_explorer object to check.


Is the current position an api_catalogue position?

Description

Is the current position an api_catalogue position?

Usage

pxe_position_is_api_catalogue(x)

Arguments

x

apxweb_explorer object to check.


Is the current position a full query (i.e. choices for all metadata variables)?

Description

Is the current position a full query (i.e. choices for all metadata variables)?

Usage

pxe_position_is_full_query(x)

Arguments

x

apxweb_explorer object to check.


Is the current position a metadata object?

Description

Is the current position a metadata object?

Usage

pxe_position_is_metadata(x)

Arguments

x

apxweb_explorer object to check.


Are multiple choices allowed?

Description

Are multiple choices allowed?

Usage

pxe_position_multiple_choice_allowed(x)

Arguments

x

apxweb_explorer object to check.


Get the table title for the current position

Description

Get the table title for the current position

Usage

pxe_position_title(x)

Arguments

x

apxweb_explorer object.


Can the variable at the current position be eliminated?

Description

Can the variable at the current position be eliminated?

Usage

pxe_position_variable_can_be_eliminated(x)

Arguments

x

apxweb_explorer object to check.


Print code to download query

Description

Print code to download query

Usage

pxe_print_download_code(pxe, as)

Arguments

pxe

apxweb_query object.

as

json orr.


Return the pxweb object at the current position

Description

Return the pxweb object at the current position

Usage

pxe_pxobj_at_position(x)pxe_pxobj_at_position(x) <- value

Arguments

x

apxweb_explorer object.


S3 constructor forpxweb api object.

Description

The pxwebapi object contain all information to do calls to the pxweb api and keep countof the number of calls. The object is constructedThe object will also be cached in R temp folder to minimize calls to api.All urls should be passed through the constructor to set up the pxweb api config.

Garantuees:The base_url has been pingedThe sub_path has been checkedThe config has been captured from the APIThe url has been checked to be a pxweb api (through config)

Usage

pxweb(url)is.pxweb(x)## S3 method for class 'pxweb'print(x, ...)

Arguments

url

an url to a pxweb api including language and version of the api. See examples.

x

an an object to test if it is apxweb object.

...

further arguments supplied toprint().

Value

Apxweb object.

Examples

## Not run: pxapi_1 <-  pxweb("https://api.scb.se/OV0104/v1/doris/sv/ssd/START/ME/ME0104/ME0104C/ME0104T24")pxapi_2 <-  pxweb(url = "https://api.scb.se/OV0104/v1/doris/sv")## End(Not run)

Add the subpath slot to a pxweb path slot

Description

Add the subpath slot to a pxweb path slot

Usage

pxweb_add_api_subpath(obj)

Arguments

obj

an object to add subpath to

Details

Queries the path from pos 1 and up until a config is returned.


Add an api call to a pxweb_api_s3 object

Description

The pxweb_add_call function add a call the the api in the call stack, then compute

Promise:The stored rda api object will always have the latest callsThis is not thread safe so only one session at a time should call the api.

Usage

pxweb_add_call(obj, time_stamp = Sys.time())

Arguments

obj

apxweb_api_s3 object


Add the config slot to a pxweb object

Description

Add the config slot to a pxweb object

Usage

pxweb_add_config(obj)

Arguments

obj

an object to add config to

Details

Checks if there exist a config object in the object.Otherwise it query the api to get it and add that call to the call stack.


Add mandatory variables to query

Description

Add mandatory variables to query

Usage

pxweb_add_mandatory_variables(pxq, pxmd)

Arguments

pxq

apxweb_query object.

pxmd

apxweb_metadata object.

Details

Complement queries that lack explicit requests for variables with requests for every value of these variables.


Add and remove metadata to query

Description

Add and remove metadata to query

Usage

pxweb_add_metadata_to_query(pxq, pxmd)pxweb_remove_metadata_from_query(pxq, pxmd)

Arguments

pxq

apxweb_query object.

pxmd

apxweb_metadata object.

Details

Add metadata values to variables with a query with filter "all".


Do a GET call to PXWEB API for advanced users

Description

Do a GET call to PXWEB API for advanced users

Usage

pxweb_advanced_get(  url,  query = NULL,  verbose = TRUE,  log_http_calls = FALSE,  pxmdo = NULL,  ...)

Arguments

url

apxweb object or url that can be coherced to apxweb object.

query

a json string, json file or list object that can be coherced to apxweb_query object.

verbose

should large queries print out progress.

log_http_calls

Should the http calls to the API be logged (for debugging reasons).If TRUE, all calls and responses are logged and written to "log_pxweb_api_http_calls.txt" in the working directory.

pxmdo

Apxweb_metadata object to use for query.

...

Further arguments sent tohttr::POST (for queries) orhttr::GET (for query =NULL).If used with query, also supply apxweb_metadata object. Otherwise the same parameters are sent tobothhttr::POST andhttr::GET.

Details

This function is intended for more advanced users that want to supply specific arguments inhttr calls or what to debughttr calls.

pxweb_get() is a wrapper for standard use.


Get the PXWEB API catalogue

Description

Get the PXWEB API catalogue

Usage

pxweb_api_catalogue()pxweb_api_catalogue_from_json(json)pxweb_api_catalogue_from_github(branch = "master")pxweb_api_catalogue_path()

Details

A list with implemented API:s.

Examples

pxweb_api_catalogue()

Constructor forpxweb_api_catalogue_entry.

Description

Constructor forpxweb_api_catalogue_entry.

Usage

pxweb_api_catalogue_entry(x)## S3 method for class 'list'pxweb_api_catalogue_entry(x)assert_pxweb_api_catalogue_entry(x)

Arguments

x

an object to assert is apxweb_api_catalogue_entry.


Get the api name, rootpath, subpath, path or dbpath

Description

Get the api name, rootpath, subpath, path or dbpath

Usage

pxweb_api_name(x)## S3 method for class 'url'pxweb_api_name(x)## S3 method for class 'pxweb'pxweb_api_name(x)## S3 method for class 'pxweb_api_catalogue_entry'pxweb_api_name(x)## S3 method for class 'pxweb_explorer'pxweb_api_name(x)pxweb_api_rootpath(x)## S3 method for class 'url'pxweb_api_rootpath(x)## S3 method for class 'pxweb'pxweb_api_rootpath(x)## S3 method for class 'pxweb_explorer'pxweb_api_rootpath(x)pxweb_api_subpath(x, init_slash = TRUE, as_vector = FALSE)## S3 method for class 'pxweb'pxweb_api_subpath(x, init_slash = TRUE, as_vector = FALSE)## S3 method for class 'pxweb_explorer'pxweb_api_subpath(x, init_slash = TRUE, as_vector = FALSE)pxweb_api_path(x, init_slash = TRUE, as_vector = FALSE)## S3 method for class 'url'pxweb_api_path(x, init_slash = TRUE, as_vector = FALSE)## S3 method for class 'pxweb'pxweb_api_path(x, init_slash = TRUE, as_vector = FALSE)## S3 method for class 'pxweb_explorer'pxweb_api_path(x, init_slash = TRUE, as_vector = FALSE)pxweb_api_dbpath(x, init_slash = TRUE, as_vector = FALSE)## S3 method for class 'pxweb'pxweb_api_dbpath(x, init_slash = TRUE, as_vector = FALSE)## S3 method for class 'pxweb_explorer'pxweb_api_path(x, init_slash = TRUE, as_vector = FALSE)assert_path(x)pxe_position_path(  x,  init_slash = TRUE,  as_vector = FALSE,  include_rootpath = FALSE)pxe_metadata_path(x, as_vector = FALSE)

Arguments

x

object to get the name or path for

init_slash

shouldsubpath andpath start with a/. Default isTRUE.

as_vector

shouldsubpath andpath be a vector split by /. Default isFALSE.

include_rootpath

Should the rootpath be included? Default is FALSE

Details

The PXWEB API contain the following path:API-NAME/API-VERSION/LANGUAGE/DATABASE-ID/<LEVELS>/TABLE-ID

The full url is made up by therootpath,subpath, andpath.Therootpath is made up of the protocol and the API-NAME / hostname and protocol (if any).

Thesubpath contain the API-VERSION and LANGUAGE but can contain other parts as well.The subpath is the shortest the config can be called for. It can be seen as the base for the API.

Thedbpath, the data base path, contain DATABASE-ID/<LEVELS>/TABLE-ID.

Thepath, is the standar path of an url, i.e.subpath +dbpath.

No path ends with slash, butsubpath anddbpath may begin with slash,see the parameters


Coerce apxweb_data object to adata.frame

Description

Coerce apxweb_data object to adata.frame

Usage

pxweb_as_data_frame(  x,  row.names = NULL,  optional = FALSE,  ...,  stringsAsFactors = FALSE,  column.name.type = "text",  variable.value.type = "text")## S3 method for class 'pxweb_data'pxweb_as_data_frame(  x,  row.names = NULL,  optional = FALSE,  ...,  stringsAsFactors = FALSE,  column.name.type = "text",  variable.value.type = "text")## S3 method for class 'pxweb_data_comments'pxweb_as_data_frame(  x,  row.names = NULL,  optional = FALSE,  ...,  stringsAsFactors = FALSE)## S3 method for class 'pxweb_data_comment'pxweb_as_data_frame(  x,  row.names = NULL,  optional = FALSE,  ...,  stringsAsFactors = FALSE)## S3 method for class 'pxweb_levels'pxweb_as_data_frame(  x,  row.names = NULL,  optional = FALSE,  ...,  stringsAsFactors = FALSE)## S3 method for class 'pxweb_data'as.data.frame(  x,  row.names = NULL,  optional = FALSE,  ...,  stringsAsFactors = FALSE,  column.name.type = "text",  variable.value.type = "text")## S3 method for class 'pxweb_data_comments'as.data.frame(  x,  row.names = NULL,  optional = FALSE,  ...,  stringsAsFactors = FALSE)## S3 method for class 'pxweb_levels'as.data.frame(  x,  row.names = NULL,  optional = FALSE,  ...,  stringsAsFactors = FALSE)## S3 method for class 'pxweb_metadata'as.data.frame(  x,  row.names = NULL,  optional = FALSE,  ...,  stringsAsFactors = FALSE)pxweb_as_matrix(  x,  row.names = NULL,  column.name.type = "text",  variable.value.type = "text")## S3 method for class 'pxweb_data'pxweb_as_matrix(  x,  row.names = NULL,  column.name.type = "text",  variable.value.type = "text")## S3 method for class 'pxweb_data'as.matrix(  x,  ...,  row.names = NULL,  column.name.type = "text",  variable.value.type = "text")pxweb_pxd_slot_idx_pos(x)

Arguments

x

an object to convert todata.frame.

row.names

Seeas.data.frame.

optional

Seeas.data.frame.

...

Seeas.data.frame.

stringsAsFactors

Seeas.data.frame.

column.name.type

character: shouldcode ortext be used as column names?

variable.value.type

character: shouldcode ortext be used as values in columns?

See Also

as.data.frame.


Convert object to json

Description

Convert object to json

Usage

pxweb_as_json(x)## S3 method for class 'pxweb_query'pxweb_as_json(x)

Arguments

x

an object to convert.


Combine pxweb objects

Description

Combine pxweb objects

Usage

pxweb_c(x)

Arguments

x

a list withpxweb objects.


Cite a PXWEB data object

Description

Cite a PXWEB data object

Usage

pxweb_cite(x, style = "citation")

Arguments

x

apxweb_data object to cite.

style

seebibentry.

Details

Functionality to automatic cite PXWEB data objects.


Clear cache of all (or one)pxweb object

Description

Clear cache of all (or one)pxweb object

Usage

pxweb_clear_cache(x = NULL)

Arguments

x

apxweb object to clear cache for. Default is NULL (clear everything).

Details

Clean the cache and sleep to restore api timing limit.


Construct apxweb_data object.

Description

An object that contain the data for a given PXWEB table.

Usage

pxweb_data(x)

Arguments

x

a list returned from a PXWEB API to convert to apxweb_data object.

Value

apxweb_data object


Combine pxweb objects

Description

Combine pxweb objects

Usage

pxweb_data_c(x)

Arguments

x

a list withpxweb objects.


Get query filter

Description

Get query filter

Usage

pxweb_data_colnames(pxd, type = "text")

Arguments

pxd

apxweb_data object.

Value

character vector with column names.


Construct apxweb_data_comment object

Description

Construct apxweb_data_comment object

Usage

pxweb_data_column_comment(x, column_idx)pxweb_data_value_comment(x, comment_idx)pxweb_data_obs_comment(x, obs_idx)

Arguments

x

anpxweb_data to extract apxweb_data_comment object from.

column_idx

the index of the column to extract.

comment_idx

the index of the comment to extract.

obs_idx

the index of the comment to extract.


Construct apxweb_data_comments object.

Description

An object that contain the comments for a given PXWEB table.

Usage

pxweb_data_comments(x)## S3 method for class 'pxweb_data'pxweb_data_comments(x)

Arguments

x

apxweb_data object.

Value

apxweb_data_comments object

Examples

## Not run: 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")pxd <- pxweb_get(url = url, query = json_query)pxdcs <- pxweb_data_comments(x = pxd)pxdc_df <- as.data.frame(pxdcs, stringsAsFactors = TRUE)## End(Not run)

Compute the dimension of the querypxweb_data object

Description

Compute the dimension of the querypxweb_data object

Usage

pxweb_data_dim(pxd)

Arguments

pxd

apxweb_data object.


Construct apxweb_data_jsonstat object.

Description

An object that contain the data for a given PXWEB table.

Usage

pxweb_data_jsonstat(x)

Arguments

x

a list returned from a PXWEB API to convert to apxweb_data_jsonstat object.

Value

apxweb_data_jsonstat object.


Construct apxweb_database_list object.

Description

An object that contain the list of databases for a given PXWEB api.

Usage

pxweb_database_list(x)

Arguments

x

a list returned from a PXWEB API to convert to apxweb_database_list object.

Value

apxweb_database_list object


Create apxweb_explorer object.

Description

position the current position in the api, as a character vector from the root.Note position is not alway a correct url. Metadata and other choices are part of position

root is the bottom path (as position) that the user can go. If length 0, user can essentially go to hostname.

paste(root_path + position, collapse = "/") is used to construct the path to the positionin case of url.

print out a bar for separation purposes

Usage

pxweb_explorer(x = NULL)## S3 method for class ''NULL''pxweb_explorer(x)## S3 method for class 'character'pxweb_explorer(x)## S3 method for class 'pxweb'pxweb_explorer(x)## S3 method for class 'pxweb_api_catalogue_entry'pxweb_explorer(x)assert_pxweb_explorer(x)## S3 method for class 'pxweb_explorer'print(x, ...)print_bar()pxe_print_choices(x)

Arguments

x

apxweb object, a PXWEB url,NULL or an api in the api catalogue.

Examples

## The functions below are internal generic functions## x <- pxweb_explorer()## url <- "api.scb.se"## x <- pxweb_explorer(x = url)## url <- "https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/"## x <- pxweb_explorer(x = url)## url <- "https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/BefolkningNy"## x <- pxweb_explorer(x = url)

Fix url characters

Description

Fix url characters

Usage

pxweb_fix_url(x)

Arguments

x

a string to fix


Do a GET call to PXWEB API

Description

Do a GET call to PXWEB API

Usage

pxweb_get(url, query = NULL, verbose = TRUE)

Arguments

url

apxweb object or url that can be coherced to apxweb object.

query

a json string, json file or list object that can be coherced to apxweb_query object.

verbose

should large queries print out progress.

Examples

## Not run: url <- "https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0101/BE0101A/BefolkningNy"px_meta_data <- pxweb_get(url)url <- "https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0101"px_levels <- pxweb_get(url)url <- "https://api.scb.se/OV0104/v1/doris/sv"px_levels <- pxweb_get(url)url <- "https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0101/BE0101A/BefolkningNy"query <- file.path(  system.file(package = "pxweb"),  "extdata", "examples", "json_query_example.json")px_data <- pxweb_get(url = url, query = query)# Convert to data.frameas.data.frame(px_data, column.name.type = "text", variable.value.type = "text")# Get raw dataas.matrix(px_data, column.name.type = "code", variable.value.type = "code")# Get data commentspxweb_data_comments(px_data)# Get jsonstat datajstat <- query <- file.path(  system.file(package = "pxweb"),  "extdata", "examples", "json-stat_query_example.json")jstat_data <- pxweb_get(url = url, query = query)# Get very large datasets (multiple downloads needed)big_query <- file.path(  system.file(package = "pxweb"),  "extdata", "examples", "json_big_query_example.json")px_data <- pxweb_get(url = url, query = big_query)## End(Not run)

Build api test data.frame

Description

Build api test data.frame

Usage

pxweb_get_api_test_data_frame(x)

Arguments

x

a pxweb object


Do a GET call to PXWEB API and return a data.frame

Description

Do a GET call to PXWEB API and return a data.frame

Usage

pxweb_get_data(  url,  query,  verbose = TRUE,  column.name.type = "text",  variable.value.type = "text")

Arguments

url

apxweb object or url that can be coherced to apxweb object.

query

a json string, json file or list object that can be coherced to apxweb_query object.

verbose

should large queries print out progress.

column.name.type

character: shouldcode ortext be used as column names?

variable.value.type

character: shouldcode ortext be used as values in columns?

Details

The functions use will do apxweb_query to a PXWEBurl and return adata.frame.This is a wrapper for thepxweb_get function.

See Also

Seepxweb_get for mor general usage andpxweb_query for details on PXWEB queries.

Examples

## Not run: url <- "https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0101/BE0101A/BefolkningNy"query <- file.path(  system.file(package = "pxweb"),  "extdata", "examples", "json_query_example.json")df <- pxweb_get_data(url = url, query = query)## End(Not run)

Setup a structure to log all API calls

Description

Setup a structure to log all API calls

Usage

pxweb_http_log_on(fn = "log_pxweb_api_http_calls.txt")pxweb_http_log_off()pxweb_log_paths_path()pxweb_http_log_is_on()pxweb_http_log_response(r)pxweb_response_to_log_as_json(r)

Arguments

fn

The file name of the log file.

Details

Set up internal structure to handle http PXWEB API calls. http calls are stored in a log file.To access the path to this log file, the path is stored in the pxweb folder in the tempdir().The path is given bypxweb_log_paths_path().If the file exists, the http calls should be logged (appended) to the log file where the object contains the path.


Find and download data interactively from a PXWEB API

Description

Wrapper function (forpxweb_get) to simply find and download data to the current R session.

Usage

pxweb_interactive(x = NULL)interactive_pxweb(x = NULL)

Arguments

x

The name or alias of the pxweb api to connect to, apxweb object or an url.

Value

The function returns a list with three slots:url: The URL to the dataquery: The query to access the datadata: The downloaded data (if chosen to download data)

See Also

pxweb_get

Examples

pxweb_api_catalogue() # List apis## The examples below can only be run in interactive mode##  x <- pxweb_interactive()##  x <- pxweb_interactive(x = "api.scb.se")##  x <- pxweb_interactive(x = "https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/")##  x <- pxweb_interactive(x = "https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/")

Get input from user

Description

Get input from user

Usage

pxweb_interactive_input(pxe, test_input = NULL)

Arguments

pxe

apxweb_explorer object to get user input for.

test_input

supplying a test input (for testing only).


Construct apxweb_levels object.

Description

An object that contain the levels for a given PXWEB api position.

Usage

pxweb_levels(x)

Arguments

x

a list returned from a PXWEB API to convert to apxweb_levels object.

Value

apxweb_levels object


Construct apxweb_metadata object.

Description

An object that contain the metadata for a given PXWEB table.

Usage

pxweb_metadata(x)

Arguments

x

a list returned from a PXWEB API to convert to apxweb_metadata object.

Value

apxweb_metadata object


Add values to NULL value variables in PXWEB metadata objects

Description

Add values to NULL value variables in PXWEB metadata objects

Usage

pxweb_metadata_add_null_values(x, px)

Arguments

x

an object to check if is apxweb_metadata object to which we should add values.

px

apxweb object

Details

Some metadata objects may have NULL values. In these cases the values are downloaded and addedto the metadata object.


Compue the dimension of a metadata object

Description

Compue the dimension of a metadata object

Usage

pxweb_metadata_dim(pxmd)

Arguments

pxmd

apxweb_metadata object.


Get boolean vector

Description

Get boolean vector

Usage

pxweb_metadata_elimination(pxmd)

Arguments

pxmd

apxweb_metadata object.

Value

pxweb_metadata eliminations as a named boolean vector.


Get boolean vector

Description

Get boolean vector

Usage

pxweb_metadata_time(pxmd)

Arguments

pxmd

apxweb_metadata object.

Value

pxweb_metadata eliminations as a named boolean vector.


Parse the response from a PXWEB API (advanced)

Description

The function parses the response from a call made to a PXWEB APIusing thehttr R package. In this way it is possible to parse thecontent of calls made outside the pxweb R package.

Usage

pxweb_parse_response(x)is_pxweb_response(x)

Arguments

x

ahttr response object from a PXWEB call.


Create a PXWEB query

Description

Creates a pxweb query object from either a list with named values,a json query file or json query string. See examples below.

Usage

pxweb_query(x)## S3 method for class 'character'pxweb_query(x)## S3 method for class 'json'pxweb_query(x)## S3 method for class 'pxweb_query'pxweb_query(x)## S3 method for class 'list'pxweb_query(x)## S3 method for class 'response'pxweb_query(x)## S3 method for class 'pxweb_explorer'pxweb_query(x)

Arguments

x

an object to cast as a pxweb_query object.

See Also

pxweb_query_as_json,pxweb_query_as_rcode

Examples

dims <- list(  Alue = c("*"),  "Asuntokunnan koko" = c("*"),  Talotyyppi = c("S"),  Vuosi = c("*"))pxq1 <- pxweb_query(dims)json_query <- file.path(  system.file(package = "pxweb"),  "extdata", "examples", "json_query_example.json")pxq2 <- pxweb_query(json_query)

Convert apxweb_query object to ajson string

Description

Convert apxweb_query object to ajson string

Usage

pxweb_query_as_json(pxq, ...)

Arguments

pxq

apxweb_query object.

...

further argument tojsonlite::toJSON().

See Also

pxweb_query,pxweb_query_as_rcode

Examples

json_query <- file.path(  system.file(package = "pxweb"),  "extdata", "examples", "json_query_example.json")pxq <- pxweb_query(json_query)json <- pxweb_query_as_json(pxq, pretty = TRUE)

Print apxweb_query object as R code

Description

Print apxweb_query object as R code

Usage

pxweb_query_as_rcode(pxq)

Arguments

pxq

apxweb_query object.

See Also

pxweb_query_as_json,pxweb_query


Compue the dimension of the query

Description

Compue the dimension of the query

Usage

pxweb_query_dim(pxq)

Arguments

pxq

apxweb_query object.


Get vector indicating splittable variables

Description

Get vector indicating splittable variables

Usage

pxweb_query_dim_splittable(pxq, pxmd)

Arguments

pxq

apxweb_query object.

Details

Splitable variables are variables that can be split. Content variables cannot be split,nor variables with filter == "top".

Currently, we can only be sure that time variables and eliminated variables can be split.Hopefully the next API makes this more clear.

Value

a named logical vector.


Get query values

Description

Get query values

Usage

pxweb_query_filter(pxq)

Arguments

pxq

apxweb_query object.

Value

query variable selection filters as a named character vector.


Get query filter

Description

Get query filter

Usage

pxweb_query_values(pxq)

Arguments

pxq

apxweb_query object.

Value

query variable selection values as a named list of character vectors.


Split query in optimal sub-queries

Description

Split query in optimal sub-queries

Usage

pxweb_split_query(pxq, px, pxmd)

Arguments

pxq

apxweb_query object.

px

apxweb object.

pxmd

apxweb_metadata object.

Details

Computes (brute-force) the optimal split of a query tomatch the api maximum value limit. It also take into accountthat time variables and content variables should not be split.Also variables with filter "top" should not be split, sincethe top filter does not supply the individual levels, just anumber. This can probably be improved further.

Value

a list withpxweb_query objects.


Setup temorary directory for the pxweb

Description

Setup temorary directory for the pxweb

Usage

pxweb_tempdir(to = "apis")

Arguments

to

to what part of the temp folder (apis or logs)


Test a full or a part of a PXWEB api.

Description

The function can be used to test a whole pxweb api by using the api base url.By using a branch in a tree the api is tested below this branch.

Usage

pxweb_test_api(  url,  test_type = "first",  n = 1,  verbose = TRUE,  time_limit = Inf)

Arguments

url

The base url to the pxweb api (or a branch of the metadata tree)

test_type

What type of test should be done.Thefirst observation of each table.A randomsample of sizen.Download allfull tables.touch the api by only downloading the first table metadata.This is minimal testing of the API.

n

sample size iftest_type issample.

verbose

The function will print information.

time_limit

Time limit in second the API is allowed to be tested.

Value

Function returns a data.frame with information on each nodeTwo variables are added:checked : The node has been checkederror : Whether there were errors encountered with the calldownload_error : Whether there were errors encountered during download

Examples

## Not run: url <- "https://bank.stat.gl/api/v1/en/Greenland/BE/BE01"res <- pxweb_test_api(url)res <- pxweb_test_api(url, test_type = "touch")## End(Not run)

Create all paths from a list of pxweb_api_catalogue entries

Description

Create all paths from a list of pxweb_api_catalogue entries

Usage

pxweb_test_create_api_paths(apis)

Arguments

apis

a list of pxweb_api_catalogue_entry elements


Test time limit object

Description

Test time limit object

Usage

pxweb_test_time_limit(time_limit)is_test_time_limit_reached(x)

Arguments

time_limit

the number of seconds the API will be tested.

Details

Used to limit testing of API:s.


Validate apxweb_query with apxweb_metadata object

Description

Validate apxweb_query with apxweb_metadata object

Usage

pxweb_validate_query_with_metadata(pxq, pxmd)

Arguments

pxq

apxweb_query object.

pxmd

apxweb_metadata object.

Details

Validate a query with a metadata object to asses that the query can be used toquery the table.

Examples

## Not run: 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")pxq <- pxweb_query(json_query)pxweb_validate_query_with_metadata(pxq, pxweb_get(url))## End(Not run)

Save and loadpxweb objects from R temp folder

Description

Save and loadpxweb objects from R temp folder

Usage

save_pxweb(obj)load_pxweb(obj)load_pxweb_calls(obj)load_pxweb_config(obj)load_pxweb_api_subpath(obj)

Arguments

obj

apxweb object


Split variables into chunks

Description

Split variables into chunks

Usage

split_dimensions_left_right(x, bool, max_size)

Details

Splitable variables are variables that can be split. Content variables cannot be split,not variables with filter == "top"

Value

apxweb_split_dimensions


Pad a string to a fixed size

Description

Pad a string to a fixed size

Usage

str_pad(txt, n = 5, pad = " ", type = "left")

Arguments

txt

a character vector to pad

n

final char width

pad

pad symbol

type

pad from 'left' or 'right'.


Taken fromtrimws for reasons of compatibility with previous R versios.

Description

Taken fromtrimws for reasons of compatibility with previous R versios.

Usage

str_trim(x, which = c("both", "left", "right"))

Arguments

x

a string to trim.

which

how to trim the string.

See Also

trimws


[8]ページ先頭

©2009-2025 Movatter.jp