R View() Does Not Display All Columns of Data Frame

R View() does not display all columns of data frame

I also see this problem with x <- matrix(1:200,nrow=1); View(x) in RStudio, but not in vanilla R. It is a known limitation and they're working on it. You can contact the devs on their forum to give your feedback (and have done so, I see).

View function showing all columns - makes R really slow

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.

R expand view to see all columns

To see the columns 30:35

View(dataframe[30:35])

To see the columns 30 and 35

View(dataframe[c(30,35)])

Rstudio show only the first 50 columns

I do not believe you can increase the number of columns to view at a time. But you can click the little arrow at the top to scroll across to more columns.

Sample Image

I'm using RStudio 1.2.1335 and not sure which version of RStudio first implemented this feature.

Overriding Variables not shown in dplyr, to display all columns from df

There's (now) a way of overriding the width of columns that gets printed out. If you run this command all will be well

options(dplyr.width = Inf)

I wrote it up here.

hist() not showing all columns

I wonder how you could at all use hist in a data frame without Vectorizeing it. Best would be you use a different device such as the png.

png('foo.png', 2560, 1440)
par(mfrow=c(12, 11))
Vectorize(hist)(df)
dev.off()

Sample Image

Update

We can get nice titles and labels with nobs and missings using lapply and a misfun for convenience.

misfun <- \(z) paste(
paste(c('n', 'm'), table(factor(as.double(is.na(z)), levels=0:1)), sep=':'),
collapse=' ')

png('foo2.png', 2560, 1440)
par(mfrow=c(12, 11))
lapply(names(df), \(x) hist(df[[x]], main=x, xlab=misfun(df[x])))
dev.off()

Sample Image


Data:

df <- read.table("https://leicester.figshare.com/ndownloader/files/23581310", sep = ",", header = TRUE, stringsAsFactors = FALSE)

Viewing single column of data frame in R

View(data5[1:100,1, drop=FALSE])

When you access a single column of a data frame it is converted to a vector, drop=FALSE prevents that and retains the column name.

For instance:

> df
n s b
1 2 aa TRUE
2 3 bb TRUE
3 5 cc TRUE
> df[, 1]
[1] 2 3 5
> df[, 1, drop=FALSE]
n
1 2
2 3
3 5


Related Topics



Leave a reply



Submit