NASISChoiceList: Work with NASIS Choice Lists

View source: R/uncode.R

NASISChoiceListR Documentation

Work with NASIS Choice Lists

Description

Create (ordered) factors and interchange between choice names, values and labels for lists of input vectors.

Usage

NASISChoiceList(
  x = NULL,
  colnames = names(x),
  what = "ColumnPhysicalName",
  choice = c("ChoiceName", "ChoiceValue", "ChoiceLabel"),
  obsolete = FALSE,
  factor = TRUE,
  droplevels = FALSE,
  ordered = TRUE,
  simplify = TRUE,
  dsn = NULL
)

Arguments

x

A named list of vectors to use as input for NASIS Choice List lookup

colnames

vector of values of the column specified by what. E.g. colnames="texcl" for what="ColumnPhysicalName". Default: names(x) (if x is named)

what

passed to get_NASIS_column_metadata(); Column to match x against. Default "ColumnPhysicalName"; alternate options include "DomainID", "DomainName", "DomainRanked", "DisplayLabel", "ChoiceSequence", "ChoiceValue", "ChoiceName", "ChoiceLabel", "ChoiceObsolete", "ChoiceDescription", "ColumnLogicalName"

choice

one of: "ChoiceName", "ChoiceValue", or "ChoiceLabel"

obsolete

Include "obsolete" choices? Default: FALSE

factor

Convert result to factor? Default: TRUE

droplevels

Drop unused factor levels? Default: TRUE (used only when factor=TRUE)

ordered

Should the result be an ordered factor? Default: TRUE (use only if DomainRanked is true for all choices)

simplify

Should list result with length 1 be reduced to a single vector? Default: TRUE

dsn

Optional: path to local SQLite database containing NASIS table structure; default: NULL

Value

A list of "choices" based on the input x that have been converted to a consistent target set of levels (specified by choice) via NASIS 7 metadata.

When factor=TRUE the result is a factor, possibly ordered when ordered=TRUE and the target domain is a "ranked" domain (i.e. ChoiceSequence has logical meaning).

When factor=FALSE the result is a character or numeric vector. Numeric vectors are always returned when choice is "ChoiceValue".

Examples


NASISChoiceList(1:3, "texcl")

NASISChoiceList(1:3, "pondfreqcl")

NASISChoiceList("Clay loam", "texcl", choice = "ChoiceValue")

NASISChoiceList("Silty clay loam", "texcl", choice = "ChoiceName")

soilDB documentation built on Sept. 11, 2024, 8:28 p.m.