## For demo, a temp. file path is created with the file extension .dta (Stata)
dta_file <- tempfile(fileext = ".dta")
## .csv
csv_file <- tempfile(fileext = ".csv")
## .xlsx
xlsx_file <- tempfile(fileext = ".xlsx")
## Create a Stata data file
export(mtcars, dta_file)
## convert Stata to CSV and open converted file
convert(dta_file, csv_file)
import(csv_file)
## correct an erroneous file format
export(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')"
Run the code above in your browser using DataLab