Skip to content

Instantly share code, notes, and snippets.

View kohske's full-sized avatar

kohske takahashi kohske

  • Ritsumeikan University
  • Osaka, Japan
  • X @kohske
View GitHub Profile
@kohske
kohske / sample.Rnw
Last active August 29, 2015 13:56
knitr+animation+latex
\documentclass{ltjsarticle}
\usepackage{luatexja}
\let\ifdraft\relax % おまじない
\usepackage{animate}
\title{PDFレポートでアニメーション}
\author{@kohske}
\begin{document}
\maketitle
@kohske
kohske / lp.R
Last active August 29, 2015 13:56
「R & knitr で文芸的プログラミング的な何か」のWEBファイル
## ----include=FALSE-------------------------------------------------------
library(knitr)
opts_chunk$set(tidy=TRUE)
## ----平均しますね--------------------------------------------------------------
Mean <- function(x) {
y <-
@kohske
kohske / rmarkdown-to-html
Created February 21, 2014 03:02
emacsでknit2html
(defun rmarkdown-to-html ()
"Run knitr::knit2html on the current file"
(interactive)
(shell-command
(format "Rscript -e \"knitr::knit2html('%s')\""
(shell-quote-argument (buffer-file-name)))))
@kohske
kohske / sample.Rmd
Created February 22, 2014 13:33
RmdからWordへ...... Enjoy Tikz!!
# RmdからWordへ
と見せかけて、ホントはTikz推しの話。
## RmdからWordへの変換
@teramonagiさんのTokyo R #36での発表
http://www.slideshare.net/teramonagi/tokyo-r36-20140222
unlockBinding("to_deck", asNamespace("slidify"))
f <- function (doc)
{
txt = str_split_fixed(read_file(doc), "\n---", 2)
meta = yaml.load(gsub("^---\n+", "", txt[1]))
meta <- lapply(meta, iconv, "utf8", "sjis")
cfile = ifelse(is.null(meta$config), "config.yml", meta$config)
deck = modifyList(get_config(cfile), c(meta, slides = txt[2]))
deck$standalone = ifelse(deck$mode == "standalone", TRUE,
FALSE)
# ↓CP932
> txt <- "あa"
> txt
[1] "あa"
> Encoding(txt)
[1] "unknown"
> charToRaw(txt)
@kohske
kohske / script.R
Last active August 29, 2015 13:57
install.packages("devtools")
library(devtools)
dev_mode()
install_github("kohske/markdown@fix/encode")
install_github("kohske/slidify@fix/encode")
install_github("kohske/knitrBootstrap@fix/encode")
library(knitr)
knit2html("test-knit-CP932.Rmd", encoding="CP932")
knit2html("test-knit-UTF8.Rmd", encoding="UTF8")
@kohske
kohske / gist:ce83301f4e666156a722
Created September 8, 2014 04:16
R6 extension
Person <- R99Class("Person",
public : {
name = NA
hair = NA
# initialize
initialize = function(name, hair) {
if (!missing(name)) self$name <- name
if (!missing(hair)) self$hair <- hair
@kohske
kohske / pie3d.R
Created October 7, 2014 04:50
pie3d -- interactive 3d pie chart by R and rgl
library(rgl)
pie3d <- function(x, depth = 0.2, webgl = TRUE) {
x = cumsum(x)/sum(x)
ps = embed(c(0, 2*pi*x), 2)
for (i in 1:nrow(ps)) {
p = seq(ps[i, 2], ps[i, 1], by = 2*pi/360)
rgl.triangles(rep(c(t(cbind(embed(sin(p), 2), 0))), 2),
@kohske
kohske / session.R
Created November 8, 2014 01:42
sessionInfo / 20141108
> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)
locale:
[1] ja_JP.UTF-8/ja_JP.UTF-8/ja_JP.UTF-8/C/ja_JP.UTF-8/ja_JP.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base