Description Usage Arguments Author(s) Examples
Replacing separators (for example, decimal and thousand separators).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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
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 27 28 29 30 31 32 | ## 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.