Skip to content

Instantly share code, notes, and snippets.

View yutannihilation's full-sized avatar
🍣
Nobody loves you

Hiroaki Yutani yutannihilation

🍣
Nobody loves you
View GitHub Profile
library(tidyverse)
library(gghighlight)

d <- mtcars %>%
  #filter(drat >= 3) %>%
  select(mpg,disp,hp,drat) %>%
  gather(variable, value, -disp, -hp, -drat) 
d
#>     disp  hp drat variable value
library(ggplot2)
# To reproduce this error shadowtext is installed from source, not binary.
library(shadowtext)

set.seed(1)
d <- data.frame(x = rnorm(3), y=rnorm(3), label = c('hello', 'world', '!!!'))
ggplot(d, aes(x,y)) +
  geom_shadowtext(aes(label=label, color=label), bgcolor='firebrick')
#&gt; Error in col[, rep(1, length(alpha)), drop = FALSE]: subscript out of bounds
# https://github.com/GuangchuangYu/shadowtext/blob/master/vignettes/shadowtext.Rmd
library(ggplot2)
library(shadowtext)

random_text <- function(n=1, length=10) {
  d <- data.frame(n=1:n, length=length)
  sapply(1:nrow(d), function(i) {
    paste(sample(c(0:9, letters, LETTERS),
                 d$length[i], replace=TRUE),
foo <- function(x = list()) structure(x, class = "foo")
`+.foo` <- function(e1, e2) message("foo!")

bar <- function(x = list()) structure(x, class = "bar")
`+.bar` <- function(e1, e2) message("bar?")

# unaddable, no methods
list() + list()
#&gt; Error in list() + list(): non-numeric argument to binary operator
@yutannihilation
yutannihilation / knitr-hook.Rmd
Created August 8, 2018 14:19
Use knitr's output hook to hide path
---
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
orig_hook <- knitr::knit_hooks$get("output")
knitr::knit_hooks$set(
library(leaflet)
# 先にbasemapをつくっておく
basemap <- leaflet() %>%
addTiles("http://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png",
attribution = "<a href='http://maps.gsi.go.jp/development/ichiran.html' target='_blank'>地理院タイル</a>")
library(mapview)
# つくったbasemapをmap引数に指定する

参考

nest_join()full_join()以外のjoinを一般化するものらしい。おもしろい。

nest_join() is the most fundamental join since you can recreate the other joins from it. An inner_join() is a nest_join() plus an [tidyr::unnest()], and left_join() is a nest_join() plus an unnest(drop = FALSE). A semi_join() is a nest_join() plus a filter() where you check that every element of data has at least one row, and an anti_join() is a nest_join() plus a filter() where you check every element has zero rows.

@yutannihilation
yutannihilation / missingness-can-be-lost.md
Created July 12, 2018 11:00
Missingness won't propagate if the default value is set.
func1 <- function(dummy = 1) {
  missing(dummy)
}

func1()
#> [1] TRUE

func2 <- function(dummy = 1) {
 func1(dummy=dummy)