csv {fritools2} | R Documentation |
Read and Write a Comma Separated File
Description
Functions to read and write CSV files. The objects returned by these
functions are data.frames
with the following attributes:
- path
The path to the file on disk.
- csv
The type of CSV: either
standard
orgerman
.- hash
The hash value computed with digest's digest function, if digest is installed.
read_csv
is a wrapper to determine whether to use
utils:read.csv2
or
utils:read.csv
.
It sets the above three arguments.
write_csv
compares the hash
value stored in the object's
attribute
with the objects current hash value. If they differ, it writes the object to
the file
argument or, if not given, to the path
stored in the object's attribute. If no csv_type
is given, it uses
the csv
type stored in object's attribute.
If digest is not installed, the object will (unconditionally) be
written to disk.
Usage
read_csv(file, ...)
write_csv(x, file = NULL, csv_type = c(NA, "standard", "german"))
Arguments
file |
The path to the file to be read or written. |
... |
Arguments passed to |
x |
The object to write to disk. |
csv_type |
Which |
Value
For read_csv
: An object read from the file.
For write_csv
: The object with updated hash
(and possibly path
and csv
)
attribute.
See Also
Other CSV functions:
bulk_read_csv()
,
bulk_write_csv()
,
check_ascii_file()
,
csv2csv()
Examples
# read from standard CSV
f <- tempfile()
write.csv(mtcars, file = f)
str(read_csv(f))
f <- tempfile()
write.csv2(mtcars, file = f)
str(read_csv(f))
# write to standard CSV
f <- tempfile()
d <- mtcars
str(d <- write_csv(d, file = f))
file.mtime(f)
Sys.sleep(2) # make sure the mtime would have changed
write_csv(d, file = f)
file.mtime(f)