Create a classification object from a data frame or .vs and .agg files.
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.
- vs_path
Optional. Path to a values set (.vs) file.
- agg_paths
Optional.
If NULL, aggregation paths are automatically taken from the [Aggreg] field in the .vs file.
Use a vector of paths to one or more aggregation files (.agg) to manually choose aggregations.
Use character(0) if aggregations from the .vs files should not be added automatically.
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.
Only type 'V' value sets are supported. Type 'H' and 'N' value sets are not supported.
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+"
)
)
if (FALSE) { # \dontrun{
# Create classification from .vs file and use aggregations mentioned in .vs
c2 <- px_classification(vs_path = "path/to/value_set.vs")
# Create classification from .vs file and manually specify aggregation files
c3 <- px_classification(vs_path = "path/to/value_set.vs",
agg_paths = c("path/to/aggregation1.agg",
"path/to/aggregation2.agg"
)
)
} # }