Skip to contents

The "parseCharInput" function converts a comma-seperated string into a vector by splitting the string along the commas. If "convertToNumeric" is true, the elements of the string will be converted into numbers and a numeric vector will be returned.

Usage

parseCharInput(
  input,
  convertToNumeric = TRUE,
  sort = FALSE,
  expected,
  msg = "wrong length",
  checkdup = FALSE,
  missingMsg = "Unknown",
  checkProb = FALSE,
  valid = FALSE
)

Arguments

input

(Required) The string to be processed

convertToNumeric

(Optional) A logical value. Should the input should be converted into numerics? TRUE by default

sort

(Optional) A logical value. Should the resulting vector be sorted. FALSE by default

expected

(Optional) The expected length of the output vector. No check is performed by default

msg

(Optional) Error message to print if the input is not of the correct length specified by "expected". Default is "Wrong length"

checkdup

(Optional) A logical value. Should an error be generated if there are any duplicated value? FALSE by default

missingMsg

(Optional) Error message to print if the input is missing. Default is "Unknown"

checkProb

(Optional) A logical value. Should the function check that the output vector sums to one? FALSE by default

valid

(Optional) A logical value. Should the validNames function be used to check the validity of the extracted names? FALSE by default

Value

A numeric vector or a character vector depending on the convertToNumeric flag.

See also

parseHashString uses parseCharInput sequentially.

Author

Romain Francois

Examples


  parseCharInput( "1,2,4")
#> [1] 1 2 4
  parseCharInput( "1,6,4", sort = TRUE )
#> [1] 1 4 6

  if (FALSE) {
  ## see also the unit tests for more examples
  file.show( system.file( "Runit", "runit.supportfunctions.R" ,
    package = "MSToolkit"))
  }