| read_data | R Documentation |
read_data() reads tabular data from many formats commonly used in data
science (see supported_formats()) and returns a plain data.frame. The
format is inferred from the file extension unless format is given.
If path is a directory (for example as written by generate_to_file()),
all files in it with a recognised extension are read and row-bound.
Because text formats (CSV, JSON, Excel) do not store column types, a
template data frame can be supplied: columns are then coerced to the
classes of the template (factor levels, Date, POSIXct, integer, ...)
with match_types().
read_data(
path,
format = NULL,
template = NULL,
object = NULL,
dataset = "data",
sheet = 1L,
...
)
path |
File or directory path. |
format |
Optional format name or extension, e.g. |
template |
Optional data frame whose column classes are imposed on the result. |
object |
For |
dataset |
For |
sheet |
For Excel files: sheet name or number. |
... |
Further arguments passed to the backend reader. |
A data.frame.
write_data(), supported_formats(), match_types()
f <- tempfile(fileext = ".csv")
write_data(iris, f)
x <- read_data(f, template = iris)
str(x)
f2 <- tempfile(fileext = ".rds")
write_data(iris, f2)
identical(read_data(f2), iris)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.