Skip to content

Instantly share code, notes, and snippets.

View otsaw's full-sized avatar

Osmo Salomaa otsaw

  • Helsinki, Finland
View GitHub Profile
@otsaw
otsaw / timer.py
Created January 27, 2022 12:36
Python context manager timer
import contextlib
import time
@contextlib.contextmanager
def Timer():
start = time.time()
yield lambda: time.time() - start
print(f"Elapsed: {time.time() - start:.3f} s")
with Timer():
*** caught segfault ***
address (nil), cause 'unknown'
*** glibc detected *** /usr/lib/R/bin/exec/R: corrupted double-linked list: 0x0000000004369b30 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x76d76)[0x7ff267663d76]
/lib/x86_64-linux-gnu/libc.so.6(+0x7a6a4)[0x7ff2676676a4]
/lib/x86_64-linux-gnu/libc.so.6(__libc_malloc+0x70)[0x7ff267668c00]
/usr/lib/R/lib/libR.so(R_AllocStringBuffer+0x78)[0x7ff267ea9948]
/usr/lib/R/lib/libR.so(+0x92140)[0x7ff267e34140]
/usr/lib/R/lib/libR.so(+0x93956)[0x7ff267e35956]
==20550== Invalid read of size 1
==20550== at 0x4F29B42: Rf_inherits (Rinlinedfuns.h:365)
==20550== by 0xEF48632: Rcpp::DataFrame_Impl<Rcpp::PreserveStorage>::set__(SEXPREC*) (DataFrame.h:79)
==20550== by 0xEF789F3: Rcpp::DataFrame_Impl<Rcpp::PreserveStorage>::DataFrame_Impl(SEXPREC*) (DataFrame.h:44)
==20550== by 0xEF6585E: ungroup_grouped_df(Rcpp::DataFrame_Impl<Rcpp::PreserveStorage>) (dplyr.cpp:1711)
==20550== by 0xEF658DA: tbl_df_impl(Rcpp::DataFrame_Impl<Rcpp::PreserveStorage>) (dplyr.cpp:1718)
==20550== by 0xEF426B7: dplyr_tbl_df_impl (RcppExports.cpp:530)
==20550== by 0x4EC9BEC: do_dotcall (dotcode.c:581)
==20550== by 0x4F09290: Rf_eval.part.14 (eval.c:656)
==20550== by 0x4F0C7B6: do_begin (eval.c:1632)
==15635== Invalid read of size 1
==15635== at 0x4F29B42: Rf_inherits (Rinlinedfuns.h:365)
==15635== by 0xEF48632: Rcpp::DataFrame_Impl<Rcpp::PreserveStorage>::set__(SEXPREC*) (DataFrame.h:79)
==15635== by 0xEF789F3: Rcpp::DataFrame_Impl<Rcpp::PreserveStorage>::DataFrame_Impl(SEXPREC*) (DataFrame.h:44)
==15635== by 0xEF65930: as_regular_df(Rcpp::DataFrame_Impl<Rcpp::PreserveStorage>) (dplyr.cpp:1702)
==15635== by 0xEF42937: dplyr_as_regular_df (RcppExports.cpp:500)
==15635== by 0x4EC9BEC: do_dotcall (dotcode.c:581)
==15635== by 0x4F09290: Rf_eval.part.14 (eval.c:656)
==15635== by 0x4F0C7B6: do_begin (eval.c:1632)
==15635== by 0x4F090A6: Rf_eval.part.14 (eval.c:628)
@otsaw
otsaw / test_dplyr_rbind.R
Created April 1, 2014 10:14
Testing type promotions with dplyr's rbind
.rbind = function(x, y)
tryCatch({
dplyr::rbind_list(x, y)
message("OK")
}, error=function(e) print(e))
message("logical --> integer")
.rbind(data.frame(x=TRUE), data.frame(x=1L))
.rbind(data.frame(x=1L), data.frame(x=TRUE))