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(tidyverse) | |
| library(gt) | |
| library(gtExtras) | |
| some_vals <- tibble::tibble(variable = names(mtcars)) %>% | |
| dplyr::mutate( | |
| class = purrr::map_chr(mtcars, typeof)) |> | |
| pivot_wider(names_from = variable, values_from = class) | |
| head(mtcars) |> |
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(gtExtras) | |
| library(dplyr) | |
| #> | |
| #> Attaching package: 'dplyr' | |
| #> The following objects are masked from 'package:stats': | |
| #> | |
| #> filter, lag | |
| #> The following objects are masked from 'package:base': |
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(readr) | |
| library(janitor) | |
| #> | |
| #> Attaching package: 'janitor' | |
| #> The following objects are masked from 'package:stats': | |
| #> | |
| #> chisq.test, fisher.test | |
| write_csv(mtcars, "mtcars.csv") |
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
| ``` r | |
| library(gt) | |
| test_tab <- head(mtcars) |> | |
| gt() |> | |
| text_transform( | |
| locations = cells_body(cyl), | |
| fn = function(x){ | |
| purrr::map(x, ~gtExtras::add_text_img( | |
| .x, |
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
| ``` r | |
| library(dplyr,w=F) | |
| mtcars |> | |
| group_by(cyl) |> | |
| summarize( | |
| mean_mpg = mean(mpg), | |
| mean_man_mpg = mean(mpg[am == 0]), | |
| mean_auto_mpg = mean(mpg[am == 1]) | |
| ) | |
| #> # A tibble: 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
| ``` r | |
| library(dplyr,w=F) | |
| mtcars |> | |
| group_by(cyl) |> | |
| summarize( | |
| mean_mpg = mean(mpg), | |
| mean_man_mpg = mean(mpg[am == 0]), | |
| mean_auto_mpg = mean(mpg[am == 1]) | |
| ) | |
| #> # A tibble: 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
| ``` r | |
| library(gtExtras) | |
| all_fns <- lsf.str("package:gtExtras") |> | |
| tibble::tibble(fn_name = _) |> | |
| dplyr::mutate(fn_id = dplyr::row_number()) |> | |
| dplyr::rowwise() |> | |
| dplyr::mutate(args = list(formalArgs(fn_name))) |> | |
| tidyr::unnest_longer(args) |> | |
| dplyr::ungroup() |
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(gtExtras) | |
| all_fns <- lsf.str("package:gtExtras") |> | |
| tibble::tibble(fn_name = _) |> | |
| dplyr::mutate(fn_id = dplyr::row_number()) |> | |
| dplyr::rowwise() |> | |
| dplyr::mutate(args = list(formalArgs(fn_name))) |> | |
| tidyr::unnest_longer(args) |> | |
| dplyr::ungroup() |
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(htmltools) | |
| library(gt) | |
| gt_scroll <- function(data, gt_fun){ | |
| # empty table | |
| head_data <- data[0,] | |
| tab_topp <- head_data %>% | |
| # apply user function |
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
| ``` r | |
| library(rvest) | |
| library(tidyverse) | |
| tab_url <- "https://graphics.axios.com/2022-05-16-harris-poll/index.html?initialWidth=469&childId=av-2022-05-16-harris-poll-69AC2&parentTitle=The%202022%20Axios%20Harris%20Poll%20100%20reputation%20rankings&parentUrl=https%3A%2F%2Fwww.axios.com%2F2022%2F05%2F24%2F2022-axios-harris-poll-100-rankings" | |
| tab_js <- "https://graphics.axios.com/2022-05-16-harris-poll/js/app.57adf1a5a55662f9bc9f.min.js?57adf1a5a55662f9bc9f" | |
| raw_txt <- readLines(tab_js) | |
| #> Warning in readLines(tab_js): incomplete final line found on 'https:// | |
| #> graphics.axios.com/2022-05-16-harris-poll/js/app.57adf1a5a55662f9bc9f.min.js? |