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.
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().
Returns
A character string containing the name of the output file (invisibly).
Examples
## For demo, a temp. file path is created with the file extension .dta (Stata)dta_file <- tempfile(fileext =".dta")## .csvcsv_file <- tempfile(fileext =".csv")## .xlsxxlsx_file <- tempfile(fileext =".xlsx")## Create a Stata data fileexport(mtcars, dta_file)## convert Stata to CSV and open converted fileconvert(dta_file, csv_file)import(csv_file)## correct an erroneous file formatexport(mtcars, xlsx_file, format ="tsv")## DON'T DO THIS## import(xlsx_file) ## ERROR## convert the file by specifying `in_opts`convert(xlsx_file, xlsx_file, in_opts = list(format ="tsv"))import(xlsx_file)## convert from the command line:## Rscript -e "rio::convert('mtcars.dta', 'mtcars.csv')"
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.