R/strToVec.R

Defines functions strToVec

Documented in strToVec

#' strToVec 
#' @param string a string of class character which is to be split 
#' @param delimiter a string of class character indicating the delimiter at which the string \code{string} is supposed to be split (e.g. ",", "-", " " etc.)
#' @return strToVec returns a vector of class character with elements created by splitting \code{string} at \code{delimiter}
#' @description strToVec takes as input a character string (\code{string}) and a delimiter (\code{delimiter}) and returns a vector of class character whose elements are created by splitting the string at the delimiter
#' @examples
#' strToVec("Monday,Tuesday,Wednesday,Thursday,Friday",",")
#' strToVec("Jun-Jul-Aug-Sep","-")
#' strToVec("alpha beta gamma"," ")
#' @export
strToVec<-function(string,delimiter)
{
  if(class(string)!="character")
  {vec<-unlist(strsplit(as.character(string),delimiter))}   #cast the string variable into a character first, then split the string
  else
    vec<-unlist(strsplit(string,delimiter))
  return(vec)
}
lwTools/agriTrf documentation built on March 26, 2020, 12:09 a.m.