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(tidyverse) | |
vec_slice2 <- function(x, i) { | |
if (!is.data.frame(x)) { | |
return(.subset2(x, i)) | |
} | |
# FIXME: Other special cases? | |
row <- vctrs::vec_slice(x, i) | |
lists <- map_lgl(row, ~ is.list(.x) && !is.data.frame(.x)) | |
length_one_elements <- map_lgl( |
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
pak::pak("duckdb/duckdb-r") | |
#> ! Using bundled GitHub PAT. Please add your own PAT using `gitcreds::gitcreds_set()`. | |
#> | |
#> ✔ Updated metadata database: 4.81 MB in 4 files. | |
#> | |
#> ℹ Updating metadata database | |
#> ✔ Updating metadata database ... done | |
#> | |
#> | |
#> → Will update 1 package. |
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
facepalm <- "\U1F926" | |
fitzpatrick_3 <- "\U1F3FC" | |
zero_width_joiner <- "\U200D" | |
male <- "\U2642" | |
my_facepalm <- paste0(facepalm, fitzpatrick_3, zero_width_joiner, male) | |
my_facepalm | |
#> [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
usethis::use_standalone("cynkra/dm", "standalone-check_suggested.R") | |
#> ✔ Setting active project to '/Users/kirill/git/R/fledge' | |
#> ✔ Writing 'R/import-standalone-check_suggested.R' |
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
my_fun <- function() { | |
rlang::local_interactive() | |
rlang::check_installed(c("DiagrammeR (>= 1.0.9)", "DiagrammeRsvg")) | |
stopifnot(requireNamespace("DiagrammeR", quietly = TRUE)) | |
stopifnot(requireNamespace("DiagrammeRsvg", quietly = TRUE)) | |
} | |
my_fun() | |
#> ℹ The packages "DiagrammeR" (>= 1.0.9) and "DiagrammeRsvg" are required. | |
#> ✖ Would you like to install them? |
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(DBI) | |
con <- dbConnect( | |
RPostgres::Postgres(), | |
... | |
) | |
dbExecute( | |
con, | |
"CREATE TEMP TABLE x (a int); CREATE TEMP TABLE y (b int)", | |
immediate = TRUE |
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
my_letters <- c("A", "B", "C", "D", "E") | |
bench::mark(for (i in 1:10000) NULL) | |
#> # A tibble: 1 × 6 | |
#> expression min median `itr/sec` mem_alloc `gc/sec` | |
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl> | |
#> 1 for (i in 1:10000) NULL 312µs 332µs 2972. 38.9KB 36.3 | |
bench::mark(for (i in 1:10000) my_letters[3], for (i in 1:10000) my_letters[[3]]) | |
#> # A tibble: 2 × 6 | |
#> expression min median `itr/sec` mem_alloc `gc/sec` | |
#> <bch:expr> <bch:t> <bch:> <dbl> <bch:byt> <dbl> |
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
# Use: add `log_call("<function name")` to your functions | |
# TODO: Add to all functions in a namespace via `trace()` | |
indent <- new_environment(list(value = 0L)) | |
log_call <- function(name, call = sys.call(-1), envir = parent.frame()) { | |
srcref <- attr(call, "srcref") | |
if (is.null(srcref)) { | |
call_dep <- paste(gsub("^ +", "", deparse(call)), collapse = "") |
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(conflicted) | |
library(tidyverse) | |
new_region <- function(name) { | |
paste0("# ", name, " ", strrep("-", max(88 - nchar(name) - 4, 0))) | |
} | |
boilerplate <- function(name) { | |
paste(collapse = "\n", c( | |
new_region(name), |
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
generate <- function(named, unnamed, used = exprs()) { | |
if (length(named) == 0 && length(unnamed) == 0) { | |
return(deparse(call2("check_api", !!!used), width.cutoff = 500)) | |
} | |
out <- character() | |
for (i in seq_along(named)) { | |
out <- c(out, generate(named[-i], unnamed, c(used, named[i]))) | |
} |
NewerOlder