xls2csv {climatol} | R Documentation |
Join all data in *.xls or *.xlsx files into a single CSV file
Description
This function reads all *.xls or *.xlsx files contained in a directory and dumps their data into a single CSV file.
Usage
xls2csv(tmpdir, archdir, var, datcols=1:4, codesep='-', dec='.', sep=',')
Arguments
tmpdir |
temporal directory containing the files to read. |
archdir |
directory where to archive files after processing. |
var |
destination name of the variable. |
datcols |
data columns to be written to the output file. |
codesep |
character string separating the code from the rest of the file name ( |
dec |
character to use as decimal point in the output file ( |
sep |
character separating data in the output file ( |
Details
File names must begin with their station code, which may optionally be followed by a hyphen ('-') or other code separator character (specified with the parameter codesep
) and the name of the station or other characters.
File contents must have one header line at the top. If they contain more, supplementary header lines should have at least one empty cell in the columns of date and data to be read.
After their data have been dumped into the output xls_*_data.csv
file, original files are moved to the archdir
directory.
Note that data are appended to the output CSV files every time you run this function putting new files in the tmpdir
directory.
Code and station names (if included in the file names) are appended to xls_*_stations.csv
.
climatol
input files can then be obtained from both output
xls_*.csv
files with the csv2climatol
function.
See Also
Examples
## Set a temporal working directory:
wd <- tempdir()
wd0 <- setwd(wd)
## Create origin and destination directories and copy example input files:
dir.create('dir1'); dir.create('dir2')
file.copy(exampleFiles('p064.xlsx'),'dir1')
file.copy(exampleFiles('p082.xlsx'),'dir1')
file.copy(exampleFiles('p084.xlsx'),'dir1')
## Now run the example:
xls2csv('dir1','dir2','TN',datcols=c(1:3,6))
## Return to user's working directory:
setwd(wd0)
## Input and output files can be found in the directory:
print(wd)