Split a Character String into Fields

DESCRIPTION:

Splits a character string into a vector of character strings representing fields in the original string separated by a given character string.

USAGE:

unpaste(str, sep="/", fnames=NULL, nfields=NULL, first=c(1, 3, 5), width=2)

REQUIRED ARGUMENTS:

str
a list or vector of character strings, such as might be returned from a database query.

OPTIONAL ARGUMENTS:

sep
a single-character specifying the separator between fields in str.
fnames
a character vector of field names.
nfields
an integer specifying the number of fields.
first
a numeric vector specifying the location within the string of field starting points for fixed-format data.
width
a numeric vector specifying the width of fixed-format data fields.

VALUE:

a list containing the separated fields.

DETAILS:

If sep is not the empty string "" , unpaste uses sep to determine field boundaries, and extracts the contents of each field as a character string. If sep is the empty string, unpaste uses the first and width argument to determine the beginning and width of each field, then uses the substring function to extract the contents of each fixed-format field.

Often, it is convenient to return a character vector instead of a list; this can be accomplished by wrapping the call to unpaste inside a call to unlist.

SEE ALSO:

, .

EXAMPLES:

# Break a string into its individual characters:
unlist(unpaste(str = "seattle", sep = "", 
       first = 1:nchar("seattle"), width = 1))
[1] "s" "e" "a" "t" "t" "l" "e"
# Separate the user's path into its components:
unpaste(getenv("PATH"), sep=":")
# Return the user's path as a character vector:
unlist(unpaste(getenv("PATH"), sep=":"))