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 / pynR.Rmd
Created October 10, 2015 11:48
RMarkdown de PythonInR
---
title: "RMarkdownでPythonInR"
author: '@kohske'
date: "2015年10月10日"
output: html_document
---
参考 https://speakerdeck.com/yamano357/tokyor51-lt
@kohske
kohske / pynR.Rmd
Created October 10, 2015 11:43
RMarkdown de PythonInR
---
title: "RMarkdownでPythonInR"
author: '@kohske'
date: "2015年10月10日"
output: html_document
---
参考 https://speakerdeck.com/yamano357/tokyor51-lt
フック
@kohske
kohske / spfw.R
Created April 2, 2015 12:15
separate plot of facet_wrap in ggplot2
library(gtable)
d=data.frame(g=c(1,1,1,2,2,3),x=c(1,2,3,1,2,3),y=1:6);
p = ggplot(d,aes(x,y))+geom_bar(stat="identity")+facet_wrap(~g)
gt= ggplot_gtable(ggplot_build(g))
graphics.off()
for (p in c(4, 7, 10)) {
pdf(paste0("plot-", p, ".pdf"))
grid.draw(gt[,c(1:3, p, 12)])
@kohske
kohske / gyakutan.R
Last active August 29, 2015 14:17
Gaykutan.R
# http://blog.goo.ne.jp/r-de-r/e/c9cc759642ea0c02560bd08c975fb156
b = 0.111111 * 1:9 # b は 0.111111 ~ 0.999999 の 9 種類
bz = b+0.000001
b2 = 2 * b
bz2 = 2*bz
b.sq = b ^ 2
bz.sq = bz ^ 2
n = 10000 # 探索範囲上限
ansa = c()
@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
@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 / 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 / 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")
# ↓CP932
> txt <- "あa"
> txt
[1] "あa"
> Encoding(txt)
[1] "unknown"
> charToRaw(txt)
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)