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

Description Usage Arguments Details Value Examples

View source: R/filelist.code.r

Description

(file2list) reads a conveniently tagged text file into nested lists. It is just the linking of the two functions file2text and text2list, see their comments for the description of the arguments.
(list2file) Transforms a list and writes it onto a text file. The reverse operation of file2list and just the successive calls of list2text and text2file. See their own descriptions for complete details.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
 
  file2list(file,path="",
            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("/","/")
            ) 
  list2file(lili,file,path="",
            tags=rbsa0$tag1$v,
            stag=c("/",";","/"),
            comment="#",
            comments=character(0),
            ap=FALSE,
            monitor=rbsa0$monitor$v
            ) 

Arguments

file

file to be read and transformed into a list.

lili

The list structure to be transformed and written in file.

path

Directory containing the file.

clean

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

ended

To indicate the line at 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 hyphen 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; that is skipping with the first row is performed, then with the remaining lines, skipping witht the second row is performed, and so on.

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 character vectors of every line. Notice that LF is always considered as a separator.

rsep

Indicates if repetitions of sep must be considered as significant or not; when significant "" values are introduced. If no_action then the repetitions will be ignored.

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.

comments

Comments that the user want to be added at the beginning of the file. Moreover, the function will introduce its signature at the beginning of the file.

ap

Must the file be appended if it already exist?

monitor

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

Details

(list2file) No use is made of the general constant monitor$chk$v. Of course, the permission to write must exist in the proposed directory.

Value

(file2list) a list [of lists [of lists [...] ] ] of character (possibly named) vectors or matrices or arrays.
(list2file) Nothing but a file is created or modified when everything is right; except when
file==character(0), in that case a character is returned.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
  ## 
  ## file2list 
  sink("rbsa.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("rbsa.list.txt"); 
  unlink("rbsa.list.txt"); 
  ## 
  ## list2file 
  list2file(rbsa0$lis1$v,"toto.txt"); 
  unlink("toto.txt"); 
  list2file(rbsa0$lis1$v,file=character(0)); 

rbsa documentation built on May 31, 2017, 4:29 a.m.