Reputation: 1675
I'm looking for a better way to view output of the data frame in the console.
The computer that I'm using has high security restrictions, so installing many of the more popular packages such as tidyr
and tibble
is not possible.
What I want is for the ouput to be more compact and not wrap in the console.
Is there a way to use base R to improve the console output for data frames?
Upvotes: 2
Views: 1262
Reputation: 1278
Would str()
from the base package work for you?
> str(iris)
'data.frame': 150 obs. of 5 variables:
$ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
$ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
$ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
$ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
$ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
I realize that you can't install tidy packages, but for others who may read this, the formatting provided by pillar::glimpse()
is perhaps a bit more compact and readable:
> pillar::glimpse(iris)
Rows: 150
Columns: 5
$ Sepal.Length <dbl> 5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9, 5.4, 4.8, 4.8…
$ Sepal.Width <dbl> 3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3.4, 3.0…
$ Petal.Length <dbl> 1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 1.4, 1.5, 1.4, 1.5, 1.5, 1.6, 1.4…
$ Petal.Width <dbl> 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1, 0.2, 0.2, 0.1…
$ Species <fct> setosa, setosa, setosa, setosa, setosa, setosa, setosa, setosa,…
glimpse()
is also re-exported by dplyr
. You can call it as dplyr::glimpse()
or:
library(dplyr)
glimpse(iris)
Upvotes: 0
Reputation: 16035
You could edit
your data.frame without changing it. It will open a new window for you to see. There is an editor
parameter which allows to choose an editor of your choise.
Or you could page through the data:
page(mtcars, method = "print")
Upvotes: 2