Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture output of data

Tags:

r

I want to capture the output from the data function in which you supply a package name and the function produces a static output. I want to turn this into a dataframe.

Currently the following gives the static output:

data(package = "ggplot2")

I'd like it to be as a dataframe and actually never have the external static output produced.

diamonds                Prices of 50,000 round cut diamonds
economics               US economic time series.
midwest                 Midwest demographics.
movies                  Movie information and user ratings from IMDB.com.
mpg                     Fuel economy data from 1999 and 2008 for 38 popular models of car
msleep                  An updated and expanded version of the mammals sleep dataset.
presidential            Terms of 10 presidents from Eisenhower to Bush W.
seals                   Vector field of seal movements.
like image 469
Tyler Rinker Avatar asked Mar 03 '13 06:03

Tyler Rinker


People also ask

What is capture output?

output: Send Output to a Character String or File.

How do I save output to a File in R?

You can also save the entire R console screen within the GUI by clicking on "Save to File..." under the menu "File." This saves the commands and the output to a text file, exactly as you see them on the screen.


1 Answers

Is this enough to get you started?

> data(package = "ggplot2")$results
     Package   LibPath                  Item          
[1,] "ggplot2" "/home/mrdwab/R/library" "diamonds"    
[2,] "ggplot2" "/home/mrdwab/R/library" "economics"   
[3,] "ggplot2" "/home/mrdwab/R/library" "midwest"     
[4,] "ggplot2" "/home/mrdwab/R/library" "movies"      
[5,] "ggplot2" "/home/mrdwab/R/library" "mpg"         
[6,] "ggplot2" "/home/mrdwab/R/library" "msleep"      
[7,] "ggplot2" "/home/mrdwab/R/library" "presidential"
[8,] "ggplot2" "/home/mrdwab/R/library" "seals"       
     Title                                                              
[1,] "Prices of 50,000 round cut diamonds"                              
[2,] "US economic time series."                                         
[3,] "Midwest demographics."                                            
[4,] "Movie information and user ratings from IMDB.com."                
[5,] "Fuel economy data from 1999 and 2008 for 38 popular models of car"
[6,] "An updated and expanded version of the mammals sleep dataset."    
[7,] "Terms of 10 presidents from Eisenhower to Bush W."                
[8,] "Vector field of seal movements."    

Obviously, to get a data.frame of just the "Item" and "Title" data, you can use:

> data.frame(data(package = "ggplot2")$results)[-c(1, 2)]
          Item                                                             Title
1     diamonds                               Prices of 50,000 round cut diamonds
2    economics                                          US economic time series.
3      midwest                                             Midwest demographics.
4       movies                 Movie information and user ratings from IMDB.com.
5          mpg Fuel economy data from 1999 and 2008 for 38 popular models of car
6       msleep     An updated and expanded version of the mammals sleep dataset.
7 presidential                 Terms of 10 presidents from Eisenhower to Bush W.
8        seals                                   Vector field of seal movements.
like image 181
A5C1D2H2I1M1N2O1R2T1 Avatar answered Sep 22 '22 14:09

A5C1D2H2I1M1N2O1R2T1