This file contains 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
# Top-level | |
thefuck <- function(e = rlang::last_error()) { | |
stopifnot(rlang::is_call_simple(e$call)) | |
if (grep("^unused argument", e$message)) { | |
fix_unused_arg(e) | |
} | |
# ... more cases | |
} | |
# Internal methods |
This file contains 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
## Setup ---- | |
devtools::load_all(".") | |
library(dplyr) | |
library(tidyr) | |
library(gt) | |
mangle <- function(x) { | |
stringi::stri_sub(x, 1, 2) <- "__" | |
x | |
} |
This file contains 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(rrapply) | |
expr <- y ~ x + (1 || z) | |
lobstr::ast(!!expr) | |
#> █─`~` | |
#> ├─y | |
#> └─█─`+` | |
#> ├─x | |
#> └─█─`(` | |
#> └─█─`||` | |
#> ├─1 |
This file contains 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
# The reprex | |
library(ggplot2) | |
data <- tibble::tribble( | |
~x, ~group, ~y, ~measure, ~base, | |
"FY18", "aaa", 0.5603448, 260, 464, | |
"FY15", "aaa", 0.5081269, 1313, 2584, | |
"FY19", "aaa", 0.5799373, 185, 319, | |
"FY16", "aaa", 0.5225225, 580, 1110, | |
"FY13", "aaa", 0.4779116, 595, 1245, | |
"FY17", "aaa", 0.5502471, 334, 607, |
This file contains 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
lobstr::ast(T ? F : 1) | |
`%?%` <- function(e1, e2) { | |
e2_expr <- substitute(e2) | |
if (e1) { | |
return(eval.parent(e2_expr[[2]])) | |
} else { | |
return(eval.parent(e2_expr[[3]])) | |
} | |
} |
This file contains 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
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 |
This file contains 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(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'))]") |
This file contains 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
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 |
This file contains 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(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 |
This file contains 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
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'] |
NewerOlder