Learn R Programming

ksformat (version 0.3.5)

fnew_bid: Create Bidirectional Format

Description

Creates both a format and its corresponding invalue for bidirectional conversion. Both are automatically stored in the global format library if name is provided.

Usage

fnew_bid(..., name = NULL, type = "auto")

Value

List with format (ks_format) and invalue (ks_invalue) components.

Arguments

...

Named arguments for format mappings

name

Character. Base name for both formats. The invalue will be named paste0(name, "_inv").

type

Character. Format type

Examples

Run this code
# Bidirectional status format
status_bi <- fnew_bid(
  "A" = "Active",
  "I" = "Inactive",
  "P" = "Pending",
  name = "status"
)

# Forward: code -> label
fputc(c("A", "I", "P", "A"), "status")
# [1] "Active" "Inactive" "Pending" "Active"

# Reverse: label -> code
finputc(c("Active", "Pending", "Inactive"), "status_inv")
# [1] "A" "P" "I"
fclear()

Run the code above in your browser using DataLab