Home > Uncategorized > Dump R datasets into a single file

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.

About these ads
Categories: Uncategorized Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: