R/get_leaf_code.R

Defines functions get_leaf_code

get_leaf_code <- function(x,
                          inductiveCodingHierarchyMarker) {

  if ((length(x)==0) || is.na(x)) {
    return(NA_character_);
  }

  if (length(x) > 1) {
    stop("Only pass exactly one code / string!");
  }

  ### Split by hierarchy marker; select first object in list,
  ### because strsplit always returns a list of the results
  ### since it's vectorized over x
  res <-
    strsplit(x,
             inductiveCodingHierarchyMarker)[[1]];

  ### Extract last substring and return it.
  return(utils::tail(res, 1));
}

Try the rock package in your browser

Any scripts or data that you put into this service are public.

rock documentation built on Dec. 28, 2022, 1:55 a.m.