read8list: reads a file and transforms it in a list (of lists) of...

Description Usage Arguments Details Value See Also Examples

View source: R/rbsa2.code.r

Description

Reads a file and transforms it in a list (of lists) of characters It is a slight generalization of file2list.
It is worth explaining why such a function was written. The obvious one is that not always names for the components of the list are natural. (In future version, it could be good to mixed with and without names). Another reason is that the contraint of 'value only at the final level is not always natural. read8list adds itself 'null' components (named rbsa0$l00$v) to allow it. Finally, levels can be skipped and missing levels are introduced.
So the generalization is that the components of the list have not to be given in the file but are determined by the function from an additionnal line (everywhere in the file) tagged with the third argument starting at the first character. This line contains the list of bullets, giving then their number. Notice that all proposed bullets must be different from rbsa0$l00$v. But everything has to be paid: now the constraint is that every component must have a non empty content.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
 
  read8list(file,path=getwd(),bullet=")BULLETS(",
            clean=TRUE,ended=")STOP(",comment="#",
            skip=matrix(c(")SKIPPING(",")READING("),1),
            include=c(")FILE("),
            tags=rbsa0$tag1$v,
            sep=rbsa0$sep0$v,
            rsep="no_action",
            stag=c("/","/"),
            monitor=rbsa0$monitor$v
            ) 

Arguments

file

file to be read and transformed into a list.

path

Directory containing the file.

bullet

Indicates the bullets to be considered. This tags must be at the very beginning of a line. But the bullets can be preceeded by spaces.

clean

Indicates if starting and ending spaces of every lines must be eliminated at first.

ended

To indicate the line from which to stop the reading.

comment

At the beginning of a line, it indicates that this line must not be considered. More than one commenting character can be considered when it is a vector. For instance c("#","%") means that lines starting with an hash or a percent are comment lines.

skip

To indicate set(s) of lines to be skipped. Must be a character matrix where the two columns correspond respectively to the opening and closing tags, and where each row is associate to a couple of tags. Tags are considered successively following the order of these matrix rows.

include

Tags to indicate a file (including possible path) by a character(1) to include at this point its contents as a text file with the same tags specifications. Including files can be recursive.

tags

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

sep

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

rsep

Indicates if repetitions of sep must be considered as significant 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.

monitor

List of constants indicating the monitoring choices, see the rbsa0$monitor$v provided object as an example.

Details

An intermediary file is generated (and not deleted) to be read by file2list function; its name is obtained from the global constant rbsa0$fin$v.
The numbering of the levels of the list is determined by cycling the global constant rbsa0$tyl$v (run the example to have an idea of what this means).
Only the first three arguments plus the tags are used by this function, all others are directly passed to file2list.
For the moment, the numbering of the different levels does not take into account the level hierarchy, this must be offered in future versions of this function.

Value

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

See Also

list2file

Examples

1
2
3
4
5
6
7
8
9
 
  sink("rbsa.list.txt") 
  cat(rbsa0$text5$v,sep="\n"); 
  sink(); 
  read8list("rbsa.list.txt"); 
  # deleting the created file 
  unlink("rbsa.list.txt"); 
  # deleting the intermediate file 
  unlink(rbsa0$fin$v); 

rbsa documentation built on May 2, 2019, 6:07 p.m.