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
cmake_minimum_required(VERSION 2.8) | |
project(RcppPackage) | |
find_package(LibR) | |
if(${LIBR_FOUND}) | |
else() | |
message(FATAL_ERROR "No R...") | |
endif() | |
message(STATUS ${CMAKE_SOURCE_DIR}) | |
execute_process( | |
COMMAND ${LIBR_EXECUTABLE} "--slave" "-e" "stopifnot(require('Rcpp'));cat(Rcpp:::Rcpp.system.file('include'))" |
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
#! /usr/bin/Rscript | |
# convert from: | |
# | |
# ``` | |
# xxxxx.... | |
# ``` | |
# | |
# to: | |
# | |
# ```txt |
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
# outline <- c("a", "b") | |
# print_outline(outline): | |
# - a | |
# - b | |
# print_outline(outline, 1): | |
# - **a** | |
# - b | |
# --- | |
# outline <- list("a" = c("b", "c", "d"), "e" = NULL, "f" = NULL) | |
# print_outline(outline): |
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
a <- "X123456789050102550703 | |
A123456987050102660703 | |
B123456789050102" | |
gregexpr("(?<id>[A-Z]\\d{9})(?<b_date>\\d{6})(?<d_date>\\d{6}){0,1}", a, perl=TRUE) | |
# [[1]] | |
# [1] 1 24 47 | |
# attr(,"match.length") | |
# [1] 22 22 16 | |
# attr(,"useBytes") | |
# [1] 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
detect_continuous <- function(src, gap = 1) { | |
index.bool <- diff(src) == gap | |
is.in_sequence <- FALSE | |
start <- c() | |
end <- c() | |
for(i in 1:length(index.bool)) { | |
if(!index.bool[i]) { | |
is.in_sequence <- FALSE | |
} | |
if(index.bool[i] & !is.in_sequence) { |
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
#'@title Generate HTML table from data.frame and add a pop-up comment on specific table entry | |
#'@param r_dataframe a data.frame object | |
#'@param js_show a list object whose name is the column names of r_dataframe, value is the added pop-up comment | |
html_table_popup_comment <- function(r_dataframe, js_show, ...) { | |
stopifnot(require(xtable)) | |
global.env <- environment() | |
r_dataframe.xtable <- xtable(r_dataframe) | |
global.env$sanitize <- function(str) { | |
result <- str | |
result <- gsub("&", "& ", result, fixed = 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
batch_fetch.PostgreSQLConnection <- function(db, query, n, m) { | |
require(data.table) | |
start.index <- 0 | |
pb <- txtProgressBar(max = n) | |
dbSendQuery(db, "START TRANSACTION READ ONLY") | |
dbSendQuery(db, sprintf('DECLARE res CURSOR FOR %s', query)) | |
res <- dbSendQuery(db, sprintf("fetch %d from res", m)) | |
tb.part <- fetch(res, m) | |
tb.class <- sapply(tb.part, class) |
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
extract_subpattern <- function(text, pattern) { | |
gregexpr.result <- gregexpr(pattern=pattern, text=text, perl=TRUE) | |
retval <- list() | |
for(i in 1:length(gregexpr.result)) { | |
result <- gregexpr.result[[i]] | |
retval[[i]] <- list() | |
for(name in attr(result, "capture.names")) { | |
start <- attr(result, "capture.start")[,name] | |
len <- attr(result, "capture.length")[,name] | |
retval[[i]][[name]] <- substr(text[i], start=start, stop = start + len - 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
# Escape Zombie Land! | |
# This is a simulation an escape from a hot zombie zone. It freezes and gives an error if you get get killed so you had best not. You attempt to navigate the zone by constructing waypoints. | |
# This is not a very clean set up and I would like to clean it up. However, I have spent way more time on it than I intended. So I might come back to it another day. | |
# Zombies are distributed on a 10 x 10 grid. | |
gridxy = c(10,10) | |
# The number of zombies on the map |
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
RMD_FILES = $(wildcard *.Rmd) | |
HTML_FILES = $(RMD_FILES:.Rmd=.html) | |
all: $(HTML_FILES) | |
(cd img && make) | |
%.html: %.md | |
pandoc -s -S -i -t slidy --mathjax -V slidy_url=slidy --base-header-level=3 $(@:.html=.md) -o $@ | |
%.md: %.Rmd |