This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| divide_by_two <- function(x, call. = FALSE) { | |
| if(!is.numeric(x)) { | |
| stop("IT'S NOT NUMERIC", call. = call.) | |
| } else { | |
| x/2 | |
| } | |
| } | |
| divide_by_two(2) | |
| #> [1] 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(testthat) | |
| library(dplyr, warn.conflicts = FALSE) | |
| # expect_equal() returns silently if they're the same | |
| expect_equal(iris, iris) | |
| # but with an error if they're not | |
| expect_equal(iris, mtcars) | |
| #> Error: `iris` not equal to `mtcars`. | |
| #> Names: 5 string mismatches |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyr) | |
| df <- tribble( | |
| ~Date, ~Fruit, ~Sold, | |
| "2020-02-01", "Apple", 5, | |
| "2020-02-01", "Banana", 1, | |
| "2020-02-02", "Apple", 2 | |
| ) | |
| df_complete <- df %>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(dplyr) | |
| library(tidytext) | |
| nintendo <- tribble( | |
| ~console, ~sales_type, ~sales_million, | |
| "Nintendo Switch", "Hardware", 52.48, | |
| "Nintendo Switch", "Software", 310.65, | |
| "Nintendo 3DS", "Hardware", 75.71, | |
| "Nintendo 3DS", "Software", 382.22, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyr) | |
| library(dplyr) | |
| library(forcats) | |
| library(purrr) | |
| library(magick) | |
| items <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-05-05/items.csv") | |
| flowers <- items %>% | |
| filter(category == "Flowers") %>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(gt) | |
| library(tibble) | |
| acnh_bugs_n <- tribble( | |
| ~name, ~price, ~location, ~time, ~months, ~image, | |
| "Yellow butterfly", 160, "Flying", "4 AM - 7 PM", "Mar - Jun, Sep - Oct", "https://vignette.wikia.nocookie.net/animalcrossing/images/f/fa/NH-Icon-yellowbutterfly.png", | |
| "Peacock butterfly", 2500, "Flying by Hybrid Flowers", "4 AM - 7 PM", "Mar - June", "https://vignette.wikia.nocookie.net/animalcrossing/images/8/8f/NH-Icon-peacockbutterfly.png", | |
| "Atlas moth", 3000, "On Trees", "7 PM - 4 AM", "Apr - Sep", "https://vignette.wikia.nocookie.net/animalcrossing/images/6/6a/NH-Icon-atlasmoth.png", | |
| "Centipede", 300, "Hitting Rocks", "4 PM - 11 PM", "Sep - June", "https://vignette.wikia.nocookie.net/animalcrossing/images/3/30/NH-Icon-centipede.png", | |
| "Snail", 250, "On Rocks and Bushes (Rain) ", "All Day", "Jan - Dec", "https://vignette.wikia.nocookie.net/animalcrossing/images/b/b1/NH-Icon-snail.png", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(rtweet) | |
| library(dplyr) | |
| library(tidytext) | |
| library(stringr) | |
| library(ggplot2) | |
| library(ggwordcloud) | |
| dc <- search_tweets( | |
| "datacamp", | |
| n = 1000, include_rts = FALSE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggkeyboard) | |
| library(ggplot2) | |
| extrafont::loadfonts() | |
| # More adventurous | |
| ggkeyboard(tkl, | |
| palette = c( | |
| background = "#FFFFFF", | |
| keyboard = "#272530", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(dplyr) | |
| library(tidyr) | |
| initial <- tibble( | |
| name = c("name_1", "name_2"), | |
| value = list( | |
| tibble(name = c("subname_1", "subname_2"), value = c(1, 2)), | |
| tibble(name = c("subname_3", "subname_4"), value = c(3, 4)) | |
| ) | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(tibble) | |
| df <- tribble( | |
| ~x, ~y, ~label, | |
| 1, 2, "A super long label oh god how am I going to deal with this", | |
| 2, 1, "A shorter one" | |
| ) | |
| # Default - text is cut off |