I've mostly used head(), tail(), and View() to look at tables in R, but I wonder if anyone uses anything more sophisticated. I recall reading that there were R <-> Excel interfaces available (based on COM or XLLoop?) - does anyone use one to use Excel (or OpenOffice) to display data frames during an R session, and not necessarily just result the final result exported to a csv file?
Edit: Thanks for all the suggestions. I guess I should have specified that I was running 开发者_StackOverflowEmacs+ESS on a Mac primarily (which disqualifies COM and Deducer), though I also switch to Linux and Windows on occasion. I guess View() still is the best multi-platform solution that I could find...
You can use the basic data editor to view the data
edit(your.data.frame)
You can run utils::View(data)
.
Another option would be to open a new RStudio window. One can do this (on linux at least) simply by running in the terminal : rstudio If one wants to be able to close the terminal afterwards, just run
nohup rstudio &
Yes, I sometimes use Excel to view data from R during a session. I recommend looking at this blog post on the Learning R blog. I use the RDCOMClient; it allows for more than just export/import, but the trade-off is added complexity.
Edit: There are several other solutions that are non-COM based in that blog post, including using ODBC.
Another elegant option would be to use the DT package
if (!require("DT")) devtools::install_github("rstudio/DT")
datatable(iris)
This will open a paginated, sortable and filterable table in your browser. See http://rstudio.github.io/DT/ for examples.
I use the following function to look at a sample of lines from a dataframe... I keep it in my startup and use it all the time to run checks... frequently I'll run this a couple of times...
#
# sample a couple of lines from a data frame
#
sample.df <- function(df, n=3, ordered=TRUE) {
if(ordered) {
df[sort(sample(nrow(df), min(nrow(df), n))),]
} else {
df[sample(nrow(df), min(nrow(df), n)),]
}
}
Deducer's Data Viewer.
Form the manual:
The data viewer can be accessed using either deducer("Data viewer") or the data.viewer() function
There are many other useful features there, all of them available from command interface.
fix
works for me
also my.df[seq(1, nrow(my.df), nrow(my.df)/30),]
As edit
is too basic, I tend to just open tables in Excel while using R. To do so I write the data to a temporary file, and open it with Excel:
open_in_excel <- function(some_df){
tFile<-tempfile(fileext=paste0(substitute(some_df), ".tsv"),tmpdir="~/tmp")
write.table(some_df, tFile, row.names=F, sep="\t", quote=F)
system(paste('open -a \"/Applications//Microsoft Office 2011/Microsoft Excel.app\"', tFile))
}
open_in_excel(iris)
For sure the system
call needs to be adjusted to the used OS and the installation path of Excel.
精彩评论