[Maturing]

as_tibble() turns an existing object, such as a data frame or matrix, into a so-called tibble, a data frame with class tbl_df. This is in contrast with tibble(), which builds a tibble from individual columns. as_tibble() is to tibble() as base::as.data.frame() is to base::data.frame().

as_tibble() is an S3 generic, with methods for:

[Maturing]

glimpse() is like a transposed version of print(): columns run down the page, and data runs across. This makes it possible to see every column in a data frame. It's a little like str() applied to a data frame but it tries to show you as much data as possible. (And it always shows the underlying data, even when applied to a remote data source.)

This generic will be moved to pillar, and reexported from there as soon as it becomes available.

Arguments

rownames

How to treat existing row names of a data frame or matrix:

  • NULL: remove row names. This is the default.

  • NA: keep row names.

  • A string: the name of a new column. Existing rownames are transferred into this column and the row.names attribute is deleted. Read more in rownames.

.name_repair

see tidyr

For compatibility only, do not use for new code.

x

An object to glimpse at.

width

Width of output: defaults to the setting of the option tibble.width (if finite) or the width of the console.

...

Unused, for extensibility.

Value

A tibble

x original x is (invisibly) returned, allowing glimpse() to be used within a data pipe line.

Row names

The default behavior is to silently remove row names.

New code should explicitly convert row names to a new column using the rownames argument.

For existing code that relies on the retention of row names, call pkgconfig::set_config("tibble::rownames"=NA) in your script or in your package's .onLoad() function.

Life cycle

Using as_tibble() for vectors is superseded as of version 3.0.0, prefer the more expressive maturing as_tibble_row() and as_tibble_col() variants for new code.

S3 methods

glimpse is an S3 generic with a customised method for tbls and data.frames, and a default method that calls str().

See also

tibble() constructs a tibble from individual columns. enframe() converts a named vector to a tibble with a column of names and column of values. Name repair is implemented using vctrs::vec_as_names().

Examples

pbmc_small %>%

    as_tibble()
#> # A tibble: 80 × 31
#>    .cell orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8 letter.idents groups
#>    <chr> <fct>           <dbl>        <int> <fct>           <fct>         <chr> 
#>  1 ATGC… SeuratPro…         70           47 0               A             g2    
#>  2 CATG… SeuratPro…         85           52 0               A             g1    
#>  3 GAAC… SeuratPro…         87           50 1               B             g2    
#>  4 TGAC… SeuratPro…        127           56 0               A             g2    
#>  5 AGTC… SeuratPro…        173           53 0               A             g2    
#>  6 TCTG… SeuratPro…         70           48 0               A             g1    
#>  7 TGGT… SeuratPro…         64           36 0               A             g1    
#>  8 GCAG… SeuratPro…         72           45 0               A             g1    
#>  9 GATA… SeuratPro…         52           36 0               A             g1    
#> 10 AATG… SeuratPro…        100           41 0               A             g1    
#> # ℹ 70 more rows
#> # ℹ 24 more variables: RNA_snn_res.1 <fct>, file <chr>, ident <fct>,
#> #   PC_1 <dbl>, PC_2 <dbl>, PC_3 <dbl>, PC_4 <dbl>, PC_5 <dbl>, PC_6 <dbl>,
#> #   PC_7 <dbl>, PC_8 <dbl>, PC_9 <dbl>, PC_10 <dbl>, PC_11 <dbl>, PC_12 <dbl>,
#> #   PC_13 <dbl>, PC_14 <dbl>, PC_15 <dbl>, PC_16 <dbl>, PC_17 <dbl>,
#> #   PC_18 <dbl>, PC_19 <dbl>, tSNE_1 <dbl>, tSNE_2 <dbl>
pbmc_small %>% tidy %>% glimpse()
#> Warning: `tidy()` was deprecated in tidySingleCellExperiment 1.1.1.
#>  tidySingleCellExperiment says: tidy() is not needed anymore.
#> Formal class 'SingleCellExperiment' [package "SingleCellExperiment"] with 9 slots
#>   ..@ int_elementMetadata:Formal class 'DFrame' [package "S4Vectors"] with 6 slots
#>   ..@ int_colData        :Formal class 'DFrame' [package "S4Vectors"] with 6 slots
#>   ..@ int_metadata       :List of 3
#>   .. ..$ version          :Classes 'package_version', 'numeric_version'  hidden list of 1
#>   .. ..$ spike_names      : chr(0) 
#>   .. ..$ size_factor_names: chr(0) 
#>   ..@ rowRanges          :Formal class 'CompressedGRangesList' [package "GenomicRanges"] with 5 slots
#>   ..@ colData            :Formal class 'DFrame' [package "S4Vectors"] with 6 slots
#>   ..@ assays             :Formal class 'SimpleAssays' [package "SummarizedExperiment"] with 1 slot
#>   ..@ NAMES              : NULL
#>   ..@ elementMetadata    :Formal class 'DFrame' [package "S4Vectors"] with 6 slots
#>   ..@ metadata           : list()