add_tibble_to_list | R Documentation |
This function prepends tibbles to a list, creating the list in the environment calling this function if not already present.
add_tibble_to_list(.data, .name)
.data |
The tibble to be added to the beginning of the list. |
.name |
The name of the tibble to be added to the beginning of the list. |
Adding a tibble to a list is an example of assigning a variable to an environment.
The tibble is returned invisibly so that the function may be used within a pipe workflow.
suppressPackageStartupMessages({
suppressWarnings({
library(palmerpenguins)
library(dplyr)
})
})
# select top 5 heaviest penguins from each species on each island
heaviest_penguins <- penguins %>%
select(species, island, body_mass_g) %>%
group_by(species, island) %>%
arrange(desc(body_mass_g)) %>%
slice_head(n = 5) %>%
ungroup()
heaviest_penguins
# prepend heaviest penguin species tibble to list
suppressPackageStartupMessages({
suppressWarnings({
library(forcats)
})
})
heaviest_penguins %>%
filter(species == "Adelie") %>%
mutate(species = fct_drop(species)) %>%
add_tibble_to_list("adelie")
heaviest_penguins %>%
filter(species == "Chinstrap") %>%
mutate(species = fct_drop(species)) %>%
add_tibble_to_list("chinstrap")
heaviest_penguins %>%
filter(species == "Gentoo") %>%
mutate(species = fct_drop(species)) %>%
add_tibble_to_list("gentoo")
str(tibble_list, max.level = 1, list.len = 3)
# convert list to tibble
bind_rows(tibble_list)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.