For some weird reason, RStudio is showing me all columns of a data.frame when I use the View() function or when I click on a data frame in the environment pane. I installed a new version of R three weeks ago (because I have a new Windows10 laptop) and since then I am running into this problem.
This is really annoying because R becomes super slow when having to display more than 100 columns. Random example of code
a=data.frame(replicate(1000,sample(0:1,10,rep=TRUE)))
View(a)
In the good old days, only the first 100 columns were displayed...
Any ideas on how to change this back to normal?
I have this problem with long dataframes of > 300000 rows. The RStudio session will freeze if I View()
the df. Unfortunately I often use View()
to check my results but I often forget to make sure the df isn't too large. To prevent this I have written a function as recommended in the comments above. I spent a bit of time figuring out how to get the name to show up like with View()
so I thought I would share it.
RStudioView <- View
View <- function(x) {
name <- deparse(substitute(x))
if ("data.frame" %in% class(x)) {
RStudioView(x[1:1000,], name)
} else {
RStudioView(x)
}
}
Based on a function found here. You could just change it to limit columns instead of rows and set whatever cutoff works best for you.