char2list: transforms a character into a list (of lists) of characters

Description Usage Arguments Details Value Examples

View source: R/f0.rbsb1.code.r

Description

from a conveniently tagged character vector, returns nested lists. Most often such a character is obtained by reading a file with the function file2char, this explains why it is convenient to speak about 'lines' rather about 'components of the character vector'.
All lists are named lists and the tags give the names of their component. The maximum number of nested levels of lists is given by the number of rows of the matrix tags. The corresponding two columns give the opening and closing sequence of the tags. Final lists contain character vectors, each component of them being on the same line and/or on the following line (before a new tag).
All tags must start at the very beginning of a line. All separator tags must be used sticked to the list tag.

Usage

1
2
char2list(chara, tags=rbsb.tag1, sep=rbsb.sep0, rsep="no_action", stag=c("/",
	  "/"))

Arguments

chara

character vector to be transformed into a list.

tags

Character matrix with two columns indicating the opening and closing tags of the lists at different levels. Its row numbers gives the maximum number of levels. Opening tags must be different.

sep

Character sequence used to split the character vectors of every line. Notice that LF is always considered as a separator.

rsep

Indicates if repetitions of sep must be considered as signicant or not and which null value to introduce. If no_action then the repetitions will be ignored if not rsep component(s) will be introduced.

stag

Two character strings indicating the tag to define different sep for a given [sub]list. These two correspond to stag[c(1,3)] of list2file function.

Details

It is compulsory to tag each level of the lists, this implies that when starting a new list, a character vma (see char2vma for the details: vma means vector or matrix or array) is provided meaning that this is the final level for this branch, or a new sublist is started with the corresponding tag, or a new component of the list is given at a level less or equal to the present.
Separator between different character component is given by the sep argument or indicated by the separator tag (stag), in the last case, it can be different from a leaf list to another.
Be aware that before reading a line for a character translation, all starting and ending spaces are eliminated.

Value

a list [of lists [of lists [...] ] ] of character (possibly named) vectors or matrices or arrays.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
 rbsb3k("reset"); # for R checking convenience
 chara <- c("<<A>>", 
 "[[a]]/*/v 1*un deux trois", 
 "[[b]]/*/v 1*2*3", 
 "un uno one", 
 "deux dos two", 
 "trois tres three", 
 "<<B>>", 
 "[[a]] un deux trois", 
 "[[b]] un uno one", 
 " deux dos two", 
 "trois tres three", 
 "<<C>> 1 2 3");
 char2list(chara);

rbsb documentation built on May 31, 2017, 1:45 a.m.