Skip to content

Instantly share code, notes, and snippets.

View wrathematics's full-sized avatar

Drew Schmidt wrathematics

View GitHub Profile
# Replacement for tools::package_native_routine_registration_skeleton(".") using ctags
register = function(dir=".", dump=TRUE)
{
pkg = read.dcf(paste0(dir, "/DESCRIPTION"))[1]
outfile = paste0(dir, "/src/", pkg, "_native.c")
if (dump && file.exists(outfile))
file.remove(outfile)
@wrathematics
wrathematics / answerbox.md
Created August 16, 2016 17:49
answer box
title author output
Worksheet
Professor of Science
pdf_document

\newcommand{\answerbox}{% \begin{picture}(450,50)(0,0)% \centering% \framebox(450,50){}%

#include <Rcpp.h>
using namespace Rcpp;
class foo {
public:
int hmn;
foo(int q){
hmn = q;
}
library(memuse)
library(ngram)
library(RWeka)
x = ngram::rcorpus(nwords=1e6, alphabet="a")
memuse(x)
## 4.292 MiB
system.time(ngram::ngram_asweka(x, min=2, max=2))
## user system elapsed
## 0.216 0.044 0.261
@wrathematics
wrathematics / gist:53c761b3e8cdfce18e3c
Created March 24, 2016 13:01
readxl valgrind report
$ R --vanilla -d valgrind < read.r
==13800== Memcheck, a memory error detector
==13800== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==13800== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==13800== Command: /usr/lib/R/bin/exec/R --no-save --quiet --no-restore --vanilla
==13800==
==13800== WARNING: valgrind ignores shmget(shmflg) SHM_HUGETLB
> readxl::read_excel('exp.xlsx')
==13800== Invalid free() / delete / delete[] / realloc()
==13800== at 0x4C2D28B: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
library(Rcpp)
source <- "
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
std::string str_rep(std::string x, IntegerVector ind, std::string value)
{
int pos;
for (int i=0; i<ind.length(); i++)
@wrathematics
wrathematics / gist:b72293aa6e3585ad382d
Last active March 4, 2016 19:17
Using scan-build with R
### Snippet from my "R package installer" script
export RCMD="env MAKE='scan-build make -j 5' R --vanilla CMD INSTALL"
eval `echo $RCMD` $PKG
@wrathematics
wrathematics / gist:956d2468958bc93851de
Created October 18, 2015 02:42
emojis with knitr/latex
% !TeX program = XeLaTeX
\documentclass[a4paper,10pt]{article}
\usepackage{fontspec}
\setmainfont{DejaVu Sans}
\setmonofont{DejaVu Sans}
\usepackage{listings}
\lstset{language=R}
@wrathematics
wrathematics / unicode.Rnw
Created October 18, 2015 01:08
knitr drops unicode?
\documentclass[a4paper,10pt]{article}
\begin{document}
<<>>=
cat("\U0001f431")
@
\end{document}
@wrathematics
wrathematics / gist:a4813c6f2c3de59b2e3a
Created October 7, 2015 11:23
Saccharomyces cerevisiae
ATGGTACTGACGATTTATCCTGACGAACTCGTACAAATAGTGTCTGATAAAATTGCTTCAAATAAGGGAAAAATCACTTTGAATCAGCTGTGGGATATATCTGGTAAATATTTTGATTTGTCTGATAAAAAAGTTAAACAGTTCGTGCTTTCATGCGTGATATTGAAAAAGGACATTGAGGTGTATTGTGATGGTGCTATAACAACTAAAAATGTGACTGATATTATAGGCGACGCTAATCATTCATACTCGGTTGGGATTACTGAGGACAGCCTATGGACATTATTAACGGGATACACAAAAAAGGAGTCAACTATTGGAAATTCTGCATTTGAACTACTTCTCGAAGTTGCCAAATCAGGAGAAAAAGGGATCAATACTATGGATTTGGCGCAGGTAACTGGGCAAGATCCTAGAAGTGTGACTGGACGTATCAAGAAAATAAACCACCTGTTAACAAGTTCACAACTGATTTATAAGGGACACGTCGTGAAGCAATTGAAGCTAAAAAAATTCAGCCATGACGGGGTGGATAGTAATCCCTATATTAATATTAGGGATCATTTAGCAACAATAGTTGAGGTGGTAAAACGATCAAAAAATGGTATTCGCCAGATAATTGATTTAAAGCGTGAATTGAAATTTGACAAAGAGAAAAGACTTTCTAAAGCTTTTATTGCAGCTATTGCATGGTTAGATGAAAAGGAGTACTTAAAGAAAGTGCTTGTAGTATCACCCAAGAATCCTGCCATTAAAATCAGATGTGTAAAATACGTGAAAGATATTCCAGACTCTAAAGGCTCGCCTTCATTTGAGTATGATAGCAATAGCGCGGATGAAGATTCTGTATCAGATAGCAAGGCAGCTTTCGAAGATGAAGACTTAGTCGAAGGTTTAGATAATTTCAATGCGACTGATTTATTACAAAATCAAGGCCTTGTTATGGAAGAGAAAGAGGATGCTGTAAAGAATGAAGTTCTTCTTAATCGATTTTATCCACTTCAAAATCAGACTTATGACATTG