-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathREADME.Rmd
More file actions
119 lines (88 loc) · 4.24 KB
/
README.Rmd
File metadata and controls
119 lines (88 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
---
output:
github_document:
html_preview: false
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
clean_output <- function(x, options) {
x <- gsub("0x[0-9a-f]+", "0xdeadbeef", x)
x <- gsub("dataframe_[0-9]*_[0-9]*", " dataframe_42_42 ", x)
x <- gsub("[0-9]*\\.___row_number ASC", "42.___row_number ASC", x)
index <- x
index <- gsub("─", "-", index)
index <- strsplit(paste(index, collapse = "\n"), "\n---\n")[[1]][[2]]
writeLines(index, "index.md")
x <- gsub('(`vignette[(]"([^"]+)"[)]`)', "[\\1](https://tibble.tidyverse.org/articles/\\2.html)", x)
x <- fansi::strip_sgr(x)
x
}
options(
cli.num_colors = 256,
cli.width = 71,
width = 71,
pillar.bold = TRUE,
pillar.max_title_chars = 5,
pillar.min_title_chars = 5,
pillar.max_footer_lines = 12,
conflicts.policy = list(warn = FALSE)
)
local({
hook_source <- knitr::knit_hooks$get("document")
knitr::knit_hooks$set(document = clean_output)
})
```
# tibble <img src="man/figures/logo.png" align="right" alt="Hexagonal logo for the R package ‘tibble’, styled with a sci-fi theme. The word ‘TIBBLE’ appears at the top in a futuristic font, and below it is a stylized table with colored bars resembling columns and rows, set against a starry space background." />
<!-- badges: start -->
[](https://github.com/tidyverse/tibble/actions)
[](https://app.codecov.io/gh/tidyverse/tibble?branch=main)
[](https://cran.r-project.org/package=tibble)
[](https://lifecycle.r-lib.org/articles/stages.html)
<!-- badges: end -->
## Overview
A __tibble__, or `tbl_df`, is a modern reimagining of the data.frame, keeping what time has proven to be effective, and throwing out what is not. Tibbles are data.frames that are lazy and surly: they do less (i.e. they don't change variable names or types, and don't do partial matching) and complain more (e.g. when a variable does not exist). This forces you to confront problems earlier, typically leading to cleaner, more expressive code. Tibbles also have an enhanced `print()` method which makes them easier to use with large datasets containing complex objects.
If you are new to tibbles, the best place to start is the [tibbles chapter](https://r4ds.had.co.nz/tibbles.html) in *R for data science*.
## Installation
```{r, eval = FALSE}
# The easiest way to get tibble is to install the whole tidyverse:
install.packages("tidyverse")
# Alternatively, install just tibble:
install.packages("tibble")
# Or the the development version from GitHub:
# install.packages("pak")
pak::pak("tidyverse/tibble")
```
## Usage
```{r}
library(tibble)
```
Create a tibble from an existing object with `as_tibble()`:
```{r}
data <- data.frame(a = 1:3, b = letters[1:3], c = Sys.Date() - 1:3)
data
as_tibble(data)
```
This will work for reasonable inputs that are already data.frames, lists, matrices, or tables.
You can also create a new tibble from column vectors with `tibble()`:
```{r}
tibble(x = 1:5, y = 1, z = x^2 + y)
```
`tibble()` does much less than `data.frame()`: it never changes the type of the inputs (e.g. it keeps list columns as is), it never changes the names of variables, it only recycles inputs of length 1, and it never creates `row.names()`. You can read more about these features in `vignette("tibble")`.
You can define a tibble row-by-row with `tribble()`:
```{r}
tribble(
~x, ~y, ~z,
"a", 2, 3.6,
"b", 1, 8.5
)
```
## Related work
The tibble print method draws inspiration from [data.table](https://rdatatable.gitlab.io/data.table), and [frame](https://github.com/patperry/r-frame). Like `data.table::data.table()`, `tibble()` doesn't change column names and doesn't use rownames.
---
## Code of Conduct
Please note that the tibble project is released with a [Contributor Code of Conduct](https://tibble.tidyverse.org/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.