Skip to content

Instantly share code, notes, and snippets.

@krlmlr
krlmlr / columns.R
Last active June 15, 2022 02:58
Script to query information_schema.columns with dm >= 0.2.8.9007
library(dm)
# Connect to your database here
con <- DBI::dbConnect(duckdb::duckdb())
meta <- dm:::dm_meta(con, simple = TRUE)
# Does this work?
meta %>%
dm_ptype()
@krlmlr
krlmlr / dt-print.R
Last active April 24, 2022 12:59
Use tibble's print method for data.table
penguins_dt <- data.table::as.data.table(palmerpenguins::penguins[1:3,])
penguins_dt
print_data_table <- function(x, ...) {
# Adapted from data.table:::as.data.frame.data.table()
ans <- x
attr(ans, "row.names") <- .set_row_names(nrow(x))
attr(ans, "class") <- c("tbl", "data.frame")
attr(ans, "sorted") <- NULL
attr(ans, ".internal.selfref") <- NULL

Keybase proof

I hereby claim:

  • I am krlmlr on github.
  • I am krlmlr (https://keybase.io/krlmlr) on keybase.
  • I have a public key ASBWEsk3aAEpYhxYHUb4WzW1oPyWabWULdGBQ1_ci84Hiwo

To claim this, I am signing this object:

@krlmlr
krlmlr / block.R
Created June 10, 2021 03:40
Block assigning to a variable more than once
`<-` <- function(lhs, rhs, envir = parent.frame()) {
assign(as.character(substitute(lhs)), rhs, envir)
lockBinding(substitute(lhs), envir)
invisible(rhs)
}
@krlmlr
krlmlr / Rprofile-entrace
Last active January 7, 2021 01:59
Pretty stack traces in R
# Add this to your .Rprofile
options(
error = quote(rlang::entrace()),
rlang__backtrace_on_error = "collapse" # or "branch" or "full"
)
@krlmlr
krlmlr / covr-per-file-analyze.R
Last active March 12, 2020 09:09
Mismatch between source and test file names
#' ---
#' title: Mismatch between source and test files in tibble
#' output:
#' html_notebook:
#' toc: true
#' code_folding: hide
#' ---
# For paged output
options(max.print = 1000)
library(RSQLite)
conn <- dbConnect(SQLite())
dbExecute(conn, "
CREATE TABLE IF NOT EXISTS `sim` (
`time` TEXT,
`subject` INTEGER,
`encounter` INTEGER,
`location` INTEGER,
`temp` REAL,
#!/bin/sh
# Must be called with two command-line args.
# Example: git-svn-relocate.sh http://old.server https://new.server
if [ $# -ne 2 ]
then
echo "Please invoke this script with two command-line arguments (old and new SVN URLs)."
exit $E_NO_ARGS
fi
@krlmlr
krlmlr / deps.R
Created January 19, 2016 14:44
Module dependency graph for an R package
devtools::load_all()
envir <- as.environment("package:darn")
deps <- mvbutils::foodweb(where = envir, plotting = FALSE)
funmat <- deps$funmat
funs <- mget(colnames(funmat), envir, mode = "function")
fun_files <-
lapply(funs, attr, "srcref") %>%
@krlmlr
krlmlr / olson-abbrev.txt
Created October 25, 2017 12:14
Abbreviations for Olson names from Ubuntu system
Africa/Abidjan
Africa/Accra
Afr/Addis_Abab
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau