inputting: reads a file and transforms it in a single character

Description Usage Arguments Details Value Examples

Description

(file2text) reads a conveniently tagged file to produce a vector of characters where all non used lines are eliminated. Each component of the resulting vector is associated to an original line.
(text2file) The reverse operation of file2text. This function is not very tricky, it was written for completeness.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
 
  file2text(file,path="",
            clean=TRUE,
            ended=")STOP(",
            comment="#",
            skip=matrix(c(")START_SKIPPING(",")END_SKIPPING(",
            "/*","*/"),ncol=2,byrow=TRUE),
            include=c(")FILE("),
            monitor=rbsa0$monitor$v
            ) 
  text2file(text,file,path="",
            ap=FALSE,
            monitor=rbsa0$monitor$v
            ) 

Arguments

file

file which have to be read and transformed into a list.

text

The character to be written into file.

path

Directory containing the file.

clean

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

ended

The tag indicating 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. If no comment line must be filtered, just give comment the value of character(0).

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.

monitor

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

ap

Must the file be appended if it already exist?

Details

All tags are supposed to be in the first position of the line after cleaning when asked.
Successive performed actions are : (i) cleaning the lines, i.e. removing starting and ending spaces, (ii) eliminating commented lines, (iii) eliminating lines after a 'stop', (iv) including indicated files and (v) skipping sequences of lines.

Value

(file2text) a character of length, the number of retained lines.
(text2file) Nothing but a file is created or completed when everything is right -or- according to the value of file, 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
 
  ## 
  ## file2text 
  sink("rbsa.text.txt") 
  cat("# comments can be included as well\n") 
  cat(" something\n"); 
  cat("/* skipping from here\n"); 
  cat("blablabla\n"); 
  cat("  */ until here (this line is ALSO eliminated\n"); 
  cat(" interesting:\n"); 
  cat("un dos tres\n"); 
  cat(")STOP(\n"); 
  cat(" It is finished!\n"); 
  cat(" Don't insist!\n"); 
  sink(); 
  file2text("rbsa.text.txt"); 
  unlink("rbsa.text.txt"); 
  ## 
  ## text2file 
  text2file(letters,"toto.txt"); 
  unlink("toto.txt"); 
  text2file(letters,character(0)); 

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