Archive

Posts Tagged ‘datasets’

Dump R datasets into a single file

Should you need datasets that come with R and additional packages (you can access them via data()) in one single file, here’s what I did to dump the entire workspace into one file:


rm(list=ls())
data(list = data()$results[, 3])  # put datasets into your global environment
sink("datasets.txt")
for (i in 1:length(ls())) {
 cat("*****************", "\n")
 print(ls()[i])
 cat("*****************", "\n")
 print(get(ls()[i]))
 cat("\n")
}
sink()

This code can easily be adapted to dump individual dataset into its own file.

Advertisements
Categories: Uncategorized Tags: ,