atusy / blog Goto Github PK
View Code? Open in Web Editor NEWblog of atusy
Home Page: https://blog.atusy.net
blog of atusy
Home Page: https://blog.atusy.net
library(dplyr, warn.conflicts = FALSE)
library(purrr)
# mutate_at
data.frame(a = 1) %>%
mutate_at("b", identity)
#> Error in mutate_impl(.data, dots): Evaluation error: object 'b' not found.
data.frame(a = 1) %>%
mutate_at("b", function(x) "b")
#> a b
#> 1 1 b
# map_at
data.frame(a = 1) %>%
map_at("b", identity) %>%
as.data.frame
#> a
#> 1 1
data.frame(a = 1) %>%
map_at("b", function(x) "b") %>%
as.data.frame
#> a
#> 1 1
Created on 2019-02-05 by the reprex package (v0.2.1)
ユーザーが tlmgr install
を使えるようにするため, tinytex::install_tinytex
し直す
Dockerfile
FROM rocker/verse
RUN Rscript -e "tinytex::uninstall_tinytex()" \
&& sudo -u rstudio Rscript -e "tinytex::install_tinytex()"
すると以下のような Rmd を PDF にできる.
(要ipaex)
---
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \usepackage{bookmark}
- \usepackage{xltxtra}
- \usepackage{zxjatype}
- \usepackage[ipaex]{zxjafont}
---
あああ
css に .newpage { break-before: page; } 作って html は p.newpage hogehoge すればいいのね.
https://codepen.io/atusy/pen/WPrqzK
---
output: html_notebook
---
```{r, class.source='hoge'}
NULL
```
<pre class="r"><code>NULL</code></pre>
Warning message:
'devtools::build_win' is deprecated.
Use 'check_win_*()' instead.
See help("Deprecated") and help("devtools-deprecated").
row/col のサイズはマージンやgapを抜いたもの
コンテナの高さを指定しておくと, fr 単位でアイテムを作れる
<link rel="stylesheet" href="//use.fontawesome.com/releases/v5.7.1/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/languages/r.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.3.0/highlightjs-line-numbers.min.js"></script>
<script>
hljs.initHighlightingOnLoad();
hljs.initLineNumbersOnLoad();
</script>
行番号の背景を無色にする
コードブロックには source
, output
, warning
, error
それぞれの場合で異なるクラスを与えておきたい.
これにより,行番号表示を有効にすると source
以外の背景色が source
と同じになってしまう問題を CSS でカンタンに解決できる.
以下のように設定
config.toml
[params]
images = ["cover.jpg"]
記事の yaml フロントマター
images = "cover.jpg"
PDF をコマンドラインから圧縮する
https://qiita.com/peaceiris/items/f1f4c9734b98cf9c7113
Xonshでコマンドを作る
https://qiita.com/riktor/items/2f18db475dc5b2c8d829
def _pdf_compress(args) :
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=@(args[1]) @(args[0])
aliases["pdf_compress"] = _pdf_compress
helper-*.R
は load_all()
時に実行され、テスト前にも実行されるsetup.R
は load_all()
時に無視され、テスト前には実行される---
output:
html_document:
highlight: pygments
---
```{r setup, include = FALSE}
block_class = function (x) {
if(length(x) == 0) return()
paste0(".", strsplit(x, "\\s+"), collapse = " ")
}
hook.r = function(x, options, fence = "```") {
language = tolower(options$engine)
if (language == "node") language = "javascript"
if (!options$highlight) language = "text"
classes = block_class(options$class.source)
attrs = options$attr.source
paste0("\n\n", fence, "{.", language, " ", classes, " ", attrs, "}\n", x, fence, "\n\n")
}
hook_source = function(x, options) {
x = knitr:::hilight_source(x, "markdown", options)
hook.r(paste(c(x, ""), collapse = "\n"), options)
}
knitr::knit_hooks$set(source = hook_source)
```
```{r, attr.source=".numberLines startFrom='10'"}
library(magrittr)
iris %>%
.$Sepal.Length %>%
density %>%
plot
```
@importFrom
、@seealso
の他に
@inherit
がある
*italic*
**bold**
などは OK
```{r iris, fig.cap = "`include_graphics`"}
knitr::include_graphics(system.file("img", "Rlogo.jpg", package = "jpeg"))
```
は pdf_document2 で
\begin{figure}\caption{include_graphics} \end{figure}Figure 1:1
といったナゾの事態に.
\@ref(fig:iris)
: Error: '@' is an unrecognized escape in character string starting ""@"\\@ref(fig:iris)
: Undefined control sequence.@ref(fig:iris)
: GOOD(ref:foo) figure caption
形式を利用する.
(ref:foo)
r var` とすると var の中身を評価してキャプションに入れられる.
glue を併用して改行つきのキャプションを作れる.
(ref:foo) foo
(ref:bar) bar
としておくと (ref:foo) (ref:bar)
は foo bar
になるので,複数のテキストを簡単に合体させられる.
Adwaita はわかりやすいがクッソださい.
Papirus 系はよさげだが,Inkscape のアイコンが意味不明.
Newaita 中間的でよい.Document Viewer など,一部ごちゃっとしたアイコンもある.
mainfont: Noto Serif
sansfont: Noto Sans
monofont: Noto Mono
mathfont: Noto Serif
CJKmainfont: Noto Serif CJK JP
といった具合にする.数式も Noto にできてシームレス.
mainfontoptions, sansfontoptions, monofontoptions, mathfontoptions, CJKoptions
によってオプション設定も可能.
Building sites … WARN 2019/04/16 19:40:35 Page's .RSSLink is deprecated and will be removed in a future release. Use the Output Format's link, e.g. something like:
{{ with .OutputFormats.Get "RSS" }}{{ . RelPermalink }}{{ end }}.
WARN 2019/04/16 19:40:35 Page's .URL is deprecated and will be removed in a future release. Use .Permalink or .RelPermalink. If what you want is the front matter URL value, use .Params.url.
https://yihui.name/knitr/options/
```{r foo, fig.cap="Long caption.", fig.scap="Short caption", out.extra=''}
```{r foo, fig.cap="Short caption. Additional sentences.", fig.scap=NULL, out.extra=''}
The following won't work.
(ref:hoge) Short caption. Additional sentences.
```{r foo, fig.cap="(ref:hoge)", fig.scap=NULL, out.extra=''}
kable(table, caption = "Long", short.caption = "Short")
xtable(table, caption = c("Long", "Short")
pandoc 由来の syntax highlight を利用すると,pre が pre.sourceCode に変わり,div.sourceCode で囲われる.
このため,pre.sourceCode の margin をなくし,div.sourceCode に margin 1em 0 を与えるようだ.
html_document では bootstrap が pre { margin: 0 0 10px}
を指定しているので,これに合わせて div { margin: 0 0 10px }
にした方が見た目の変化が最小限に済む
rocker の docker-compose.yml はどんな風に書けばいいのかなーと思ったが,GitHubで検索すれば色々参考になりそう.
filename:docker-compose.yml rocker
https://github.com/search?q=filename%3Adocker-compose.yml+rocker
以下は等価
textInput("text", label = "text")
renderText(input$text)
textInput("text", label = "text")
renderText(input$text)
output$foo
に render 結果を保存しておき、明示的に UI として出力させるようにしておく
output$mtcars <- renderPlot(plot(mtcars$wt, mtcars$mpg))
plotOutput("mtcars", dblclick = dblclickOpts(id = "mtcars_info"))
renderPrint(input$mtcars_info)
req()
に渡した変数が NULL
や FALSE
の場合、 reactive()
の評価を中断する。
中断された reactive な変数を利用した plot などは表示されない。
---
runtime: shiny
output:
html_document: default
---
```{r, include = FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{r}
x <- NULL
y <- reactive({
req(x)
1
})
output$y <- renderPlot(plot(y()))
plotOutput("y")
```
#' @seealso [Object] # パッケージ内
#' @seealso \link[Package]{Object} #パッケージ外
Object()
という書き方ができる。knitr::knit_engines$set(
text = function(options) {
options$results <- 'asis'
options$echo <- FALSE
knitr::engine_output(options, NULL, options$code)
}
)
あいうえお
かきくけこ
sudo docker exec -it rocker_r_1 /usr/local/bin/R
sudo pacman -Syu nodejs npm git
sudo install -g gatsby-cli
linuxbrew で nodejs のインストールに失敗したので、システムレベルで導入
gatsby new hello-world https://github.com/gatsbyjs/gatsby-starter-hello-world
cd hello-world
gatsby develop --host 0.0.0.0 --port 8000
リモートからアクセスできるよう、--host
を 0.0.0.0
にした (既定値: localhost
)
mutate_if
は適用する関数を名前付きリストで複数種指定できる.
リストに与えた名前は元の変数名の suffix になる.
iris %>% mutate_if(is.numeric, list(a = ~ rnorm(., .), b = ~ identity(.)))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.