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 / 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,
@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 / 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
> devtools::install_github("tidyverse/dplyr")
Downloading GitHub repo tidyverse/dplyr@master
from URL https://api.github.com/repos/tidyverse/dplyr/zipball/master
Installing dplyr
Downloading GitHub repo hadley/rlang@ac7498c9
from URL https://api.github.com/repos/hadley/rlang/zipball/ac7498c9
Installing rlang
"C:/PROGRA~1/R/R-33~1.3/bin/x64/R" --no-site-file --no-environ --no-save
--no-restore --quiet CMD \
INSTALL \
@krlmlr
krlmlr / sqlite3-unsigned-64.patch
Created January 8, 2017 12:56
SQLITE_UINT64_TYPE
diff --git a/src/sqlite3/sqlite3.h b/src/sqlite3/sqlite3.h
index 37d1024..0f55423 100644
--- a/src/sqlite3/sqlite3.h
+++ b/src/sqlite3/sqlite3.h
@@ -248,8 +248,11 @@ typedef struct sqlite3 sqlite3;
** between 0 and +18446744073709551615 inclusive.
*/
#ifdef SQLITE_INT64_TYPE
+ #ifndef SQLITE_UINT64_TYPE
+ #define SQLITE_UINT64_TYPE unsigned SQLITE_INT64_TYPE