"R" write/export dataframe preserving the class information
The best way to achieve this would be to save the data as an R data file using either save() or saveRDS():
# option 1
save(df, file=&quot;data.Rdata&quot;)
load(&quot;data.Rdata&quot;)

# option 2
saveRDS(df, file=&quot;data2.Rds&quot;)
df &lt;- readRDS(&quot;data2.Rds&quot;)