Skip to content

Instantly share code, notes, and snippets.

View yjunechoe's full-sized avatar
🐣

June Choe yjunechoe

🐣
View GitHub Profile
order_by_name <- function(x) {
x[order(names(x))]
}
type_to_collector <- function(type) {
# Code adopted from `readr:::collector_find()`
get(paste0("col_", type), envir = asNamespace("readr"))
}
specs_to_list <- function(specs) {
if (inherits(specs, "col_spec")) {
specs <- specs$cols
@yjunechoe
yjunechoe / pkgdown-source-srcset.R
Created February 20, 2024 15:10
redirect <source> relpaths
library(xml2)
x <- read_html('
<picture>
<source media="(prefers-color-scheme: dark)" srcset="man/figures/README-/setup-io-dark.svg">
<img src="man/figures/README-/setup-io.svg" style="display: block; margin: auto;" />
</picture>
')
img_src <- xml_find_all(x, ".//img[not(starts-with(@src, 'http'))]")
source_srcset <- xml_find_all(x, ".//source[not(starts-with(@srcset, 'http'))]")
subj word condition accuracy RT
S01 blue match 1 400
S01 blue mismatch 1 549
S01 green match 1 576
S01 green mismatch 1 406
S01 red match 1 296
S01 red mismatch 1 231
S01 yellow match 1 433
S01 yellow mismatch 0 1548
S02 blue match 1 561
@yjunechoe
yjunechoe / chromote_rvest.R
Created January 24, 2024 02:22
chromote + rvest
library(rvest)
library(chromote)
# Open page in headless chrome
url <- "https://www.kulturdirektoratet.no/web/guest/stotteordning/-/vis/digitalisering-mangfold-dialog-samarbeid/tildelinger"
b <- ChromoteSession$new()
b$Page$navigate(url, wait_ = TRUE); Sys.sleep(3)
# Get document
rootnode <- b$DOM$getDocument()$root$nodeId
@yjunechoe
yjunechoe / sprintf_fmt_bottom_linter.R
Last active September 30, 2023 18:31
Linter to check that the `fmt` argument of `sprintf()` comes last
sprintf_fmt_bottom_linter <- function() {
xpath <- "
//SYMBOL_FUNCTION_CALL[text() = 'sprintf']
/parent::expr/following-sibling::expr[last()]
/preceding-sibling::*[2][not(
self::SYMBOL_SUB[text() = 'f' or text() = 'fm' or text() = 'fmt']
)]
/preceding-sibling::expr[
preceding-sibling::*[2][
self::SYMBOL_SUB[text() = 'f' or text() = 'fm' or text() = 'fmt']
@yjunechoe
yjunechoe / gt_camcorder.R
Last active July 28, 2023 16:50
Make {camcorder} work for {gt}
# gt-camcorder prototype using examples from {gt} vignette
# -- https://gt.rstudio.com/articles/creating-summary-lines.html
library(devtools)
dev_mode(on = TRUE)
# Install my fork in dev-mode with gt camcorder draft
remotes::install_github("yjunechoe/camcorder@gt-support")
library(camcorder)
@yjunechoe
yjunechoe / quarto-arquero-interactive-grouped.qmd
Created June 22, 2023 12:33
Example of interactive grouped summary in Quarto using Arquero
---
title: "Interactive aggregation"
format: html
editor: visual
---
## Define data
```{r}
ojs_define(mydata = palmerpenguins::penguins)
@yjunechoe
yjunechoe / quarto-gt-incremental-rows
Created March 28, 2023 15:23
Incremental presentation of {gt} html table rows in Quarto slides
---
title: "incremental table"
format: revealjs
editor: visual
---
## Make `{gt}` table
```{css}
table.gt_table {
@yjunechoe
yjunechoe / shinyTree_nested_select.R
Created January 13, 2023 03:56
Minimal nested select input with {shinyTree}
library(shiny)
library(shinyTree)
library(highcharter)
library(dplyr)
pokemon_df <- highcharter::pokemon |>
select(primary = type_1, secondary = type_2, pokemon) |>
mutate(secondary = coalesce(secondary, primary))
pokemon_list <- shinyTree::dfToTree(pokemon_df)
@yjunechoe
yjunechoe / rselenium-boxscroll.R
Created November 16, 2022 18:56
RSelenium script to simulate scrolling of a pop-up box to the end, using twitter app reviews on google play store as example
library(RSelenium)
# Google play store page for twitter app
url <- "https://play.google.com/store/apps/details?id=com.twitter.android"
# RSelenium firefox browser setup
driver <- rsDriver(browser = 'firefox', verbose = FALSE, port = 123L)
session <- driver$client
session$open()