"R" write/export dataframe preserving the class information Short Question

After formatting a dataframe in R with class information like &quot;Date&quot;, &quot;Factor&quot;, and etc. how to save the dataframe while preserving the class information. Consequently how to load the information back to a new R Project with preserving the above class information.

Long Question
I have created following dataframe with class information,
names &lt;- c(&quot;Adrew&quot;, &quot;Vikie&quot;, &quot;Penny&quot;, &quot;Samantha&quot;) 
date &lt;- as.Date(c(&quot;1984-12-28&quot;, &quot;1986-10-18&quot;, &quot;1986-11-30&quot;, &quot;1987-11-30&quot;))
gender &lt;- c(&quot;M&quot;, &quot;M&quot;, &quot;S&quot;, &quot;S&quot;)

df &lt;- data.frame(names, date, gender)

df$gender &lt;- factor(df$gender,
                   levels = c(&quot;M&quot;, &quot;S&quot;), 
                   labels = c(1,2), 
                   order = FALSE)


and the classes are factor, date, factor
method 01
then write the dataframe in csv format and read it
write.csv(df, &quot;df.csv&quot;)
dfcsv &lt;- read.csv(&quot;df.csv&quot;)


and the daraframe classes are changed
method 02
then tried to write the file using table export method
write.table(df, &quot;df.R&quot;)
dftable &lt;- read.table(&quot;df.R&quot;)


again the data frame classes had been changed
Question

is there a proper method to write or save a data frame with preserving the class information like date, factor, etc information intact, and conversely how to load it back.
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;)