Replacing separators (for example, decimal and thousand separators).
Replacing separators (for example, decimal and thousand separators).
convertFile( filename, symbol1 = NULL, symbol2 = NULL, newsymbol1 = "", newsymbol2 = "", sep = ";", newsep = NULL, header = TRUE, columns = NULL, outputfile = gsub("^(.*)(\\.)([^\\.]*)$", "\\1_new.\\3", filename), fixed.s1 = TRUE, fixed.s2 = TRUE, fixed.sep = TRUE, ... )
filename |
String: filename (including path if necessary) of input file. |
symbol1 |
String: symbol to replace by |
symbol2 |
String: second symbol to replace by |
newsymbol1 |
String: symbol to replace |
newsymbol2 |
String: symbol to replace |
sep |
String: column separator. Could be also used to replace symbols
in the header and data by |
newsep |
String: symbol to replace |
header |
Logical: whether or not there is header line. |
columns |
Vector with numerical values: indices of columns in which symbols need to be replaced. |
outputfile |
String: name of outputfile. |
fixed.s1 |
Logical: whether or not to treat |
fixed.s2 |
Logical: whether or not to treat |
fixed.sep |
Logical: whether or not to treat |
... |
Additional parameters for |
Jacolien van Rij
## Not run: # normally, the function call would look something like this: convertFile('example1.csv', symbol1=',', symbol2='.', sep='\t', newsymbol1='.', newsymbol2='') # But as we are not sure that the file example1.csv is available, # we need to do something a little more complicated to point to # the file 'example1.csv' that comes with the package: # finding one of the example files from the package: file1 <- system.file('extdata', 'example1.csv', package = 'plotfunctions') # example 1: system.time({ convertFile(file1, symbol1=',', symbol2='.', newsymbol1='.', newsymbol2='', outputfile='example1_new.csv') }) # example 2: type 'yes' to overwrite the previous output file, # or specify a different filename in outputfile. system.time({ convertFile(file1, symbol1=',', symbol2='.', sep='\t', newsymbol1='.', newsymbol2='', columns=1:2, outputfile='example1_new.csv') }) # Example 1 takes less time, as it does not use read.table, # but just reads the file as text lines. However, the column # version could be useful when symbols should be replaced only # in specific columns. # Note that Example 2 writes the output with quotes, but this is # not a problem for read.table: dat <- read.table('example1_new.csv', header=TRUE, sep='\t', stringsAsFactors=FALSE) ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.