Title: | Make PX-Files in R |
Version: | 0.18.0 |
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. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
Imports: | arrow, dplyr, furrr, magrittr, methods, openxlsx, purrr, readxl, rlang, stats, stringi, stringr, tibble, tidyr, tools, utils, vctrs |
Suggests: | knitr, rmarkdown, withr, testthat (≥ 3.0.0), curl |
Config/testthat/edition: | 3 |
Config/testthat/parallel: | true |
Config/testthat/start-first: | 60-metamake-bexltall |
VignetteBuilder: | knitr |
Depends: | R (≥ 4.1.0) |
LazyData: | true |
URL: | https://github.com/StatisticsGreenland/pxmake, https://statisticsgreenland.github.io/pxmake/ |
BugReports: | https://github.com/StatisticsGreenland/pxmake/issues |
NeedsCompilation: | no |
Packaged: | 2025-05-30 13:56:09 UTC; johan |
Author: | Johan Ejstrud [cre, aut], Lars Pedersen [aut], Statistics Greenland [cph] (https://stat.gl/) |
Maintainer: | Johan Ejstrud <johan@ejstrud.com> |
Repository: | CRAN |
Date/Publication: | 2025-05-30 14:20:02 UTC |
pxmake: 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.
Author(s)
Maintainer: Johan Ejstrud johan@ejstrud.com
Authors:
Lars Pedersen larp@stat.gl
Other contributors:
Statistics Greenland (https://stat.gl/) [copyright holder]
See Also
Useful links:
Report bugs at https://github.com/StatisticsGreenland/pxmake/issues
Add cell name to keywords that support it (see px-specification)
Description
Add cell name to keywords that support it (see px-specification)
Usage
add_cell_to_keyword(keyword, name)
Arguments
keyword |
String, name of keyword |
name |
String, cell name to add to keyword |
Value
String
Add a data frame as a sheet to an Excel workbook
Description
Add a data frame as a sheet to an Excel workbook
Usage
add_excel_sheet(wb, df, sheet_name)
Arguments
wb |
An Excel workbook |
df |
A data frame |
sheet_name |
Name of the sheet |
Value
Nothing
Add language, other than the main langue, to keyword
Description
Add language, other than the main langue, to keyword
Usage
add_language_to_keyword(keyword, main_language, language)
Arguments
keyword |
String, name of keyword |
main_language |
Main language of PX-file |
language |
Lange to add to keyword |
Value
String
Add boolean main_language column
Description
Add boolean main_language column
Usage
add_main_language(metadata_df)
Arguments
metadata_df |
Data frame with metadata. |
Value
A data frame
Add a sub key word (see px-specification for details on sub keys)
Description
Add a sub key word (see px-specification for details on sub keys)
Usage
add_sub_key_to_keyword(keyword, name)
Arguments
keyword |
String, name of keyword |
name |
String, name of sub key |
Value
String
Add total level to variable
Description
Add a new level to a variables which is the sum of all other levels.
Usage
add_total_level_to_var(
df,
variable,
level_name = "Total",
sum_var = "value",
na.rm = TRUE
)
Arguments
df |
Data frame to add total levels to. |
variable |
Name of variable to add total level to. |
level_name |
Total level name. |
sum_var |
String, name of variable to sum over. |
na.rm |
Optional. Logical. If TRUE, NAs are removed before summing. |
Value
A data frame
Add total levels to multiple variables
Description
Wrapper around add_total_level_to_var to add levels to total level to multiple variables.
Usage
add_totals_to_df(df, variables, level_names, sum_var = "value", na.rm = TRUE)
Arguments
df |
Data frame to add total levels to. |
variables |
List of variables to add total levels to. |
level_names |
Names of total levels. Should have length 1 or same length
as |
sum_var |
String, name of variable to sum over. |
na.rm |
Optional. Logical. If TRUE, NAs are removed before summing. |
Age classification
Description
Example data set to create age classification with aggreations form 10 and 25 years classes.
Usage
age_classification
Format
A data frame:
- valuecode
Value code
- valuetext
Value text
- 10-years_classes
Aggregtation into 10 years classes
- 25-years_classes
Aggregtation into 25 years classes
Get data set from aggregation file
Description
Get data set from aggregation file
Usage
aggregation_df(path)
Arguments
path |
to an aggregation file |
Value
A data frame with columns 'valuecode' (character) and a second column (ordered) named after the aggregation
Align data frames
Description
Align df_a to have the same columns and column types as df_b.
Usage
align_data_frames(df_a, df_b)
Arguments
df_a |
Data frame to align |
df_b |
Data frame to align to |
Value
A data frame
Split long strings at commas
Description
Long strings are split so they are no longer than 256 characters and end at a comma.
Usage
break_long_lines(str, max_line_length = 256)
Arguments
str |
String |
max_line_length |
Integer longest allowed line length |
Value
A character vector
Change pivot variables
Description
Change pivot variables
Usage
change_pivot_variables(x, value, pivot)
Arguments
x |
A px object |
value |
A character vector of variable codes to change to the pivot type |
pivot |
Pivot type (STUB, HEADING, FIGURES) |
Value
A px object
Regexp that matches a classification file section heading
Description
Regexp that matches a classification file section heading
Usage
classification_file_section_heading_regexp()
Create code to construct data frame
Description
Convert data frame to the code nessasary to construct it as a tibble.
Usage
convert_df_to_code(df)
Arguments
df |
A data frame |
Value
A character vector
Create constructing code
Description
Creates code that construct input value.
Usage
convert_value_to_code(value)
Arguments
value |
Vector of values to create constructors for |
Value
A character vector
Create a tibble with dummy values
Description
Create a tibble with dummy values
Usage
create_dummy_tibbles(dummy_value)
Arguments
dummy_value |
Value to set in all columns |
Get languages used in px object
Description
Get languages used in px object
Usage
defined_languages(x)
Arguments
x |
A px object |
Value
A character vector
Drop rows with only NA values
Description
Drop rows with only NA values
Usage
drop_blank_rows(df)
Arguments
df |
Data frame |
Value
A data frame
Add lines numbers
Description
Add '1=', '2=', etc. at start of each line.
Usage
enumerate_lines(lines)
Arguments
lines |
A character vector |
Value
A character vector
Throw error
Description
Throw error
Usage
error(msg)
Arguments
msg |
String, error message |
Value
Nothing
Throw error if argument is not a character string
Description
Throw error if argument is not a character string
Usage
error_if_agument_is_not_character_string(name, value)
Get section in .vs or .agg file
Description
Get section in .vs or .agg file
Usage
extract_section(lines, heading, key = NULL)
Arguments
lines |
A character vector |
heading |
Character, the section heading |
key |
Optional. Character, subkey in section |
Fix some common issues in px objects
Description
Fix some common issues in px objects
Usage
fix_px(x)
Arguments
x |
A px object. |
Value
A px object
Format df for px format
Description
Turn all variables, except figures variable, into character and replace NA with dash.
Usage
format_data_df(data_df, figures_variable)
Arguments
data_df |
A data frame with data. |
figures_variable |
Character. The name of the figures variable. |
Value
A data frame
Get lines for PX-file from px object
Description
Get lines for PX-file from px object
Usage
format_px_object_as_lines(x)
Arguments
x |
A px object |
Value
A character vector
Format time values for PX-file
Description
Format time values for PX-file
Usage
format_time_values(values)
Arguments
values |
Time values |
Value
A character vector
Get data cube used in PX-file format
Description
Get data cube used in PX-file format
Usage
get_data_cube(metadata_df, data_df)
Arguments
metadata_df |
Data frame with metadata. |
data_df |
A data frame with data. |
Value
A data frame
Default encoding to read and save PX-file in
Description
Default encoding to read and save PX-file in
Usage
get_default_encoding()
Value
Character
Get encoding listed in PX-file
Description
Encoding is listed in CODEPAGE.
Usage
get_encoding_from_px_file(px_path)
Arguments
px_path |
Path to a PX-file |
Value
Character
Get specific sheet from Excel workbook
Description
Get specific sheet from Excel workbook
Usage
get_excel_sheet(sheet, add_automatically = FALSE)
Arguments
sheet |
String. Sheet to read. |
add_automatically |
Logical. If TRUE, return an empty data frame if the sheet does not exist. |
Value
A data frame.
Get figures variable from Excel workbook
Description
Get figures variable from Excel workbook
Usage
get_figures_variable_from_excel(excel_path)
Arguments
excel_path |
Path to Excel metadata workbook. |
Value
Character, name of figures variable.
Get the main language from metadata
Description
Get the main language from metadata
Usage
get_main_language(metadata_df)
Arguments
metadata_df |
Data frame with metadata. |
Value
Character
A list of which variables should be in each sheet
Description
A list of which variables should be in each sheet
Usage
get_mandatory_variables()
Get metadata df from px object
Description
Get metadata df from px object
Usage
get_metadata_df_from_px(x)
Arguments
x |
A px object |
Value
A data frame
Get metadata df from px lines
Description
Get metadata df from px lines
Usage
get_metadata_df_from_px_lines(metadata_lines)
Arguments
metadata_lines |
A character vector with the header of a PX-file. |
Value
A data frame
Get names of pivot variables
Description
Get names of pivot variables
Usage
get_pivot_variables(x, pivot)
Arguments
x |
A px object |
pivot |
A string, either "STUB", "HEADING" or "FIGURES" |
Value
A character vector of variable codes
Regular expression to parse header in PX-file
Description
Regular expression to parse header in PX-file
Usage
get_px_metadata_regex()
Value
A character vector
Return lines in section
Description
Return lines in section
Usage
get_section(lines, head_line)
Arguments
lines |
A character vector |
head_line |
A numeric value, line number of section heading |
Get time scale code from values (see TIMEVAL in px-specification)
Description
Get time scale code from values (see TIMEVAL in px-specification)
Usage
get_timeval_type_from_values(values)
Arguments
values |
Values form PX-file |
Value
A character vector
Get time values from formatted string
Description
Get time values from formatted string
Usage
get_values_from_time_format(str)
Arguments
str |
String with time values |
Value
A character vector
Get variable code and label
Description
Get a data frame with variable codes and label in all languages. If VARIABLECODE is used, the relation is defined there, but otherwise the variable code is set to be the main languages' label.
Usage
get_variable_label(metadata_df)
Arguments
metadata_df |
Data frame with metadata. |
Value
A data frame
Greenlanders
Description
A fictive data set with demographic data for Greenlanders split in two cohorts.
Usage
greenlanders
Format
An object of class tbl_df
(inherits from tbl
, data.frame
) with 100 rows and 4 columns.
Guess encoding of file
Description
Guess encoding of file
Usage
guess_file_encoding(path, prefer = list(`UTF-8` = 0.2, `ISO-8859-1` = 0.2))
Arguments
path |
Path to file |
prefer |
Named list of encodings, used to give higher confidence to specific encodings. |
Value
Character
Check if a path has a specific extension (function factory)
Description
Check if a path has a specific extension (function factory)
Usage
is_path_extension(extension)
Arguments
extension |
String, file name extension |
Value
Logic
Get a sorted list of distinct values in list
Description
Get a sorted list of distinct values in list
Usage
lst_distinct_and_arrange(lst)
Arguments
lst |
List to sort |
Value
List
Put two named lists together, remove duplicates and sort
Description
Put two named lists together, remove duplicates and sort
Usage
merge_named_lists(lst1, lst2)
Arguments
lst1 |
List to merge |
lst2 |
List to merge |
Value
List
Change language in px object
Description
Changes languages in 3 of the px tables
Usage
modify_languages_in_px(x, new_languages)
Arguments
x |
A px object |
new_languages |
A character vector |
Value
A px object
Change language in table
Description
Change language in table
Usage
modify_languages_in_table(df, new_languages, keep_vars, align_df)
Arguments
df |
A data frame to change languages in |
new_languages |
A character vector |
keep_vars |
A character vector |
align_df |
A data frame to align with |
Value
A data frame
Add or modify value
Description
Modify a value in a row of a data frame based on its value in another column. If the value is not found, a new row is added.
Usage
modify_or_add_row(
df,
lookup_column,
lookup_column_values,
modify_column,
new_value
)
Arguments
df |
Data frame |
lookup_column |
Column to look up |
lookup_column_values |
Values to look up |
modify_column |
Column to modify |
new_value |
New value to modify/add to modify_column |
Value
A data frame
Change all variables to character
Description
Change all variables to character
Usage
mutate_all_vars_to_character(df)
Arguments
df |
Data frame |
Value
A data frame
Create new classification object
Description
Constructor for internal functions
Usage
new_classification(name, prestext, domain, df)
Arguments
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. If the column type is character the aggregation levels will be sorted alphabetically; use factors to control the ordering. |
Value
A classification object
Create new px object
Description
px constructor for internal functions
Usage
new_px(
languages,
table1,
table2,
variables1,
variables2,
cells1,
cells2,
acrosscells,
data
)
Arguments
languages |
A data frame with language metadata. |
table1 |
A data frame with language independent table metadata. |
table2 |
A data frame with language dependent table metadata. |
variables1 |
A data frame with language independent variable metadata. |
variables2 |
A data frame with language dependent variable metadata. |
cells1 |
A data frame with language independent cells metadata. |
cells2 |
A data frame with language dependent cells metadata. |
acrosscells |
A data frame with metadata that spans multiple cells. |
data |
A data frame with data. |
Value
A px object
Population Greenland
Description
A subset of the population count data available in Statistic Greenland's BEESTA table.
Usage
population_gl
Format
An object of class tbl_df
(inherits from tbl
, data.frame
) with 30 rows and 4 columns.
Source
https://bank.stat.gl/pxweb/en/Greenland/Greenland__BE__BE01__BE0120/BEXSTA.px/
Create a px object
Description
Create a px object from a PX-file, an Excel metadata workbook, or a data frame.
Usage
px(input = NULL, data = NULL, validate = TRUE)
Arguments
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 |
Value
A px object
Examples
# Create px object from dataset
x1 <- px(population_gl)
# Download PX-file for example
download_succeeded <- tryCatch({
px_path <- tempfile(fileext = ".px")
url <- "https://bank.stat.gl:443/sq/0cf06962-19f1-4d5c-8d43-b7ed0009617d"
download.file(url, px_path)
TRUE
}, error = function(e) FALSE)
# Run examples only if file was downloaded
if (download_succeeded) {
# Create px object from PX-file
x2 <- px(px_path)
# Create px object from URL
x3 <- px(url)
}
# Create minimal px object
x4 <- px()
Add total levels to variables
Description
Adds a total level, which is the sum of the figures for all other levels of the variable.
The default name of the total level is 'Total', unless px_elimination is set, in which case the elimination code is used.
Usage
px_add_totals(x, value, na.rm = TRUE, validate)
## S3 method for class 'px'
px_add_totals(x, value, na.rm = TRUE, validate = TRUE)
Arguments
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 |
Value
A px object
See Also
Examples
# Create small px object example
x0 <- px(subset(population_gl, age == "65+"))
px_data(x0)
# Add total level to one variable
x1 <- px_add_totals(x0, "gender")
px_data(x1)
# Add total level to multiple variables
x2 <- px_add_totals(x0, c("gender", "age"))
px_data(x2)
# The name of the total level can be changed with px_elimination()
x3 <-
x0 |>
px_elimination("T") |>
px_add_totals("gender")
px_data(x3)
AGGREGALLOWED
Description
Inspect or change AGGREGALLOWED.
Usage
px_aggregallowed(x, value, validate)
## S3 method for class 'px'
px_aggregallowed(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# Set AGGREGALLOWED
x1 <-
px(population_gl) |>
px_aggregallowed('NO')
# Print AGGREGALLOWED
px_aggregallowed(x1)
# Remove AGGREGALLOWED
x2 <- px_aggregallowed(x1, NULL)
px_aggregallowed(x2)
AUTOPEN
Description
Inspect or change AUTOPEN.
Usage
px_autopen(x, value, validate)
## S3 method for class 'px'
px_autopen(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# Set AUTOPEN
x1 <-
px(population_gl) |>
px_autopen('YES')
# Print AUTOPEN
px_autopen(x1)
# Remove AUTOPEN
x2 <- px_autopen(x1, NULL)
px_autopen(x2)
AXIS-VERSION
Description
Inspect or change AXIS-VERSION.
Usage
px_axis_version(x, value, validate)
## S3 method for class 'px'
px_axis_version(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# 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)
BASEPERIOD
Description
Inspect or change BASEPERIOD.
Usage
px_baseperiod(x, value, validate)
## S3 method for class 'px'
px_baseperiod(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
CELLNOTE
Description
Inspect or change CELLNOTE.
Usage
px_cellnote(x, value, na_to_star, validate)
## S3 method for class 'px'
px_cellnote(x, value, na_to_star = TRUE, validate = TRUE)
Arguments
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 |
Value
A px object or data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
CELLNOTEX
Description
Inspect or change CELLNOTEX.
Usage
px_cellnotex(x, value, na_to_star, validate)
## S3 method for class 'px'
px_cellnotex(x, value, na_to_star = TRUE, validate = TRUE)
Arguments
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 |
Value
A px object or data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
CFPRICES
Description
Inspect or change CFPRICES.
Usage
px_cfprices(x, value, validate)
## S3 method for class 'px'
px_cfprices(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
CHARSET
Description
Inspect or change CHARSET.
Usage
px_charset(x, value, validate)
## S3 method for class 'px'
px_charset(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# 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
Description
Create a classification object from a data frame or .vs and .agg files.
Usage
px_classification(name, prestext, domain, df, vs_path, agg_paths)
Arguments
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. If the column type is character the aggregation levels will be sorted alphabetically; use factors to control the ordering. |
vs_path |
Optional. Path to a values set (.vs) file. |
agg_paths |
Optional.
|
Details
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.
For aggregations, it's normally possible to have codes and values in the .agg file under the sections '[Aggreg]' and '[Aggtext]' respectively. However, in pxmake's implementation of classifications, it's not possible to distinguish between these. When a new classification is created, the values in the section '[Aggtext]' are used as aggregation values.
Only value sets of type 'V' are supported. Type values sets with type 'H' and 'N' are not supported.
Value
A classification object
Examples
# 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)
}
px classification from data frame
Description
Create px classification from a data frame.
Usage
px_classification_from_df(name, prestext, domain, df)
Arguments
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. If the column type is character the aggregation levels will be sorted alphabetically; use factors to control the ordering. |
Value
A classification object
px classification from path
Description
Create px classification from .vs and .agg files
Usage
px_classification_from_path(vs_path, agg_paths)
Arguments
vs_path |
Optional. Path to a values set (.vs) file. |
agg_paths |
Optional.
|
Value
A classification object
CODEPAGE
Description
Inspect or change CODEPAGE.
Usage
px_codepage(x, value, validate)
## S3 method for class 'px'
px_codepage(x, value, validate = TRUE)
Arguments
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 |
Details
CODEPAGE controls which encoding PX-files are read and stored in.
Use iconvlist()
to see available encodings on your system.
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# 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)
CONFIDENTIAL
Description
Inspect or change CONFIDENTIAL.
Usage
px_confidential(x, value, validate)
## S3 method for class 'px'
px_confidential(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# Set CONFIDENTIAL
x1 <-
px(population_gl) |>
px_confidential('1')
# Print CONFIDENTIAL
px_confidential(x1)
# Remove CONFIDENTIAL
x2 <- px_confidential(x1, NULL)
px_confidential(x2)
CONTACT
Description
Inspect or change CONTACT.
Usage
px_contact(x, value, validate)
## S3 method for class 'px'
px_contact(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
CONTENTS
Description
Inspect or change CONTENTS.
Usage
px_contents(x, value, validate)
## S3 method for class 'px'
px_contents(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
CONTVARIABLE
Description
Inspect or change CONTVARIABLE.
Setting CONTVARIABLE indexes several variables in table2. Removing CONTVARIABLE removes the indexing from table2.
Usage
px_contvariable(x, value, validate)
## S3 method for class 'px'
px_contvariable(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# 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)
COPYRIGHT
Description
Inspect or change COPYRIGHT.
Usage
px_copyright(x, value, validate)
## S3 method for class 'px'
px_copyright(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# Set COPYRIGHT
x1 <-
px(population_gl) |>
px_copyright('YES')
# Print COPYRIGHT
px_copyright(x1)
# Remove COPYRIGHT
x2 <- px_copyright(x1, NULL)
px_copyright(x2)
CREATION-DATE
Description
Inspect or change CREATION-DATE.
Usage
px_creation_date(x, value, validate)
## S3 method for class 'px'
px_creation_date(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# 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)
DATA
Description
Inspect or change DATA.
Usage
px_data(x, value, labels, validate)
## S3 method for class 'px'
px_data(x, value, labels = FALSE, validate = TRUE)
Arguments
x |
A px object |
value |
Optional. A data frame. If missing, the current DATA is returned. If NULL, all data rows are removed. |
labels |
Optional. Logic or character vector. If TRUE, the data table is returned with VALUES instead of CODES. By default the VALUES of the main language are returned, use a character language code to return VALUES for a specific language. |
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 |
Details
If adding a new data frame, metadata is generated for the new columns and removed for columns that are no longer present.
Value
A px object or data frame.
See Also
Statistics Sweden's documentation
Examples
x1 <- px(population_gl)
# Print data table
px_data(x1)
# Change data table
population_gl_2024 <- subset(population_gl, year == 2024)
x2 <- px_data(x1, population_gl_2024)
# Return data table with VALUES instead of CODES
px_data(x1, labels = TRUE)
# Return VALUES for a specific language
x_mult <-
x1 |>
px_languages(c("en", "gl"))
px_data(x_mult, labels = "gl")
DECIMALS
Description
Inspect or change DECIMALS.
Usage
px_decimals(x, value, validate)
## S3 method for class 'px'
px_decimals(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# Set DECIMALS
x1 <-
px(population_gl) |>
px_decimals('3')
# Print DECIMALS
px_decimals(x1)
DESCRIPTION
Description
Inspect or change DESCRIPTION.
Usage
px_description(x, value, validate)
## S3 method for class 'px'
px_description(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
DESCRIPTIONDEFAULT
Description
Inspect or change DESCRIPTIONDEFAULT.
Usage
px_descriptiondefault(x, value, validate)
## S3 method for class 'px'
px_descriptiondefault(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# Set DESCRIPTIONDEFAULT
x1 <-
px(population_gl) |>
px_descriptiondefault('YES')
# Print DESCRIPTIONDEFAULT
px_descriptiondefault(x1)
# Remove DESCRIPTIONDEFAULT
x2 <- px_descriptiondefault(x1, NULL)
px_descriptiondefault(x2)
DOMAIN
Description
Inspect or change DOMAIN.
Usage
px_domain(x, value, validate)
## S3 method for class 'px'
px_domain(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
ELIMINATION
Description
Inspect or change ELIMINATION.
Usage
px_elimination(x, value, validate)
## S3 method for class 'px'
px_elimination(x, value, validate = TRUE)
Arguments
x |
A px object |
value |
Optional. Use character to set ELIMINATION for all STUB and HEADING variables. Use a data frame with columns 'variable-code' and 'elimination' to set ELIMINATION for individual variables. If value is missing, the current ELIMINATION is returned. If NULL, ELIMINATION is removed for all variables. |
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 |
Value
A px object or data frame.
See Also
Statistics Sweden's documentation
Examples
library(tibble)
# Set ELIMINATION
x1 <-
px(population_gl) |>
px_elimination(tribble(~`variable-code`, ~elimination,
"gender", "T",
"age", "YES"
)
)
# Print ELIMINATION
px_elimination(x1)
# Remove ELIMINATION
x2 <- px_elimination(x1, NULL)
px_elimination(x2)
Change figures variable
Description
Inspect or change which variable is used as figures. The previous figures variable is changed to STUB. There can only be one figures variable.
Usage
px_figures(x, value, validate)
## S3 method for class 'px'
px_figures(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string
See Also
Examples
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)
Create a minimal px object from a data frame
Description
Create a minimal px object from a data frame
Usage
px_from_data_df(df)
Arguments
df |
A data frame |
Value
A px object
Create a px object from an Excel workbook
Description
Create a px object from an Excel workbook
Usage
px_from_excel(excel_path, data = NULL)
Arguments
excel_path |
Path to Excel metadata workbook. |
data |
A data frame if data isen't stored in the Excel workbook. |
Value
A px object.
Create a px object form a PX-file
Description
Create a px object form a PX-file
Usage
px_from_px_file(path)
Arguments
path |
Path to a PX-file |
Value
A px object
HEADING
Description
Inspect or change HEADING.
Usage
px_heading(x, value, validate)
## S3 method for class 'px'
px_heading(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character vector.
See Also
Statistics Sweden's documentation
Examples
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)
INFOFILE
Description
Inspect or change INFOFILE.
Usage
px_infofile(x, value, validate)
## S3 method for class 'px'
px_infofile(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
px keywords
Description
Properties of all px keywords. Used internally by the package.
Usage
px_keywords
Format
A data frame:
- keyword
Name
- px_function
Function name
- mandatory
Is required in a PX-file
- table_meta
Is metadata for entire table; not individual variables or cells
- language_dependent
Is language dependent
- indexed_by_contvariable
Is indexed if CONTVARIABLE is set
- quote_value
Value should be quoted in PX-file
- default_value
Default value for mandatory keywords
- documentation
URL to Statistic Sweden's documentation
- order
Recommended order
Source
https://www.scb.se/globalassets/vara-tjanster/px-programmen/PX-file_format_specification_2013.pdf
LANGUAGE
Description
Inspect or change LANGUAGE.
Usage
px_language(x, value, validate)
## S3 method for class 'px'
px_language(x, value, validate = TRUE)
Arguments
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 |
Details
If LANGUAGES is defined, changing LANGUAGE will also add is to LANGUAGES.
Value
A px object
See Also
Examples
# 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)
LANGUAGES
Description
Inspect or change LANGUAGES.
Usage
px_languages(x, value, validate)
## S3 method for class 'px'
px_languages(x, value, validate = TRUE)
Arguments
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 |
Details
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.
Value
A px object
See Also
Examples
# 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)
LAST-UPDATED
Description
Inspect or change LAST-UPDATED.
Usage
px_last_updated(x, value, validate)
## S3 method for class 'px'
px_last_updated(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
LINK
Description
Inspect or change LINK.
Usage
px_link(x, value, validate)
## S3 method for class 'px'
px_link(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
MAP
Description
Inspect or change MAP.
Usage
px_map(x, value, validate)
## S3 method for class 'px'
px_map(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
MATRIX
Description
Inspect or change MATRIX.
Usage
px_matrix(x, value, validate)
## S3 method for class 'px'
px_matrix(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# Set MATRIX
x1 <-
px(population_gl) |>
px_matrix('POPULATION')
# Print MATRIX
px_matrix(x1)
Create micro PX-files
Description
Split one px object into many small PX-files (micro files), with count of the variables in it.
Usage
px_micro(x, out_dir = NULL, keyword_values = NULL)
Arguments
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. |
Details
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.
Value
Nothing
Examples
# 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)
NEXT-UPDATE
Description
Inspect or change NEXT-UPDATE.
Usage
px_next_update(x, value, validate)
## S3 method for class 'px'
px_next_update(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# 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)
NOTE
Description
Inspect or change NOTE.
Usage
px_note(x, value, validate)
## S3 method for class 'px'
px_note(x, value, validate = TRUE)
Arguments
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 |
Details
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.
Value
A px object, a character string, a data frame, or a list of character strings and/or data frames.
See Also
Statistics Sweden's documentation
Examples
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)
NOTEX
Description
Inspect or change NOTEX.
Usage
px_notex(x, value, validate)
## S3 method for class 'px'
px_notex(x, value, validate = TRUE)
Arguments
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 |
Details
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.
Value
A px object, a character string, a data frame, or a list of character strings and/or data frames.
See Also
Statistics Sweden's documentation
Examples
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)
Change value order
Description
Inspect or change ORDER.
Usage
px_order(x, value, validate)
## S3 method for class 'px'
px_order(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or data frame.
Examples
# 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)
PRECISION
Description
Inspect or change PRECISION.
Usage
px_precision(x, value, validate)
## S3 method for class 'px'
px_precision(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or data frame.
See Also
Statistics Sweden's documentation
Examples
# 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
Description
Save px object to file
Usage
px_save(x, path, save_data = TRUE, data_path = NULL)
Arguments
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 |
Details
Use px_codepage()
to change file encoding.
Value
Nothing
See Also
Examples
# 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 classification as .vs and .agg files
Description
Save a classification object as .vs and .agg files. The .vs file contains the value set and the .agg files contain the aggregations.
Usage
px_save_classification(c, path)
Arguments
c |
A classification object |
path |
Directory to save the files in |
Value
Nothing.
Examples
# 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())
SHOWDECIMALS
Description
Inspect or change SHOWDECIMALS.
Usage
px_showdecimals(x, value, validate)
## S3 method for class 'px'
px_showdecimals(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# Set SHOWDECIMALS
x1 <-
px(population_gl) |>
px_showdecimals('2')
# Print SHOWDECIMALS
px_showdecimals(x1)
# Remove SHOWDECIMALS
x2 <- px_showdecimals(x1, NULL)
px_showdecimals(x2)
SOURCE
Description
Inspect or change SOURCE.
Usage
px_source(x, value, validate)
## S3 method for class 'px'
px_source(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
STOCKFA
Description
Inspect or change STOCKFA.
Usage
px_stockfa(x, value, validate)
## S3 method for class 'px'
px_stockfa(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
STUB
Description
Inspect or change STUB.
Usage
px_stub(x, value, validate)
## S3 method for class 'px'
px_stub(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character vector.
See Also
Statistics Sweden's documentation
Examples
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)
SUBJECT-AREA
Description
Inspect or change SUBJECT-AREA.
Usage
px_subject_area(x, value, validate)
## S3 method for class 'px'
px_subject_area(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
SUBJECT-CODE
Description
Inspect or change SUBJECT-CODE.
Usage
px_subject_code(x, value, validate)
## S3 method for class 'px'
px_subject_code(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# Set SUBJECT-CODE
x1 <-
px(population_gl) |>
px_subject_code('POP')
# Print SUBJECT-CODE
px_subject_code(x1)
TABLEID
Description
Inspect or change TABLEID.
Usage
px_tableid(x, value, validate)
## S3 method for class 'px'
px_tableid(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# Set TABLEID
x1 <-
px(population_gl) |>
px_tableid('POPGL')
# Print TABLEID
px_tableid(x1)
# Remove TABLEID
x2 <- px_tableid(x1, NULL)
px_tableid(x2)
TIMEVAL
Description
Inspect or change TIMEVAL.
There can only be one time variable.
Usage
px_timeval(x, value, validate)
## S3 method for class 'px'
px_timeval(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# Set TIMEVAL
x1 <-
px(population_gl) |>
px_timeval('year')
# Print TIMEVAL
px_timeval(x1)
# Remove TIMEVAL
x2 <- px_timeval(x1, NULL)
px_timeval(x2)
TITLE
Description
Inspect or change TITLE.
TITLE can only be removed if DESCRIPTION is set.
Usage
px_title(x, value, validate)
## S3 method for class 'px'
px_title(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
UNITS
Description
Inspect or change UNITS.
Usage
px_units(x, value, validate)
## S3 method for class 'px'
px_units(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
UPDATE-FREQUENCY
Description
Inspect or change UPDATE-FREQUENCY.
Usage
px_update_frequency(x, value, validate)
## S3 method for class 'px'
px_update_frequency(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or a character string.
See Also
Statistics Sweden's documentation
Examples
# 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)
Check px object
Description
Runs a number of checks on px object to see if it is valid.
Usage
px_validate(x)
Arguments
x |
A supposed px object. |
Details
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.
Value
A valid px object.
Examples
# 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()
VALUENOTE
Description
Inspect or change VALUENOTE.
Usage
px_valuenote(x, value, validate)
## S3 method for class 'px'
px_valuenote(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
VALUENOTEX
Description
Inspect or change VALUENOTEX.
Usage
px_valuenotex(x, value, validate)
## S3 method for class 'px'
px_valuenotex(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
VALUES
Description
Inspect or change VALUES.
Usage
px_values(x, value, validate)
## S3 method for class 'px'
px_values(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or data frame.
See Also
Statistics Sweden's documentation
Examples
# 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)
Change VARIABLE-LABEL
Description
Inspect or change VARIABLE-LABEL.
The variable label is the name that is shown in the PX-file.
Usage
px_variable_label(x, value, validate)
## S3 method for class 'px'
px_variable_label(x, value, validate = TRUE)
Arguments
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 |
Value
A px object, a character string, or a data frame.
Examples
# 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)
VARIABLE-TYPE
Description
Inspect or change VARIABLE-TYPE.
Usage
px_variable_type(x, value, validate)
## S3 method for class 'px'
px_variable_type(x, value, validate = TRUE)
Arguments
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 |
Value
A px object or data frame.
See Also
Statistics Sweden's documentation
Examples
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)
Add quotes around unless in some very specific cases required by the px format
Description
Add quotes around unless in some very specific cases required by the px format
Usage
quote_unless_yes_no(str)
Arguments
str |
String to quote |
Value
String
Read lines from file with guessed encoding
Description
Wrapper around readLines to guess encoding before reading.
Usage
readLines_guess_encoding(path)
Arguments
path |
Path to file |
Value
A character vector
Read lines with specific encoding
Description
Read lines with specific encoding
Usage
readLines_with_encoding(path, encoding)
Arguments
path |
Path to file |
encoding |
Encoding to use |
Value
A character vector
Get PX-file content as lines
Description
Read file with correct encoding.
Usage
read_px_file(px_path)
Arguments
px_path |
Path to a PX-file |
Value
A character vector
Impute missing language
Description
Add main language as language if language is missing.
Usage
replace_na_language_with_main_language(metadata_df)
Arguments
metadata_df |
Data frame with metadata. |
Value
A data frame
Return px object
Description
Wrapper potentially validate it and return px object.
Usage
return_px(x, validate)
Arguments
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 |
Save px object to PX-file
Description
Save px object to PX-file
Usage
save_px_as_px_file(x, path)
Arguments
x |
A px object |
path |
Path to save PX-file at |
Value
Nothing
Save px object as an R script
Description
Running the R script creates the px object.
Usage
save_px_as_r_script(x, path, data_path)
Arguments
x |
A px object |
path |
Path to save R script at |
data_path |
|
Value
Nothing
Save px object as an Excel workbook
Description
Save px object as an Excel workbook
Usage
save_px_as_xlsx(x, path, save_data, data_path)
Arguments
x |
A px object |
path |
Path to save Excel workbook |
save_data |
If FALSE, no 'Data' sheet is created in the Excel workbook.
Can only be used if |
data_path |
Path to an |
Value
Nothing
Get index of first and last line of section
Description
Get index of first and last line of section
Usage
section_interval(lines, head_line)
Arguments
lines |
A character vector |
head_line |
A numeric value, line number of section heading |
Smallest larger value
Description
Smallest larger value
Usage
smallest_larger_value(vec, value)
Arguments
vec |
A numeric vector |
value |
A numeric value |
Value
The smallest value in 'vec' that is larger than 'value'
Sort metadata data frame
Description
The data frame is first sorted by the keyword order defined in the px-specification and then by the language order.
Usage
sort_metadata_df(metadata_df)
Arguments
metadata_df |
Data frame with metadata. |
Value
A data frame
Add quotes around string
Description
Add quotes around string
Usage
str_quote(str)
Arguments
str |
String to quote |
Value
String
Create and return path to temporary directory
Description
Create and return path to temporary directory
Usage
temp_dir()
Value
Character
Create temporary file
Description
Get a temporary file path with a specific extension (function factory)
Usage
temp_file_with_extension(extension)
Arguments
extension |
String, file name extension |
Value
Path to temporary file
Check all arguments to px()
Description
Check all arguments to px()
Usage
validate_px_arguments(input, data)
Arguments
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 |
Value
Nothing
Check all arguments to px_classification
Description
Check all arguments to px_classification
Usage
validate_px_classification_arguments(
name,
prestext,
domain,
df,
vs_path,
agg_paths
)
Arguments
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. If the column type is character the aggregation levels will be sorted alphabetically; use factors to control the ordering. |
vs_path |
Optional. Path to a values set (.vs) file. |
agg_paths |
Optional.
|
Value
Nothing
Check all arguments to px_data
Description
Check all arguments to px_data
Usage
validate_px_data_arguments(x, value, labels, validate)
Arguments
x |
A px object |
value |
Optional. A data frame. If missing, the current DATA is returned. If NULL, all data rows are removed. |
labels |
Optional. Logic or character vector. If TRUE, the data table is returned with VALUES instead of CODES. By default the VALUES of the main language are returned, use a character language code to return VALUES for a specific language. |
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 |
Value
Nothing
Check all arguments to px_micro()
Description
Check all arguments to px_micro()
Usage
validate_px_micro_arguments(x, out_dir)
Arguments
x |
A px object. |
out_dir |
Directory to save PX-files in. |
Value
Nothing
Check all arguments to px_save()
Description
Check all arguments to px_save()
Usage
validate_px_save_arguments(x, path, save_data, data_path)
Arguments
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 |
Value
Nothing
Convert a variable to a list
Description
Convert a variable to a list
Usage
wrap_varaible_in_list(df, var)
Arguments
df |
Data frame |
var |
Character. Variable to convert to list |
Value
A data frame
Save classification as .agg file
Description
Write one aggregation column in a classification to an .agg file.
Usage
write_aggregation(aggregation, c, directory)
Arguments
aggregation |
Character, the column name of the aggregation in the classification |
c |
A classification object |
directory |
Directory to save the file in |
Value
Nothing
Save classification as .vs file
Description
Write value set part of classification to a file.
Usage
write_value_set(c, directory)
Arguments
c |
A classification object |
directory |
Directory to save the file in |
Value
Nothing
Zips list
Description
Combine two list, by zipping them together in the order v1[1]
,
v2[1]
, v1[2]
, v2[2]
, v1[3]
, ...
Usage
zip_vectors(v1, v2)
Arguments
v1 |
First vector Elements ends up on uneven indexes. |
v2 |
Second vector. Elements ends up on even indexes. |
Value
List