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

Description Usage Arguments Value Examples

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

Description

reads a conveniently tagged file into nested lists. It is just the linking of the two functions file2char and char2list, see their comments for the description of the arguments.

Usage

1
2
3
4
file2list(file, path="./", clean=TRUE, ended=")STOP(", comme="#",
	  skip=matrix(c(")SKIPPING(", ")READING("), 1),
	  include=c(")FILE("), tags=rbsb.tag1, sep=rbsb.sep0,
	  rsep="no_action", stag=c("/", "/"))

Arguments

file

file to be read and transformed into a list.

path

Directory containing the file.

clean

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

ended

To indicate the line from which to stop the reading.

comme

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 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.

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
15
16
17
18
19
 rbsb3k("reset"); # for R checking convenience
 sink("rbsb.list.txt")
 cat("# comments can be included as well\n")
 cat("<<A>>\n");
 cat("[[a]]/*/v 1*un deux trois\n");
 cat("[[b]]/*/v 1*2*3\n");
 cat("un uno one\n");
 cat("deux dos two\n");
 cat("trois tres three\n");
 cat("<<B>>\n");
 cat("[[a]] un deux trois\n");
 cat("# the following three are interesting\n");
 cat("[[b]] un uno one\n");
 cat(" deux dos two\n");
 cat("trois tres three\n");
 cat("<<C>> 1 2 3\n");
 sink();
 file2list("rbsb.list.txt");
 unlink("rbsb.list.txt");

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