Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

convert

Convert from one file format to another


Description

This function constructs a data frame from a data file using import and uses export to write the data to disk in the format indicated by the file extension.

Usage

convert(in_file, out_file, in_opts = list(), out_opts = list())

Arguments

in_file

A character string naming an input file.

out_file

A character string naming an output file.

in_opts

A named list of options to be passed to import.

out_opts

A named list of options to be passed to export.

Value

A character string containing the name of the output file (invisibly).

See Also

Luca Braglia has created a Shiny app called rioweb that provides access to the file conversion features of rio through a web browser.

Examples

# create a file to convert
export(mtcars, "mtcars.dta")

# convert Stata to CSV and open converted file
convert("mtcars.dta", "mtcars.csv")
head(import("mtcars.csv"))

# correct an erroneous file format
export(mtcars, "mtcars.csv", format = "tsv")
convert("mtcars.csv", "mtcars.csv", in_opts = list(format = "tsv"))

# convert serialized R data.frame to JSON
export(mtcars, "mtcars.rds")
convert("mtcars.rds", "mtcars.json")

# cleanup
unlink("mtcars.csv")
unlink("mtcars.dta")
unlink("mtcars.rds")
unlink("mtcars.json")

## Not run: \donttest{
# convert from the command line:
## Rscript -e "rio::convert('mtcars.dta', 'mtcars.csv')"
}
## End(Not run)

rio

A Swiss-Army Knife for Data I/O

v0.5.26
GPL-2
Authors
Jason Becker [ctb], Chung-hong Chan [aut], Geoffrey CH Chan [ctb], Thomas J. Leeper [aut, cre] (<https://orcid.org/0000-0003-4097-6326>), Christopher Gandrud [ctb], Andrew MacDonald [ctb], Ista Zahn [ctb], Stanislaus Stadlmann [ctb], Ruaridh Williamson [ctb], Patrick Kennedy [ctb], Ryan Price [ctb], Trevor L Davis [ctb], Nathan Day [ctb], Bill Denney [ctb] (<https://orcid.org/0000-0002-5759-428X>), Alex Bokov [ctb] (<https://orcid.org/0000-0002-0511-9815>)
Initial release
2021-02-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.