Title: | Make PX-Files in R |
---|---|
Description: | Create PX-files from scratch or read and modify existing ones. Includes a function for every PX keyword, making metadata manipulation simple and human-readable. |
Authors: | Johan Ejstrud [cre, aut], Lars Pedersen [aut], Statistics Greenland [cph] (https://stat.gl/) |
Maintainer: | Johan Ejstrud <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.15.1.9000 |
Built: | 2025-02-17 14:26:33 UTC |
Source: | https://github.com/statisticsgreenland/pxmake |
Example data set to create age classification with aggreations form 10 and 25 years classes.
age_classification
age_classification
A data frame:
Value code
Value text
Aggregtation into 10 years classes
Aggregtation into 25 years classes
A fictive data set with demographic data for Greenlanders split in two cohorts.
greenlanders
greenlanders
An object of class tbl_df
(inherits from tbl
, data.frame
) with 100 rows and 4 columns.
A subset of the population count data available in Statistic Greenland's BEESTA table.
population_gl
population_gl
An object of class tbl_df
(inherits from tbl
, data.frame
) with 30 rows and 4 columns.
https://bank.stat.gl/pxweb/en/Greenland/Greenland__BE__BE01__BE0120/BEXSTA.px/
Create a px object from a PX-file, an Excel metadata workbook, or a data frame.
px(input = NULL, data = NULL, validate = TRUE)
px(input = NULL, data = NULL, validate = TRUE)
input |
Optional character string. Can be:
If input is a data frame or NULL, a px object with minimal metadata is created. |
data |
Either a data frame or a path to an |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object
# Create px object from dataset x1 <- px(population_gl) # Create px object from PX-file px_path <- tempfile(fileext = ".px") url <- "https://bank.stat.gl:443/sq/0cf06962-19f1-4d5c-8d43-b7ed0009617d" download.file(url, px_path) x2 <- px(px_path) # Create px object from URL x3 <- px(url) # Create minimal px object x4 <- px()
# Create px object from dataset x1 <- px(population_gl) # Create px object from PX-file px_path <- tempfile(fileext = ".px") url <- "https://bank.stat.gl:443/sq/0cf06962-19f1-4d5c-8d43-b7ed0009617d" download.file(url, px_path) x2 <- px(px_path) # Create px object from URL x3 <- px(url) # Create minimal px object x4 <- px()
Adds a total level, which is the sum of the figures for all other levels of the variable. NA values are ignored when calculating the sum.
The default name of the total level is 'Total', unless px_elimination is set, in which case the elimination value becomes the name of the total level.
px_add_totals(x, value, na.rm = TRUE, validate) ## S3 method for class 'px' px_add_totals(x, value, na.rm = TRUE, validate = TRUE)
px_add_totals(x, value, na.rm = TRUE, validate) ## S3 method for class 'px' px_add_totals(x, value, na.rm = TRUE, validate = TRUE)
x |
A px object |
value |
A character vector of variables to add total levels to. |
na.rm |
Optional. Logical. If TRUE, NAs are removed before summing. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object
# Create small px object example x0 <- px(subset(population_gl, age == "65+")) x0$data # Add total level to one variable x1 <- px_add_totals(x0, "gender") x1$data # Add total level to multiple variables x2 <- px_add_totals(x0, c("gender", "age")) x2$data # The name of the total level can be changed with px_elimination() x3 <- x0 |> px_elimination("T") |> px_add_totals("gender") x3$data
# Create small px object example x0 <- px(subset(population_gl, age == "65+")) x0$data # Add total level to one variable x1 <- px_add_totals(x0, "gender") x1$data # Add total level to multiple variables x2 <- px_add_totals(x0, c("gender", "age")) x2$data # The name of the total level can be changed with px_elimination() x3 <- x0 |> px_elimination("T") |> px_add_totals("gender") x3$data
Inspect or change AGGREGALLOWED.
px_aggregallowed(x, value, validate) ## S3 method for class 'px' px_aggregallowed(x, value, validate = TRUE)
px_aggregallowed(x, value, validate) ## S3 method for class 'px' px_aggregallowed(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current AGGREGALLOWED is returned. If NULL, AGGREGALLOWED is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set AGGREGALLOWED x1 <- px(population_gl) |> px_aggregallowed('NO') # Print AGGREGALLOWED px_aggregallowed(x1) # Remove AGGREGALLOWED x2 <- px_aggregallowed(x1, NULL) px_aggregallowed(x2)
# Set AGGREGALLOWED x1 <- px(population_gl) |> px_aggregallowed('NO') # Print AGGREGALLOWED px_aggregallowed(x1) # Remove AGGREGALLOWED x2 <- px_aggregallowed(x1, NULL) px_aggregallowed(x2)
Inspect or change AUTOPEN.
px_autopen(x, value, validate) ## S3 method for class 'px' px_autopen(x, value, validate = TRUE)
px_autopen(x, value, validate) ## S3 method for class 'px' px_autopen(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current AUTOPEN is returned. If NULL, AUTOPEN is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set AUTOPEN x1 <- px(population_gl) |> px_autopen('YES') # Print AUTOPEN px_autopen(x1) # Remove AUTOPEN x2 <- px_autopen(x1, NULL) px_autopen(x2)
# Set AUTOPEN x1 <- px(population_gl) |> px_autopen('YES') # Print AUTOPEN px_autopen(x1) # Remove AUTOPEN x2 <- px_autopen(x1, NULL) px_autopen(x2)
Inspect or change AXIS-VERSION.
px_axis_version(x, value, validate) ## S3 method for class 'px' px_axis_version(x, value, validate = TRUE)
px_axis_version(x, value, validate) ## S3 method for class 'px' px_axis_version(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current AXIS-VERSION is returned. If NULL, AXIS-VERSION is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set AXIS-VERSION x1 <- px(population_gl) |> px_axis_version('2010') # Print AXIS-VERSION px_axis_version(x1) # Remove AXIS-VERSION x2 <- px_axis_version(x1, NULL) px_axis_version(x2)
# Set AXIS-VERSION x1 <- px(population_gl) |> px_axis_version('2010') # Print AXIS-VERSION px_axis_version(x1) # Remove AXIS-VERSION x2 <- px_axis_version(x1, NULL) px_axis_version(x2)
Inspect or change BASEPERIOD.
px_baseperiod(x, value, validate) ## S3 method for class 'px' px_baseperiod(x, value, validate = TRUE)
px_baseperiod(x, value, validate) ## S3 method for class 'px' px_baseperiod(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string to set the value for all languages or a data frame with columns 'language' and 'value' to set it for specific languages. If 'value' is missing, the current BASEPERIOD is returned. If NULL, BASEPERIOD is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set BASEPERIOD for all languages x1 <- px(population_gl) |> px_baseperiod('year') # Print BASEPERIOD px_baseperiod(x1) # Set BASEPERIOD for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_baseperiod(tribble(~language, ~value, 'en', 'year', 'kl', 'ukioq')) px_baseperiod(x2) # Remove BASEPERIOD x3 <- px_baseperiod(x2, NULL) px_baseperiod(x3)
# Set BASEPERIOD for all languages x1 <- px(population_gl) |> px_baseperiod('year') # Print BASEPERIOD px_baseperiod(x1) # Set BASEPERIOD for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_baseperiod(tribble(~language, ~value, 'en', 'year', 'kl', 'ukioq')) px_baseperiod(x2) # Remove BASEPERIOD x3 <- px_baseperiod(x2, NULL) px_baseperiod(x3)
Inspect or change CELLNOTE.
px_cellnote(x, value, na_to_star, validate) ## S3 method for class 'px' px_cellnote(x, value, na_to_star = TRUE, validate = TRUE)
px_cellnote(x, value, na_to_star, validate) ## S3 method for class 'px' px_cellnote(x, value, na_to_star = TRUE, validate = TRUE)
x |
A px object |
value |
Optional. A data frame with columns 'cellnote' and one or more columns with the names of the STUB and HEADING variables. The 'cellnote' column is the cellnote text, and the STUB/HEADING columns control which cells the note applies to. Use star (*) if a note applies to all cells in a variable. Use column 'language' to set CELLNOTE for specific languages. If 'value' is missing, the current CELLNOTE is returned. If value is NULL, CELLNOTE is removed. |
na_to_star |
Optional. Convert all NAs to '*'. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or data frame.
Statistics Sweden's documentation
# Set CELLNOTE for a value library(tibble) x1 <- population_gl |> px() |> px_cellnote( tribble(~gender, ~age, ~year, ~cellnote, 'male', '0-6', '2004', 'Approximation')) x2 <- x1 |> px_cellnote( tribble(~gender, ~age, ~year, ~cellnote, 'female', '*', '2014', 'Uncertainty in ages')) # Print CELLNOTE px_cellnote(x2) # Set CELLNOTE in multiple languagese x3 <- x1 |> px_languages(c('en', 'kl')) |> px_cellnote( tribble(~age, ~year, ~language, ~cellnote, '*', '2003', 'en', 'Some of the figures are from 2003', '*', '2003', 'kl', 'Kisitsisit ilaat 2003-imeersuupput')) px_cellnote(x3) # Remove CELLNOTE x4 <- px_cellnote(x3, NULL) px_cellnote(x4)
# Set CELLNOTE for a value library(tibble) x1 <- population_gl |> px() |> px_cellnote( tribble(~gender, ~age, ~year, ~cellnote, 'male', '0-6', '2004', 'Approximation')) x2 <- x1 |> px_cellnote( tribble(~gender, ~age, ~year, ~cellnote, 'female', '*', '2014', 'Uncertainty in ages')) # Print CELLNOTE px_cellnote(x2) # Set CELLNOTE in multiple languagese x3 <- x1 |> px_languages(c('en', 'kl')) |> px_cellnote( tribble(~age, ~year, ~language, ~cellnote, '*', '2003', 'en', 'Some of the figures are from 2003', '*', '2003', 'kl', 'Kisitsisit ilaat 2003-imeersuupput')) px_cellnote(x3) # Remove CELLNOTE x4 <- px_cellnote(x3, NULL) px_cellnote(x4)
Inspect or change CELLNOTEX.
px_cellnotex(x, value, na_to_star, validate) ## S3 method for class 'px' px_cellnotex(x, value, na_to_star = TRUE, validate = TRUE)
px_cellnotex(x, value, na_to_star, validate) ## S3 method for class 'px' px_cellnotex(x, value, na_to_star = TRUE, validate = TRUE)
x |
A px object |
value |
Optional. A data frame with columns 'cellnotex' and one or more columns with the names of the STUB and HEADING variables. The 'cellnotex' column is the cellnotex text, and the STUB/HEADING columns control which cells the note applies to. Use star (*) if a note applies to all cells in a variable. Use column 'language' to set CELLNOTEX for specific languages. If 'value' is missing, the current CELLNOTEX is returned. If value is NULL, CELLNOTEX is removed. |
na_to_star |
Optional. Convert all NAs to '*'. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or data frame.
Statistics Sweden's documentation
# Set CELLNOTEX for a value library(tibble) x1 <- population_gl |> px() |> px_cellnotex( tribble(~gender, ~age, ~year, ~cellnote, 'male', '0-6', '2004', 'Approximation')) x2 <- x1 |> px_cellnote( tribble(~gender, ~age, ~year, ~cellnote, 'female', '*', '2014', 'Uncertainty in ages')) # Print CELLNOTEX px_cellnotex(x2) # Set CELLNOTEX in multiple languagese x3 <- x1 |> px_languages(c('en', 'kl')) |> px_cellnotex( tribble(~age, ~year, ~language, ~cellnote, '*', '2003', 'en', 'Some of the figures are from 2003', '*', '2003', 'kl', 'Kisitsisit ilaat 2003-imeersuupput')) px_cellnotex(x3) # Remove CELLNOTEX x4 <- px_cellnotex(x3, NULL) px_cellnotex(x4)
# Set CELLNOTEX for a value library(tibble) x1 <- population_gl |> px() |> px_cellnotex( tribble(~gender, ~age, ~year, ~cellnote, 'male', '0-6', '2004', 'Approximation')) x2 <- x1 |> px_cellnote( tribble(~gender, ~age, ~year, ~cellnote, 'female', '*', '2014', 'Uncertainty in ages')) # Print CELLNOTEX px_cellnotex(x2) # Set CELLNOTEX in multiple languagese x3 <- x1 |> px_languages(c('en', 'kl')) |> px_cellnotex( tribble(~age, ~year, ~language, ~cellnote, '*', '2003', 'en', 'Some of the figures are from 2003', '*', '2003', 'kl', 'Kisitsisit ilaat 2003-imeersuupput')) px_cellnotex(x3) # Remove CELLNOTEX x4 <- px_cellnotex(x3, NULL) px_cellnotex(x4)
Inspect or change CFPRICES.
px_cfprices(x, value, validate) ## S3 method for class 'px' px_cfprices(x, value, validate = TRUE)
px_cfprices(x, value, validate) ## S3 method for class 'px' px_cfprices(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string to set the value for all languages or a data frame with columns 'language' and 'value' to set it for specific languages. If 'value' is missing, the current CFPRICES is returned. If NULL, CFPRICES is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set CFPRICES for all languages x1 <- px(population_gl) |> px_cfprices('C') # Print CFPRICES px_cfprices(x1) # Set CFPRICES for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_cfprices(tribble(~language, ~value, 'en', 'C', 'kl', 'F')) px_cfprices(x2) # Remove CFPRICES x3 <- px_cfprices(x2, NULL) px_cfprices(x3)
# Set CFPRICES for all languages x1 <- px(population_gl) |> px_cfprices('C') # Print CFPRICES px_cfprices(x1) # Set CFPRICES for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_cfprices(tribble(~language, ~value, 'en', 'C', 'kl', 'F')) px_cfprices(x2) # Remove CFPRICES x3 <- px_cfprices(x2, NULL) px_cfprices(x3)
Inspect or change CHARSET.
px_charset(x, value, validate) ## S3 method for class 'px' px_charset(x, value, validate = TRUE)
px_charset(x, value, validate) ## S3 method for class 'px' px_charset(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current CHARSET is returned. If NULL, CHARSET is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set CHARSET x1 <- px(population_gl) |> px_charset('ANSI') # Print CHARSET px_charset(x1) # Remove CHARSET x2 <- px_charset(x1, NULL) px_charset(x2)
# Set CHARSET x1 <- px(population_gl) |> px_charset('ANSI') # Print CHARSET px_charset(x1) # Remove CHARSET x2 <- px_charset(x1, NULL) px_charset(x2)
Create a classification object from a data frame or .vs and .agg files.
px_classification(name, prestext, domain, df, vs_path, agg_paths)
px_classification(name, prestext, domain, df, vs_path, agg_paths)
name |
Optional. Name of the classification. |
prestext |
Optional. Presentation text. |
domain |
Optional. Character vector with domain names. Used to link to PX-file. |
df |
Optional. A data frame with required column 'valuecode' and optional column 'valuetext', if the codes have texts. Each additional column represents an aggregation. The column name is the name of the aggregation. |
vs_path |
Optional. Path to a values set (.vs) file. |
agg_paths |
Optional.
|
A classification is a combination of a value set and zero, one, or more
aggregations. The classification can be saved as .vs and .agg files
(see px_save_classification()
).
If a classification is created from a data frame, the arguments name
and
prestext
and domain
are required. If a classification is created from .vs
and .agg files, all other arguments should be empty.
Only type 'V' value sets are supported. Type 'H' and 'N' value sets are not supported.
A classification object
# Create classification from data frame library(tibble) c1 <- px_classification(name = "Age5", prestext = "Ages 0-9 - 60+", domain = "age", df = tribble( ~valuecode, ~valuetext, ~`25 years classes`, "0-4", "0-4 years", "0-24", "5-9", "5-9 years", "0-24", "10-14", "10-14 years", "0-24", "15-19", "15-19 years", "0-24", "20-24", "20-24 years", "0-24", "25-29", "25-29 years", "25-49", "30-34", "30-34 years", "25-49", "35-39", "35-39 years", "25-49", "40-44", "40-44 years", "25-49", "45-49", "45-49 years", "25-49", "50-54", "50-54 years", "50-74", "55-59", "55-59 years", "50-74", "60-64", "60-64 years", "50-74", "65-69", "65-69 years", "50-74", "70-74", "70-74 years", "50-74", "75+", "75+ years", "75+" ) ) # Create classifications from files vs_file <- system.file("extdata", "Age5.vs", package = "pxmake") agg_files <- c( system.file("extdata", "10-years_classes.agg", package = "pxmake"), system.file("extdata", "25-years_classes.agg", package = "pxmake") ) if (vs_file != "" & all(agg_files != "")) { # Create classification from .vs file and use aggregations mentioned in .vs c2 <- px_classification(vs_path = vs_file) # Create classification from .vs file and manually specify aggregation files c3 <- px_classification(vs_path = vs_file, agg_paths = agg_files ) identical(c2, c3) }
# Create classification from data frame library(tibble) c1 <- px_classification(name = "Age5", prestext = "Ages 0-9 - 60+", domain = "age", df = tribble( ~valuecode, ~valuetext, ~`25 years classes`, "0-4", "0-4 years", "0-24", "5-9", "5-9 years", "0-24", "10-14", "10-14 years", "0-24", "15-19", "15-19 years", "0-24", "20-24", "20-24 years", "0-24", "25-29", "25-29 years", "25-49", "30-34", "30-34 years", "25-49", "35-39", "35-39 years", "25-49", "40-44", "40-44 years", "25-49", "45-49", "45-49 years", "25-49", "50-54", "50-54 years", "50-74", "55-59", "55-59 years", "50-74", "60-64", "60-64 years", "50-74", "65-69", "65-69 years", "50-74", "70-74", "70-74 years", "50-74", "75+", "75+ years", "75+" ) ) # Create classifications from files vs_file <- system.file("extdata", "Age5.vs", package = "pxmake") agg_files <- c( system.file("extdata", "10-years_classes.agg", package = "pxmake"), system.file("extdata", "25-years_classes.agg", package = "pxmake") ) if (vs_file != "" & all(agg_files != "")) { # Create classification from .vs file and use aggregations mentioned in .vs c2 <- px_classification(vs_path = vs_file) # Create classification from .vs file and manually specify aggregation files c3 <- px_classification(vs_path = vs_file, agg_paths = agg_files ) identical(c2, c3) }
Inspect or change CODEPAGE.
px_codepage(x, value, validate) ## S3 method for class 'px' px_codepage(x, value, validate = TRUE)
px_codepage(x, value, validate) ## S3 method for class 'px' px_codepage(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current CODEPAGE is returned. If NULL, CODEPAGE is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
CODEPAGE controls which encoding PX-files are read and stored in.
Use iconvlist()
to see available encodings on your system.
A px object or a character string.
Statistics Sweden's documentation
# Set CODEPAGE x1 <- px(population_gl) |> px_codepage('utf-8') # Print CODEPAGE px_codepage(x1) # Remove CODEPAGE x2 <- px_codepage(x1, NULL) px_codepage(x2)
# Set CODEPAGE x1 <- px(population_gl) |> px_codepage('utf-8') # Print CODEPAGE px_codepage(x1) # Remove CODEPAGE x2 <- px_codepage(x1, NULL) px_codepage(x2)
Inspect or change CONFIDENTIAL.
px_confidential(x, value, validate) ## S3 method for class 'px' px_confidential(x, value, validate = TRUE)
px_confidential(x, value, validate) ## S3 method for class 'px' px_confidential(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current CONFIDENTIAL is returned. If NULL, CONFIDENTIAL is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set CONFIDENTIAL x1 <- px(population_gl) |> px_confidential('1') # Print CONFIDENTIAL px_confidential(x1) # Remove CONFIDENTIAL x2 <- px_confidential(x1, NULL) px_confidential(x2)
# Set CONFIDENTIAL x1 <- px(population_gl) |> px_confidential('1') # Print CONFIDENTIAL px_confidential(x1) # Remove CONFIDENTIAL x2 <- px_confidential(x1, NULL) px_confidential(x2)
Inspect or change CONTACT.
px_contact(x, value, validate) ## S3 method for class 'px' px_contact(x, value, validate = TRUE)
px_contact(x, value, validate) ## S3 method for class 'px' px_contact(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string to set the value for all languages or a data frame with columns 'language' and 'value' to set it for specific languages. If 'value' is missing, the current CONTACT is returned. If NULL, CONTACT is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set CONTACT for all languages x1 <- px(population_gl) |> px_contact('Johan Ejstrud') # Print CONTACT px_contact(x1) # Set CONTACT for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_contact(tribble(~language, ~value, 'en', 'Johan Ejstrud', 'kl', 'Lars Pedersen')) px_contact(x2) # Remove CONTACT x3 <- px_contact(x2, NULL) px_contact(x3)
# Set CONTACT for all languages x1 <- px(population_gl) |> px_contact('Johan Ejstrud') # Print CONTACT px_contact(x1) # Set CONTACT for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_contact(tribble(~language, ~value, 'en', 'Johan Ejstrud', 'kl', 'Lars Pedersen')) px_contact(x2) # Remove CONTACT x3 <- px_contact(x2, NULL) px_contact(x3)
Inspect or change CONTENTS.
px_contents(x, value, validate) ## S3 method for class 'px' px_contents(x, value, validate = TRUE)
px_contents(x, value, validate) ## S3 method for class 'px' px_contents(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string to set the value for all languages or a data frame with columns 'language' and 'value' to set it for specific languages. If 'value' is missing, the current CONTENTS is returned. If NULL, an error is thrown because CONTENTS cannot be removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set CONTENTS for all languages x1 <- px(population_gl) |> px_contents('Population') # Print CONTENTS px_contents(x1) # Set CONTENTS for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_contents(tribble(~language, ~value, 'en', 'Population', 'kl', 'Innuttaasut')) px_contents(x2)
# Set CONTENTS for all languages x1 <- px(population_gl) |> px_contents('Population') # Print CONTENTS px_contents(x1) # Set CONTENTS for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_contents(tribble(~language, ~value, 'en', 'Population', 'kl', 'Innuttaasut')) px_contents(x2)
Inspect or change CONTVARIABLE.
Setting CONTVARIABLE indexes several variables in table2. Removing CONTVARIABLE removes the indexing from table2.
px_contvariable(x, value, validate) ## S3 method for class 'px' px_contvariable(x, value, validate = TRUE)
px_contvariable(x, value, validate) ## S3 method for class 'px' px_contvariable(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current CONTVARIABLE is returned. If NULL, CONTVARIABLE is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set CONTVARIABLE x1 <- px(population_gl) |> px_contvariable('gender') # After setting CONTVARIABLE some variables are index by it, e.g. UNITS px_units(x1) # Remove CONTVARIABLE x2 <- px_contvariable(x1, NULL) px_contvariable(x2) # Removing CONTVARIABLE also removes the index from UNITS px_units(x2)
# Set CONTVARIABLE x1 <- px(population_gl) |> px_contvariable('gender') # After setting CONTVARIABLE some variables are index by it, e.g. UNITS px_units(x1) # Remove CONTVARIABLE x2 <- px_contvariable(x1, NULL) px_contvariable(x2) # Removing CONTVARIABLE also removes the index from UNITS px_units(x2)
Inspect or change COPYRIGHT.
px_copyright(x, value, validate) ## S3 method for class 'px' px_copyright(x, value, validate = TRUE)
px_copyright(x, value, validate) ## S3 method for class 'px' px_copyright(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current COPYRIGHT is returned. If NULL, COPYRIGHT is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set COPYRIGHT x1 <- px(population_gl) |> px_copyright('YES') # Print COPYRIGHT px_copyright(x1) # Remove COPYRIGHT x2 <- px_copyright(x1, NULL) px_copyright(x2)
# Set COPYRIGHT x1 <- px(population_gl) |> px_copyright('YES') # Print COPYRIGHT px_copyright(x1) # Remove COPYRIGHT x2 <- px_copyright(x1, NULL) px_copyright(x2)
Inspect or change CREATION-DATE.
px_creation_date(x, value, validate) ## S3 method for class 'px' px_creation_date(x, value, validate = TRUE)
px_creation_date(x, value, validate) ## S3 method for class 'px' px_creation_date(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current CREATION-DATE is returned. If NULL, CREATION-DATE is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set CREATION-DATE x1 <- px(population_gl) |> px_creation_date('19960612 14:20') # Print CREATION-DATE px_creation_date(x1) # Remove CREATION-DATE x2 <- px_creation_date(x1, NULL) px_creation_date(x2)
# Set CREATION-DATE x1 <- px(population_gl) |> px_creation_date('19960612 14:20') # Print CREATION-DATE px_creation_date(x1) # Remove CREATION-DATE x2 <- px_creation_date(x1, NULL) px_creation_date(x2)
Inspect or change DATA.
px_data(x, value, validate) ## S3 method for class 'px' px_data(x, value, validate = TRUE)
px_data(x, value, validate) ## S3 method for class 'px' px_data(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A data frame. If missing, the current DATA is returned. If NULL, all data rows are removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
It is not recommended to change the data table of a px object with this function, since it does update any metadata.
A px object or data frame.
Statistics Sweden's documentation
x1 <- px(population_gl) # Print data table px_data(x1) # Change data table (risky business) population_gl_2024 <- subset(population_gl, year == 2024) x2 <- px_data(x1, population_gl_2024)
x1 <- px(population_gl) # Print data table px_data(x1) # Change data table (risky business) population_gl_2024 <- subset(population_gl, year == 2024) x2 <- px_data(x1, population_gl_2024)
Inspect or change DECIMALS.
px_decimals(x, value, validate) ## S3 method for class 'px' px_decimals(x, value, validate = TRUE)
px_decimals(x, value, validate) ## S3 method for class 'px' px_decimals(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current DECIMALS is returned. If NULL, an error is thrown because DECIMALS cannot be removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set DECIMALS x1 <- px(population_gl) |> px_decimals('3') # Print DECIMALS px_decimals(x1)
# Set DECIMALS x1 <- px(population_gl) |> px_decimals('3') # Print DECIMALS px_decimals(x1)
Inspect or change DESCRIPTION.
px_description(x, value, validate) ## S3 method for class 'px' px_description(x, value, validate = TRUE)
px_description(x, value, validate) ## S3 method for class 'px' px_description(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string to set the value for all languages or a data frame with columns 'language' and 'value' to set it for specific languages. If 'value' is missing, the current DESCRIPTION is returned. If NULL, DESCRIPTION is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set DESCRIPTION for all languages x1 <- px(population_gl) |> px_description('Population') # Print DESCRIPTION px_description(x1) # Set DESCRIPTION for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_description(tribble(~language, ~value, 'en', 'Population', 'kl', 'Innuttaasut')) px_description(x2) # Remove DESCRIPTION x3 <- px_description(x2, NULL) px_description(x3)
# Set DESCRIPTION for all languages x1 <- px(population_gl) |> px_description('Population') # Print DESCRIPTION px_description(x1) # Set DESCRIPTION for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_description(tribble(~language, ~value, 'en', 'Population', 'kl', 'Innuttaasut')) px_description(x2) # Remove DESCRIPTION x3 <- px_description(x2, NULL) px_description(x3)
Inspect or change DESCRIPTIONDEFAULT.
px_descriptiondefault(x, value, validate) ## S3 method for class 'px' px_descriptiondefault(x, value, validate = TRUE)
px_descriptiondefault(x, value, validate) ## S3 method for class 'px' px_descriptiondefault(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current DESCRIPTIONDEFAULT is returned. If NULL, DESCRIPTIONDEFAULT is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set DESCRIPTIONDEFAULT x1 <- px(population_gl) |> px_descriptiondefault('YES') # Print DESCRIPTIONDEFAULT px_descriptiondefault(x1) # Remove DESCRIPTIONDEFAULT x2 <- px_descriptiondefault(x1, NULL) px_descriptiondefault(x2)
# Set DESCRIPTIONDEFAULT x1 <- px(population_gl) |> px_descriptiondefault('YES') # Print DESCRIPTIONDEFAULT px_descriptiondefault(x1) # Remove DESCRIPTIONDEFAULT x2 <- px_descriptiondefault(x1, NULL) px_descriptiondefault(x2)
Inspect or change DOMAIN.
px_domain(x, value, validate) ## S3 method for class 'px' px_domain(x, value, validate = TRUE)
px_domain(x, value, validate) ## S3 method for class 'px' px_domain(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string or data frame.
|
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set DOMAIN for all languages x1 <- px(population_gl) |> px_domain('aggregation1') # Print DOMAIN px_domain(x1) # Set DOMAIN for individual variables library(tibble) x2 <- x1 |> px_domain(tribble(~`variable-code`, ~domain, 'gender', 'aggregation2', 'age', 'aggregation3')) px_domain(x2) # Set DOMAIN for individual languages x3 <- x2 %>% px_languages(c('en', 'kl')) |> px_domain(tribble(~`variable-code`, ~language, ~domain, 'gender', 'en', 'aggregation2_en', 'gender', 'kl', 'aggregation2_kl', 'age', 'en', 'aggregation3_en')) px_domain(x3) # Remove DOMAIN x4 <- px_domain(x3, NULL) px_domain(x4)
# Set DOMAIN for all languages x1 <- px(population_gl) |> px_domain('aggregation1') # Print DOMAIN px_domain(x1) # Set DOMAIN for individual variables library(tibble) x2 <- x1 |> px_domain(tribble(~`variable-code`, ~domain, 'gender', 'aggregation2', 'age', 'aggregation3')) px_domain(x2) # Set DOMAIN for individual languages x3 <- x2 %>% px_languages(c('en', 'kl')) |> px_domain(tribble(~`variable-code`, ~language, ~domain, 'gender', 'en', 'aggregation2_en', 'gender', 'kl', 'aggregation2_kl', 'age', 'en', 'aggregation3_en')) px_domain(x3) # Remove DOMAIN x4 <- px_domain(x3, NULL) px_domain(x4)
Inspect or change ELIMINATION.
px_elimination(x, value, validate) ## S3 method for class 'px' px_elimination(x, value, validate = TRUE)
px_elimination(x, value, validate) ## S3 method for class 'px' px_elimination(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string or data frame.
|
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set ELIMINATION for all languages x1 <- px(population_gl) |> px_elimination('YES') # Print ELIMINATION px_elimination(x1) # Set ELIMINATION for individual variables library(tibble) x2 <- x1 |> px_elimination(tribble(~`variable-code`, ~elimination, 'gender', 'All', 'age', 'Total')) px_elimination(x2) # Set ELIMINATION for individual languages x3 <- x2 %>% px_languages(c('en', 'kl')) |> px_elimination(tribble(~`variable-code`, ~language, ~elimination, 'gender', 'en', 'All_en', 'gender', 'kl', 'All_kl', 'age', 'en', 'Total_en')) px_elimination(x3) # Remove ELIMINATION x4 <- px_elimination(x3, NULL) px_elimination(x4)
# Set ELIMINATION for all languages x1 <- px(population_gl) |> px_elimination('YES') # Print ELIMINATION px_elimination(x1) # Set ELIMINATION for individual variables library(tibble) x2 <- x1 |> px_elimination(tribble(~`variable-code`, ~elimination, 'gender', 'All', 'age', 'Total')) px_elimination(x2) # Set ELIMINATION for individual languages x3 <- x2 %>% px_languages(c('en', 'kl')) |> px_elimination(tribble(~`variable-code`, ~language, ~elimination, 'gender', 'en', 'All_en', 'gender', 'kl', 'All_kl', 'age', 'en', 'Total_en')) px_elimination(x3) # Remove ELIMINATION x4 <- px_elimination(x3, NULL) px_elimination(x4)
Inspect or change which variable is used as figures. The previous figures variable is changed to STUB. There can only be one figures variable.
px_figures(x, value, validate) ## S3 method for class 'px' px_figures(x, value, validate = TRUE)
px_figures(x, value, validate) ## S3 method for class 'px' px_figures(x, value, validate = TRUE)
x |
A px object |
value |
Optional. Name of variable to use as FIGRUES. If missing, the current PX_FIGURES variable is returned. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string
x1 <- px(population_gl) # Print FIGURES px_figures(x1) # Change 'age' to FIGURES variable, 'n' i changed to STUB x2 <- px_figures(x1, 'age') px_figures(x2) px_stub(x2)
x1 <- px(population_gl) # Print FIGURES px_figures(x1) # Change 'age' to FIGURES variable, 'n' i changed to STUB x2 <- px_figures(x1, 'age') px_figures(x2) px_stub(x2)
Inspect or change HEADING.
px_heading(x, value, validate) ## S3 method for class 'px' px_heading(x, value, validate = TRUE)
px_heading(x, value, validate) ## S3 method for class 'px' px_heading(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character vector of variable names to change to
STUB. This also changes the HEADING order. With names in |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character vector.
Statistics Sweden's documentation
x1 <- px(population_gl) # Print HEADING px_heading(x1) # Add 'gender' to HEADING x2 <- px_heading(x1, 'gender') px_heading(x2) # Change order of HEADING x3 <- px_heading(x2, 'year') px_heading(x3)
x1 <- px(population_gl) # Print HEADING px_heading(x1) # Add 'gender' to HEADING x2 <- px_heading(x1, 'gender') px_heading(x2) # Change order of HEADING x3 <- px_heading(x2, 'year') px_heading(x3)
Inspect or change INFOFILE.
px_infofile(x, value, validate) ## S3 method for class 'px' px_infofile(x, value, validate = TRUE)
px_infofile(x, value, validate) ## S3 method for class 'px' px_infofile(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string to set the value for all languages or a data frame with columns 'language' and 'value' to set it for specific languages. If 'value' is missing, the current INFOFILE is returned. If NULL, INFOFILE is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set INFOFILE for all languages x1 <- px(population_gl) |> px_infofile('infofile_en') # Print INFOFILE px_infofile(x1) # Set INFOFILE for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_infofile(tribble(~language, ~value, 'en', 'infofile_en', 'kl', 'infofile_kl')) px_infofile(x2) # Remove INFOFILE x3 <- px_infofile(x2, NULL) px_infofile(x3)
# Set INFOFILE for all languages x1 <- px(population_gl) |> px_infofile('infofile_en') # Print INFOFILE px_infofile(x1) # Set INFOFILE for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_infofile(tribble(~language, ~value, 'en', 'infofile_en', 'kl', 'infofile_kl')) px_infofile(x2) # Remove INFOFILE x3 <- px_infofile(x2, NULL) px_infofile(x3)
Properties of all px keywords. Used internally by the package.
px_keywords
px_keywords
A data frame:
Name
Function name
Is required in a PX-file
Is metadata for entire table; not individual variables or cells
Is language dependent
Is indexed if CONTVARIABLE is set
Value should be quoted in PX-file
Default value for mandatory keywords
URL to Statistic Sweden's documentation
Recommended order
https://www.scb.se/globalassets/vara-tjanster/px-programmen/PX-file_format_specification_2013.pdf
Inspect or change LANGUAGE.
px_language(x, value, validate) ## S3 method for class 'px' px_language(x, value, validate = TRUE)
px_language(x, value, validate) ## S3 method for class 'px' px_language(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current LANGUAGE is returned. If NULL, LANGUAGE is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
If LANGUAGES is defined, changing LANGUAGE will also add is to LANGUAGES.
A px object
# Set LANGUAGE to 'en' x1 <- population_gl |> px() |> px_language('en') # Print LANGUAGE px_language(x1) # Remove LANGUAGE x2 <- px_language(x1, NULL) px_language(x2)
# Set LANGUAGE to 'en' x1 <- population_gl |> px() |> px_language('en') # Print LANGUAGE px_language(x1) # Remove LANGUAGE x2 <- px_language(x1, NULL) px_language(x2)
Inspect or change LANGUAGES.
px_languages(x, value, validate) ## S3 method for class 'px' px_languages(x, value, validate = TRUE)
px_languages(x, value, validate) ## S3 method for class 'px' px_languages(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character vector. If missing, the current LANGUAGES are returned. If NULL, LANGUAGES are removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
If LANGUAGE is defined it should be one of the values in LANGUAGES.
If LANGUAGE is set, it is considered the main language. If LANGUAGE is not set, the first language in LANGUAGES is considered the main language.
A px object
# Set LANGUAGES to 'en' and 'kl', with 'en' as main language x1 <- population_gl |> px() |> px_languages(c('en', 'kl')) # Print LANGUAGES px_languages(x1) # Remove LANGUAGES x2 <- px_languages(x1, NULL) px_languages(x2)
# Set LANGUAGES to 'en' and 'kl', with 'en' as main language x1 <- population_gl |> px() |> px_languages(c('en', 'kl')) # Print LANGUAGES px_languages(x1) # Remove LANGUAGES x2 <- px_languages(x1, NULL) px_languages(x2)
Inspect or change LAST-UPDATED.
px_last_updated(x, value, validate) ## S3 method for class 'px' px_last_updated(x, value, validate = TRUE)
px_last_updated(x, value, validate) ## S3 method for class 'px' px_last_updated(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string to set the value for all languages or a data frame with columns 'language' and 'value' to set it for specific languages. If 'value' is missing, the current LAST-UPDATED is returned. If NULL, LAST-UPDATED is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set LAST-UPDATED for all languages x1 <- px(population_gl) |> px_last_updated('17070501 15:55') # Print LAST-UPDATED px_last_updated(x1) # Set LAST-UPDATED for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_last_updated(tribble(~language, ~value, 'en', '17070501 15:55', 'kl', '20080621 15:55')) px_last_updated(x2) # Remove LAST-UPDATED x3 <- px_last_updated(x2, NULL) px_last_updated(x3)
# Set LAST-UPDATED for all languages x1 <- px(population_gl) |> px_last_updated('17070501 15:55') # Print LAST-UPDATED px_last_updated(x1) # Set LAST-UPDATED for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_last_updated(tribble(~language, ~value, 'en', '17070501 15:55', 'kl', '20080621 15:55')) px_last_updated(x2) # Remove LAST-UPDATED x3 <- px_last_updated(x2, NULL) px_last_updated(x3)
Inspect or change LINK.
px_link(x, value, validate) ## S3 method for class 'px' px_link(x, value, validate = TRUE)
px_link(x, value, validate) ## S3 method for class 'px' px_link(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string to set the value for all languages or a data frame with columns 'language' and 'value' to set it for specific languages. If 'value' is missing, the current LINK is returned. If NULL, LINK is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set LINK for all languages x1 <- px(population_gl) |> px_link('https://stat.gl/?lang=en') # Print LINK px_link(x1) # Set LINK for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_link(tribble(~language, ~value, 'en', 'https://stat.gl/?lang=en', 'kl', 'https://stat.gl/')) px_link(x2) # Remove LINK x3 <- px_link(x2, NULL) px_link(x3)
# Set LINK for all languages x1 <- px(population_gl) |> px_link('https://stat.gl/?lang=en') # Print LINK px_link(x1) # Set LINK for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_link(tribble(~language, ~value, 'en', 'https://stat.gl/?lang=en', 'kl', 'https://stat.gl/')) px_link(x2) # Remove LINK x3 <- px_link(x2, NULL) px_link(x3)
Inspect or change MAP.
px_map(x, value, validate) ## S3 method for class 'px' px_map(x, value, validate = TRUE)
px_map(x, value, validate) ## S3 method for class 'px' px_map(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string or data frame.
|
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set MAP for all languages x1 <- px(population_gl) |> px_map('greenland') # Print MAP px_map(x1) # Set MAP for individual variables library(tibble) x2 <- x1 |> px_map(tribble(~`variable-code`, ~map, 'gender', 'cities', 'age', 'municipalities')) px_map(x2) # Set MAP for individual languages x3 <- x2 %>% px_languages(c('en', 'kl')) |> px_map(tribble(~`variable-code`, ~language, ~map, 'gender', 'en', 'cities_en', 'gender', 'kl', 'cities_kl', 'age', 'en', 'municipalities_en')) px_map(x3) # Remove MAP x4 <- px_map(x3, NULL) px_map(x4)
# Set MAP for all languages x1 <- px(population_gl) |> px_map('greenland') # Print MAP px_map(x1) # Set MAP for individual variables library(tibble) x2 <- x1 |> px_map(tribble(~`variable-code`, ~map, 'gender', 'cities', 'age', 'municipalities')) px_map(x2) # Set MAP for individual languages x3 <- x2 %>% px_languages(c('en', 'kl')) |> px_map(tribble(~`variable-code`, ~language, ~map, 'gender', 'en', 'cities_en', 'gender', 'kl', 'cities_kl', 'age', 'en', 'municipalities_en')) px_map(x3) # Remove MAP x4 <- px_map(x3, NULL) px_map(x4)
Inspect or change MATRIX.
px_matrix(x, value, validate) ## S3 method for class 'px' px_matrix(x, value, validate = TRUE)
px_matrix(x, value, validate) ## S3 method for class 'px' px_matrix(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current MATRIX is returned. If NULL, an error is thrown because MATRIX cannot be removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set MATRIX x1 <- px(population_gl) |> px_matrix('POPULATION') # Print MATRIX px_matrix(x1)
# Set MATRIX x1 <- px(population_gl) |> px_matrix('POPULATION') # Print MATRIX px_matrix(x1)
Split one px object into many small PX-files (micro files), with count of the variables in it.
px_micro(x, out_dir = NULL, keyword_values = NULL)
px_micro(x, out_dir = NULL, keyword_values = NULL)
x |
A px object. |
out_dir |
Directory to save PX-files in. |
keyword_values |
Optional. A data frame with column 'variable' and one or more of: 'px_contents', 'px_title', 'px_description', and 'px_matrix'. The columns will be added as keywords to the table for each non-HEADING variable that match the 'variable' column. It probably work for other keywords as well. Use the column 'filename' to control the filename of each micro file. The filename path is relative to 'out_dir'. Use the column 'language' if the PX-file has multiple languages. |
The HEADING variables are use in all the micro files, and a file is created
for each non-HEADING variable. The new PX-files are saved in a directory
specified by out_dir
.
The main loop uses the furrr package for parallelisation. Use future::plan() to choose how to parallelise.
Nothing
# Create px object with cohort as HEADING x <- greenlanders |> px() |> px_stub(names(greenlanders)) |> px_heading("cohort") # Create micro files, one for each of the non-HEADING variables (gender, age, # municipality) px_micro(x)
# Create px object with cohort as HEADING x <- greenlanders |> px() |> px_stub(names(greenlanders)) |> px_heading("cohort") # Create micro files, one for each of the non-HEADING variables (gender, age, # municipality) px_micro(x)
Inspect or change NEXT-UPDATE.
px_next_update(x, value, validate) ## S3 method for class 'px' px_next_update(x, value, validate = TRUE)
px_next_update(x, value, validate) ## S3 method for class 'px' px_next_update(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current NEXT-UPDATE is returned. If NULL, NEXT-UPDATE is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set NEXT-UPDATE x1 <- px(population_gl) |> px_next_update('20240621 15:55') # Print NEXT-UPDATE px_next_update(x1) # Remove NEXT-UPDATE x2 <- px_next_update(x1, NULL) px_next_update(x2)
# Set NEXT-UPDATE x1 <- px(population_gl) |> px_next_update('20240621 15:55') # Print NEXT-UPDATE px_next_update(x1) # Remove NEXT-UPDATE x2 <- px_next_update(x1, NULL) px_next_update(x2)
Inspect or change NOTE.
px_note(x, value, validate) ## S3 method for class 'px' px_note(x, value, validate = TRUE)
px_note(x, value, validate) ## S3 method for class 'px' px_note(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string, a data frame, or a list.
|
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
NOTE has a lot of possible ways to specify value
, because
it can be set both for the entire PX-file and for individual variables.
A px object, a character string, a data frame, or a list of character strings and/or data frames.
Statistics Sweden's documentation
library(tibble) # Set NOTE for entire PX-file x1 <- px(population_gl) |> px_note('Note about PX-file') # Print NOTE px_note(x1) # Set NOTE for entire PX-file in multiple languages x2 <- x1 |> px_languages(c('en', 'kl')) |> px_note(tribble(~language, ~value, 'en', 'English note', 'kl', 'Kalaallisut note' ) ) px_note(x2) # Set NOTE for variables x3 <- x1 |> px_note(tribble(~`variable-code`, ~note, 'year', 'Some data collected in following year', 'age', 'Is rounded down' ) ) px_note(x3) # Remove all NOTEs x4 <- px_note(x3, NULL)
library(tibble) # Set NOTE for entire PX-file x1 <- px(population_gl) |> px_note('Note about PX-file') # Print NOTE px_note(x1) # Set NOTE for entire PX-file in multiple languages x2 <- x1 |> px_languages(c('en', 'kl')) |> px_note(tribble(~language, ~value, 'en', 'English note', 'kl', 'Kalaallisut note' ) ) px_note(x2) # Set NOTE for variables x3 <- x1 |> px_note(tribble(~`variable-code`, ~note, 'year', 'Some data collected in following year', 'age', 'Is rounded down' ) ) px_note(x3) # Remove all NOTEs x4 <- px_note(x3, NULL)
Inspect or change NOTEX.
px_notex(x, value, validate) ## S3 method for class 'px' px_notex(x, value, validate = TRUE)
px_notex(x, value, validate) ## S3 method for class 'px' px_notex(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string, a data frame, or a list.
|
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
NOTEX has a lot of possible ways to specify value
, because
it can be set both for the entire PX-file and for individual variables.
A px object, a character string, a data frame, or a list of character strings and/or data frames.
Statistics Sweden's documentation
library(tibble) # Set NOTEX for entire PX-file x1 <- px(population_gl) |> px_notex('Note about PX-file') # Print NOTEX px_notex(x1) # Set NOTEX for entire PX-file in multiple languages x2 <- x1 |> px_languages(c('en', 'kl')) |> px_notex(tribble(~language, ~value, 'en', 'English notex', 'kl', 'Kalaallisut notex' ) ) px_notex(x2) # Set NOTEX for variables x3 <- x1 |> px_notex(tribble(~`variable-code`, ~notex, 'year', 'Some data collected in following year', 'age', 'Is rounded down' ) ) px_notex(x3) # Remove all NOTEXs x4 <- px_notex(x3, NULL)
library(tibble) # Set NOTEX for entire PX-file x1 <- px(population_gl) |> px_notex('Note about PX-file') # Print NOTEX px_notex(x1) # Set NOTEX for entire PX-file in multiple languages x2 <- x1 |> px_languages(c('en', 'kl')) |> px_notex(tribble(~language, ~value, 'en', 'English notex', 'kl', 'Kalaallisut notex' ) ) px_notex(x2) # Set NOTEX for variables x3 <- x1 |> px_notex(tribble(~`variable-code`, ~notex, 'year', 'Some data collected in following year', 'age', 'Is rounded down' ) ) px_notex(x3) # Remove all NOTEXs x4 <- px_notex(x3, NULL)
Inspect or change ORDER.
px_order(x, value, validate) ## S3 method for class 'px' px_order(x, value, validate = TRUE)
px_order(x, value, validate) ## S3 method for class 'px' px_order(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A data frame with the columns 'order' and one or more of the columns: 'variable-code', and 'code'. If 'value' is missing, the current ORDER is returned. If NULL, ORDER is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or data frame.
# Set ORDER for a variable library(tibble) x1 <- population_gl |> px() |> px_order(tribble(~`variable-code`, ~order, 'gender', 8)) # Print ORDER px_order(x1) # Set ORDER for a value x2 <- x1 |> px_order(tribble(~`variable-code`, ~code, ~order, 'age', '2004', 9)) px_order(x2) # Remove ORDER x3 <- px_order(x2, NULL) px_order(x3)
# Set ORDER for a variable library(tibble) x1 <- population_gl |> px() |> px_order(tribble(~`variable-code`, ~order, 'gender', 8)) # Print ORDER px_order(x1) # Set ORDER for a value x2 <- x1 |> px_order(tribble(~`variable-code`, ~code, ~order, 'age', '2004', 9)) px_order(x2) # Remove ORDER x3 <- px_order(x2, NULL) px_order(x3)
Inspect or change PRECISION.
px_precision(x, value, validate) ## S3 method for class 'px' px_precision(x, value, validate = TRUE)
px_precision(x, value, validate) ## S3 method for class 'px' px_precision(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A data frame with the columns 'precision' and one or more of the columns: 'variable-code', and 'code'. If 'value' is missing, the current PRECISION is returned. If NULL, PRECISION is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or data frame.
Statistics Sweden's documentation
# Set PRECISION for a variable library(tibble) x1 <- population_gl |> px() |> px_precision(tribble(~`variable-code`, ~precision, 'gender', 2)) # Print PRECISION px_precision(x1) # Set PRECISION for a value x2 <- x1 |> px_precision(tribble(~`variable-code`, ~code, ~precision, 'age', '2004', 3)) px_precision(x2) # Remove PRECISION x3 <- px_precision(x2, NULL) px_precision(x3)
# Set PRECISION for a variable library(tibble) x1 <- population_gl |> px() |> px_precision(tribble(~`variable-code`, ~precision, 'gender', 2)) # Print PRECISION px_precision(x1) # Set PRECISION for a value x2 <- x1 |> px_precision(tribble(~`variable-code`, ~code, ~precision, 'age', '2004', 3)) px_precision(x2) # Remove PRECISION x3 <- px_precision(x2, NULL) px_precision(x3)
Save px object to file
px_save(x, path, save_data = TRUE, data_path = NULL)
px_save(x, path, save_data = TRUE, data_path = NULL)
x |
A px object. |
path |
Path to file. The file extension determines the format. Can be:
|
save_data |
If FALSE, no 'Data' sheet is created in the Excel workbook.
Can only be used if |
data_path |
Path to an |
Use px_codepage()
to change file encoding.
Nothing
# Save px object to PX-file tmp_dir <- tempdir() x <- px(population_gl) px_save(x, file.path(tmp_dir, "population.px")) # Save px object to Excel workbook px_save(x, file.path(tmp_dir, "population.xlsx")) # Save px object as R-script that creates the px object px_save(x, file.path(tmp_dir, "population.R"))
# Save px object to PX-file tmp_dir <- tempdir() x <- px(population_gl) px_save(x, file.path(tmp_dir, "population.px")) # Save px object to Excel workbook px_save(x, file.path(tmp_dir, "population.xlsx")) # Save px object as R-script that creates the px object px_save(x, file.path(tmp_dir, "population.R"))
Save a classification object as .vs and .agg files. The .vs file contains the value set and the .agg files contain the aggregations.
px_save_classification(c, path)
px_save_classification(c, path)
c |
A classification object |
path |
Directory to save the files in |
Nothing.
# Save classification as .vs as .agg files c <- px_classification(name = "Age5", prestext = "Ages 0-9 - 60+", domain = "age", df = age_classification ) px_save_classification(c, path = tempdir())
# Save classification as .vs as .agg files c <- px_classification(name = "Age5", prestext = "Ages 0-9 - 60+", domain = "age", df = age_classification ) px_save_classification(c, path = tempdir())
Inspect or change SHOWDECIMALS.
px_showdecimals(x, value, validate) ## S3 method for class 'px' px_showdecimals(x, value, validate = TRUE)
px_showdecimals(x, value, validate) ## S3 method for class 'px' px_showdecimals(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current SHOWDECIMALS is returned. If NULL, SHOWDECIMALS is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set SHOWDECIMALS x1 <- px(population_gl) |> px_showdecimals('2') # Print SHOWDECIMALS px_showdecimals(x1) # Remove SHOWDECIMALS x2 <- px_showdecimals(x1, NULL) px_showdecimals(x2)
# Set SHOWDECIMALS x1 <- px(population_gl) |> px_showdecimals('2') # Print SHOWDECIMALS px_showdecimals(x1) # Remove SHOWDECIMALS x2 <- px_showdecimals(x1, NULL) px_showdecimals(x2)
Inspect or change SOURCE.
px_source(x, value, validate) ## S3 method for class 'px' px_source(x, value, validate = TRUE)
px_source(x, value, validate) ## S3 method for class 'px' px_source(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string to set the value for all languages or a data frame with columns 'language' and 'value' to set it for specific languages. If 'value' is missing, the current SOURCE is returned. If NULL, SOURCE is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set SOURCE for all languages x1 <- px(population_gl) |> px_source('Statistics Greenland') # Print SOURCE px_source(x1) # Set SOURCE for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_source(tribble(~language, ~value, 'en', 'Statistics Greenland', 'kl', 'Naatsorsueqqissaartarfik')) px_source(x2) # Remove SOURCE x3 <- px_source(x2, NULL) px_source(x3)
# Set SOURCE for all languages x1 <- px(population_gl) |> px_source('Statistics Greenland') # Print SOURCE px_source(x1) # Set SOURCE for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_source(tribble(~language, ~value, 'en', 'Statistics Greenland', 'kl', 'Naatsorsueqqissaartarfik')) px_source(x2) # Remove SOURCE x3 <- px_source(x2, NULL) px_source(x3)
Inspect or change STOCKFA.
px_stockfa(x, value, validate) ## S3 method for class 'px' px_stockfa(x, value, validate = TRUE)
px_stockfa(x, value, validate) ## S3 method for class 'px' px_stockfa(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string to set the value for all languages or a data frame with columns 'language' and 'value' to set it for specific languages. If 'value' is missing, the current STOCKFA is returned. If NULL, STOCKFA is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set STOCKFA for all languages x1 <- px(population_gl) |> px_stockfa('S') # Print STOCKFA px_stockfa(x1) # Set STOCKFA for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_stockfa(tribble(~language, ~value, 'en', 'S', 'kl', 'F')) px_stockfa(x2) # Remove STOCKFA x3 <- px_stockfa(x2, NULL) px_stockfa(x3)
# Set STOCKFA for all languages x1 <- px(population_gl) |> px_stockfa('S') # Print STOCKFA px_stockfa(x1) # Set STOCKFA for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_stockfa(tribble(~language, ~value, 'en', 'S', 'kl', 'F')) px_stockfa(x2) # Remove STOCKFA x3 <- px_stockfa(x2, NULL) px_stockfa(x3)
Inspect or change STUB.
px_stub(x, value, validate) ## S3 method for class 'px' px_stub(x, value, validate = TRUE)
px_stub(x, value, validate) ## S3 method for class 'px' px_stub(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character vector of variable names to change to
STUB. This also changes the STUB order. With names in |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character vector.
Statistics Sweden's documentation
x1 <- px(population_gl) # Print STUB px_stub(x1) # Add 'year' to STUB x2 <- px_stub(x1, 'year') px_stub(x2) # Change order of STUB x3 <- px_stub(x2, c('age', 'gender')) px_stub(x3)
x1 <- px(population_gl) # Print STUB px_stub(x1) # Add 'year' to STUB x2 <- px_stub(x1, 'year') px_stub(x2) # Change order of STUB x3 <- px_stub(x2, c('age', 'gender')) px_stub(x3)
Inspect or change SUBJECT-AREA.
px_subject_area(x, value, validate) ## S3 method for class 'px' px_subject_area(x, value, validate = TRUE)
px_subject_area(x, value, validate) ## S3 method for class 'px' px_subject_area(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string to set the value for all languages or a data frame with columns 'language' and 'value' to set it for specific languages. If 'value' is missing, the current SUBJECT-AREA is returned. If NULL, an error is thrown because SUBJECT-AREA cannot be removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set SUBJECT-AREA for all languages x1 <- px(population_gl) |> px_subject_area('Population') # Print SUBJECT-AREA px_subject_area(x1) # Set SUBJECT-AREA for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_subject_area(tribble(~language, ~value, 'en', 'Population', 'kl', 'Innuttaasut')) px_subject_area(x2)
# Set SUBJECT-AREA for all languages x1 <- px(population_gl) |> px_subject_area('Population') # Print SUBJECT-AREA px_subject_area(x1) # Set SUBJECT-AREA for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_subject_area(tribble(~language, ~value, 'en', 'Population', 'kl', 'Innuttaasut')) px_subject_area(x2)
Inspect or change SUBJECT-CODE.
px_subject_code(x, value, validate) ## S3 method for class 'px' px_subject_code(x, value, validate = TRUE)
px_subject_code(x, value, validate) ## S3 method for class 'px' px_subject_code(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current SUBJECT-CODE is returned. If NULL, an error is thrown because SUBJECT-CODE cannot be removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set SUBJECT-CODE x1 <- px(population_gl) |> px_subject_code('POP') # Print SUBJECT-CODE px_subject_code(x1)
# Set SUBJECT-CODE x1 <- px(population_gl) |> px_subject_code('POP') # Print SUBJECT-CODE px_subject_code(x1)
Inspect or change TABLEID.
px_tableid(x, value, validate) ## S3 method for class 'px' px_tableid(x, value, validate = TRUE)
px_tableid(x, value, validate) ## S3 method for class 'px' px_tableid(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current TABLEID is returned. If NULL, TABLEID is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set TABLEID x1 <- px(population_gl) |> px_tableid('POPGL') # Print TABLEID px_tableid(x1) # Remove TABLEID x2 <- px_tableid(x1, NULL) px_tableid(x2)
# Set TABLEID x1 <- px(population_gl) |> px_tableid('POPGL') # Print TABLEID px_tableid(x1) # Remove TABLEID x2 <- px_tableid(x1, NULL) px_tableid(x2)
Inspect or change TIMEVAL.
There can only be one time variable.
px_timeval(x, value, validate) ## S3 method for class 'px' px_timeval(x, value, validate = TRUE)
px_timeval(x, value, validate) ## S3 method for class 'px' px_timeval(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current TIMEVAL is returned. If NULL, TIMEVAL is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set TIMEVAL x1 <- px(population_gl) |> px_timeval('year') # Print TIMEVAL px_timeval(x1) # Remove TIMEVAL x2 <- px_timeval(x1, NULL) px_timeval(x2)
# Set TIMEVAL x1 <- px(population_gl) |> px_timeval('year') # Print TIMEVAL px_timeval(x1) # Remove TIMEVAL x2 <- px_timeval(x1, NULL) px_timeval(x2)
Inspect or change TITLE.
TITLE can only be removed if DESCRIPTION is set.
px_title(x, value, validate) ## S3 method for class 'px' px_title(x, value, validate = TRUE)
px_title(x, value, validate) ## S3 method for class 'px' px_title(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string to set the value for all languages or a data frame with columns 'language' and 'value' to set it for specific languages. If 'value' is missing, the current TITLE is returned. If NULL, TITLE is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set TITLE for all languages x1 <- px(population_gl) |> px_title('Population GR') # Print TITLE px_title(x1) # Set TITLE for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_title(tribble(~language, ~value, 'en', 'Population GR', 'kl', 'Innuttaasut KL')) px_title(x2)
# Set TITLE for all languages x1 <- px(population_gl) |> px_title('Population GR') # Print TITLE px_title(x1) # Set TITLE for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_title(tribble(~language, ~value, 'en', 'Population GR', 'kl', 'Innuttaasut KL')) px_title(x2)
Inspect or change UNITS.
px_units(x, value, validate) ## S3 method for class 'px' px_units(x, value, validate = TRUE)
px_units(x, value, validate) ## S3 method for class 'px' px_units(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string to set the value for all languages or a data frame with columns 'language' and 'value' to set it for specific languages. If 'value' is missing, the current UNITS is returned. If NULL, an error is thrown because UNITS cannot be removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
Statistics Sweden's documentation
# Set UNITS for all languages x1 <- px(population_gl) |> px_units('persons') # Print UNITS px_units(x1) # Set UNITS for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_units(tribble(~language, ~value, 'en', 'persons', 'kl', 'inuit amerlassusaat')) px_units(x2)
# Set UNITS for all languages x1 <- px(population_gl) |> px_units('persons') # Print UNITS px_units(x1) # Set UNITS for individual languages library(tibble) x2 <- x1 |> px_languages(c('en', 'kl')) |> px_units(tribble(~language, ~value, 'en', 'persons', 'kl', 'inuit amerlassusaat')) px_units(x2)
Inspect or change UPDATE-FREQUENCY.
px_update_frequency(x, value, validate) ## S3 method for class 'px' px_update_frequency(x, value, validate = TRUE)
px_update_frequency(x, value, validate) ## S3 method for class 'px' px_update_frequency(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string. If missing, the current UPDATE-FREQUENCY is returned. If NULL, UPDATE-FREQUENCY is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or a character string.
Statistics Sweden's documentation
# Set UPDATE-FREQUENCY x1 <- px(population_gl) |> px_update_frequency('Yearly') # Print UPDATE-FREQUENCY px_update_frequency(x1) # Remove UPDATE-FREQUENCY x2 <- px_update_frequency(x1, NULL) px_update_frequency(x2)
# Set UPDATE-FREQUENCY x1 <- px(population_gl) |> px_update_frequency('Yearly') # Print UPDATE-FREQUENCY px_update_frequency(x1) # Remove UPDATE-FREQUENCY x2 <- px_update_frequency(x1, NULL) px_update_frequency(x2)
Runs a number of checks on px object to see if it is valid.
px_validate(x)
px_validate(x)
x |
A supposed px object. |
This check is run by default by all px_*
functions, but can be skipped by
using validate = FALSE
. This can be useful on large px objects where the
checks are time consuming. Instead of validating on every modifying function
px_validate()
can be run as the final step to validate the object.
A valid px object.
# Turn off validation for modifying functions, and manually # run validation as final step in creating px object. x1 <- px(population_gl, validate = FALSE) |> px_title("Test", validate = FALSE) |> px_validate()
# Turn off validation for modifying functions, and manually # run validation as final step in creating px object. x1 <- px(population_gl, validate = FALSE) |> px_title("Test", validate = FALSE) |> px_validate()
Inspect or change VALUENOTE.
px_valuenote(x, value, validate) ## S3 method for class 'px' px_valuenote(x, value, validate = TRUE)
px_valuenote(x, value, validate) ## S3 method for class 'px' px_valuenote(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A data frame with the columns 'valuenote' and one or more of the columns: 'variable-code', 'code', and 'language'. If 'value' is missing, the current VALUENOTE is returned. If NULL, VALUENOTE is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or data frame.
Statistics Sweden's documentation
# Set VALUENOTE for a value library(tibble) x1 <- population_gl |> px() |> px_valuenote( tribble(~`variable-code`, ~code, ~valuenote, 'year', '2004', 'Counts are approximated')) # Print VALUENOTE px_valuenote(x1) # Set VALUENOTE for a value in specific language x2 <- x1 |> px_languages(c('en', 'kl')) |> px_valuenote( tribble(~`variable-code`, ~code, ~language, ~valuenote, 'age', '0-6', 'en', 'Some of the figures are from 2003', 'age', '0-6', 'kl', 'Kisitsisit ilaat 2003-imeersuupput')) px_valuenote(x2) # Remove VALUENOTE x3 <- px_valuenote(x2, NULL) px_valuenote(x3)
# Set VALUENOTE for a value library(tibble) x1 <- population_gl |> px() |> px_valuenote( tribble(~`variable-code`, ~code, ~valuenote, 'year', '2004', 'Counts are approximated')) # Print VALUENOTE px_valuenote(x1) # Set VALUENOTE for a value in specific language x2 <- x1 |> px_languages(c('en', 'kl')) |> px_valuenote( tribble(~`variable-code`, ~code, ~language, ~valuenote, 'age', '0-6', 'en', 'Some of the figures are from 2003', 'age', '0-6', 'kl', 'Kisitsisit ilaat 2003-imeersuupput')) px_valuenote(x2) # Remove VALUENOTE x3 <- px_valuenote(x2, NULL) px_valuenote(x3)
Inspect or change VALUENOTEX.
px_valuenotex(x, value, validate) ## S3 method for class 'px' px_valuenotex(x, value, validate = TRUE)
px_valuenotex(x, value, validate) ## S3 method for class 'px' px_valuenotex(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A data frame with the columns 'valuenotex' and one or more of the columns: 'variable-code', 'code', and 'language'. If 'value' is missing, the current VALUENOTEX is returned. If NULL, VALUENOTEX is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or data frame.
Statistics Sweden's documentation
# Set VALUENOTEX for a value library(tibble) x1 <- population_gl |> px() |> px_valuenotex( tribble(~`variable-code`, ~code, ~valuenotex, 'year', '2004', 'Counts are approximated')) # Print VALUENOTEX px_valuenotex(x1) # Set VALUENOTEX for a value in specific language x2 <- x1 |> px_languages(c('en', 'kl')) |> px_valuenotex( tribble(~`variable-code`, ~code, ~language, ~valuenotex, 'age', '0-6', 'en', 'Some of the figures are from 2003', 'age', '0-6', 'kl', 'Kisitsisit ilaat 2003-imeersuupput')) px_valuenotex(x2) # Remove VALUENOTEX x3 <- px_valuenotex(x2, NULL) px_valuenotex(x3)
# Set VALUENOTEX for a value library(tibble) x1 <- population_gl |> px() |> px_valuenotex( tribble(~`variable-code`, ~code, ~valuenotex, 'year', '2004', 'Counts are approximated')) # Print VALUENOTEX px_valuenotex(x1) # Set VALUENOTEX for a value in specific language x2 <- x1 |> px_languages(c('en', 'kl')) |> px_valuenotex( tribble(~`variable-code`, ~code, ~language, ~valuenotex, 'age', '0-6', 'en', 'Some of the figures are from 2003', 'age', '0-6', 'kl', 'Kisitsisit ilaat 2003-imeersuupput')) px_valuenotex(x2) # Remove VALUENOTEX x3 <- px_valuenotex(x2, NULL) px_valuenotex(x3)
Inspect or change VALUES.
px_values(x, value, validate) ## S3 method for class 'px' px_values(x, value, validate = TRUE)
px_values(x, value, validate) ## S3 method for class 'px' px_values(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A data frame with the columns 'values' and one or more of the columns: 'variable-code', 'code', and 'language'. If 'value' is missing, the current VALUES is returned. If NULL, VALUES is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or data frame.
Statistics Sweden's documentation
# Set VALUES for a value library(tibble) x1 <- population_gl |> px() |> px_values( tribble(~`variable-code`, ~code, ~values, 'year', '2004', 'Year 2024')) # Print VALUES px_values(x1) # Set VALUES for a value in specific language x2 <- x1 |> px_languages(c('en', 'kl')) |> px_values( tribble(~`variable-code`, ~code, ~language, ~values, 'age', '0-6', 'en', 'toddler', 'age', '0-6', 'kl', 'meeraaqqap')) px_values(x2) # Remove VALUES x3 <- px_values(x2, NULL) px_values(x3)
# Set VALUES for a value library(tibble) x1 <- population_gl |> px() |> px_values( tribble(~`variable-code`, ~code, ~values, 'year', '2004', 'Year 2024')) # Print VALUES px_values(x1) # Set VALUES for a value in specific language x2 <- x1 |> px_languages(c('en', 'kl')) |> px_values( tribble(~`variable-code`, ~code, ~language, ~values, 'age', '0-6', 'en', 'toddler', 'age', '0-6', 'kl', 'meeraaqqap')) px_values(x2) # Remove VALUES x3 <- px_values(x2, NULL) px_values(x3)
Inspect or change VARIABLE-LABEL.
The variable label is the name that is shown in the PX-file.
px_variable_label(x, value, validate) ## S3 method for class 'px' px_variable_label(x, value, validate = TRUE)
px_variable_label(x, value, validate) ## S3 method for class 'px' px_variable_label(x, value, validate = TRUE)
x |
A px object |
value |
Optional. A character string or data frame.
|
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object, a character string, or a data frame.
# Set VARIABLE-LABEL for individual variables library(tibble) x1 <- px(population_gl) |> px_variable_label(tribble(~`variable-code`, ~`variable-label`, 'gender', 'Gender', 'age', 'Age')) px_variable_label(x1) # Set VARIABLE-LABEL for individual languages x2 <- x1 %>% px_languages(c('en', 'kl')) |> px_variable_label(tribble(~`variable-code`, ~language, ~`variable-label`, 'gender', 'en', 'Gender', 'gender', 'kl', 'Suiaassuseq', 'age', 'en', 'Age', 'age', 'kl', 'Ukiut')) px_variable_label(x2) # Remove VARIABLE-LABEL x3 <- px_variable_label(x2, NULL) px_variable_label(x3)
# Set VARIABLE-LABEL for individual variables library(tibble) x1 <- px(population_gl) |> px_variable_label(tribble(~`variable-code`, ~`variable-label`, 'gender', 'Gender', 'age', 'Age')) px_variable_label(x1) # Set VARIABLE-LABEL for individual languages x2 <- x1 %>% px_languages(c('en', 'kl')) |> px_variable_label(tribble(~`variable-code`, ~language, ~`variable-label`, 'gender', 'en', 'Gender', 'gender', 'kl', 'Suiaassuseq', 'age', 'en', 'Age', 'age', 'kl', 'Ukiut')) px_variable_label(x2) # Remove VARIABLE-LABEL x3 <- px_variable_label(x2, NULL) px_variable_label(x3)
Inspect or change VARIABLE-TYPE.
px_variable_type(x, value, validate) ## S3 method for class 'px' px_variable_type(x, value, validate = TRUE)
px_variable_type(x, value, validate) ## S3 method for class 'px' px_variable_type(x, value, validate = TRUE)
x |
A px object |
value |
A data frame with columns 'variable-code' and 'variable-type'. If value is missing, the current VARIABLE-TYPE is returned. If NULL, all VARIABLE-TYPE is removed. |
validate |
Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use |
A px object or data frame.
Statistics Sweden's documentation
library(tibble) # Set VARIABLE-TYPE x1 <- px(population_gl) |> px_variable_type(tibble('variable-code' = 'year', 'variable-type' = 'time')) # Print VARIABLE-TYPE px_variable_type(x1) # Remove VARIABLE-TYPE x2 <- px_variable_type(x1, NULL) px_variable_type(x2)
library(tibble) # Set VARIABLE-TYPE x1 <- px(population_gl) |> px_variable_type(tibble('variable-code' = 'year', 'variable-type' = 'time')) # Print VARIABLE-TYPE px_variable_type(x1) # Remove VARIABLE-TYPE x2 <- px_variable_type(x1, NULL) px_variable_type(x2)