kilometer
October 22, 2022
580

# TokyoR#102_RMarkdown

October 22, 2022

## Transcript

2. ### Who！？ 名前： 三村 @kilometer 職業： ポスドク (こうがくはくし) 専⾨： ⾏動神経科学(霊⻑類) 脳イメージング

医療システム⼯学 R歴： ~ 10年ぐらい 流⾏: 南極探検隊

6. ### Beginne R Advance d Hoxo_m If I have seen further

it is by standing on the shoulders of Giants. -- Sir Isaac Newton, 1676

8. ### "a" != "b" # is A in B? ブール演算⼦ Boolean

Algebra [1] TRUE 1 %in% 10:100 # is A in B? [1] FALSE
9. ### George Boole 1815 - 1864 A Class-Room Introduc2on to Logic

h7ps://niyamaklogic.wordpress.com/c ategory/laws-of-thoughts/ Mathematician Philosopher &
10. ### ブール演算⼦ Boolean Algebra A == B A != B George

Boole 1815 - 1864 A | B A & B A %in% B # equal to # not equal to # or # and # is A in B? wikipedia

12. ### AI Programmer !? import sample data scatter plot speed and

dist as x and y axes, respectively import pandas as pd import matplotlib.pyplot as plt data = pd.read_csv('sample_data.csv') plt.scatter(data['speed'], data['dist’]) plt.show() library(tidyverse) df <- read_csv("sample_data.csv") df %>% ggplot(aes(x = speed, y = dist)) + geom_point() https://aiprogrammer.hashlab.jp/

Share

(for human)
16. ### Let us change our traditional attitude to the construction of

programs: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to humans what we want the computer to do. — Donald E. Knuth, Literate Programming, 1984 プログラム構築に関する伝統的な態度を切り替えてみましょう。 コンピュータに何をするべきかを指図するのが主な仕事だと考えるのではなく、 むしろコンピュータに何をして欲しいかを⼈間に説明することに集中しよう。 — ドナルド・E・クヌース, ⽂芸的プログラミング, 1984 Literate Programming

18. ### Literate Programming in R Sweave knitr rmarkdown Quato? 2012 2002

2014 WAB → Noweb ↓ 2021 R Markdown: The Definitive Guide Yihui Xie, J. J. Allaire, Garrett Grolemund, 2022 https://bookdown.org/yihui/rmarkdown/#ref-xie2015 Yihui Xie @xieyihui
19. ### R Markdown ① Make a new .Rmd file ② Write

something (for human) ③ Knit it!!
20. ### R Markdown ① Make a new .Rmd file ② Write

something (for human) using markdown & R ③ Knit it!!
21. ### Markdown A simple markup language that uses plain text formatting

syntax plain text with markdown .html .pdf .docx
22. ### Markup Language Plain text Rich text HTML = Hyper Text

Markup Language Web browser

24. ### Markup Language Plain text Rich text Markdown HTML Pandoc pandoc

-f markdown -t html hoge.md > hoge.html
25. ### Markdown Plain text Rich text *This* This **This** This ***This***

~~This~~ This <u>This</u> This This

29. ### ```r library(palmerpenguins) penguins[1, ] ``` ``` # A tibble: 1

× 8 species island bill_…¹ bill_…² flipp…³ body_…⁴ sex year <fct> <fct> <dbl> <dbl> <int> <int> <fct> <int> 1 Adelie Torger… 39.1 18.7 181 3750 male 2007 # … with abbreviated variable names ¹bill_length_mm, # ²bill_depth_mm, ³flipper_length_mm, ⁴body_mass_g ``` Markdown Plain text Rich text
30. ### Write .md .md .r write code test code write document

copy code paste code copy results paste results write document write document
31. ### Write .Rmd .Rmd set document write document write .r write

document write document test .r write .r test .r

33. ### Write .Rmd .Rmd set document write document write .r write

document write document test .r write .r test .r Peaceful world ・No copy & paste ・No window switching
34. ### Write .Rmd .Rmd set document write document write .r write

document write document test .r write .r test .r Peaceful world ・No copy & paste ・No window switching You MUST write docs about the R code You JUST write docs about your analysis with R code
35. ### Write .Rmd .Rmd set document write document write .r write

document write document test .r write .r test .r --- title: "Hoge" output: html_document: default --- YAML header (YAML Ain't a Markup Language.)
36. ### Write .Rmd .Rmd set document write document write .r write

document write document test .r write .r test .r --- title: "Hoge" output: html_document: keep_md: TRUE --- YAML header (YAML Ain't a Markup Language.)
37. ### Knit .Rmd in English .Rmd → .html .Rmd → .pdf

.Rmd → .docx Easy!! Great!! Comfortable! Good!! Okay, if you need.
38. ### Knit .Rmd in Japanese .Rmd → .html .Rmd → .pdf

.Rmd → .docx Easy!! Great!! Darkness Darknes(
39. ### As soon as Anakin came before him on Coruscant, Yoda

could sense darkness in his soul. --- The Phantom Menace
40. ### Write .Rmd .Rmd set document write document write .r write

document write document test .r write .r test .r YAML header for Japanese PDF (in my env.) --- title: "segments" output: pdf_document: latex_engine: xelatex documentclass: bxjsarticle classoption: xelatex,ja=standard mainfont: Hiragino Kaku Gothic Pro ---
41. ### Write .Rmd .Rmd set document write document write .r write

document write document test .r write .r test .r Code Chunk 1 Code Chunk 2 ```{r, chunk1} ``` ```{r, chunk2} Chunk name
42. ### Chunk options ```{r chunk1, ...} ``` Language Name Options echo

eval include results fig.width / fig.height collapse warning message
43. ### Chunk options ```{r chunk1, options...} ``` ```{r} #| chunk1 #|

options... ``` =
44. ### Write .Rmd .Rmd set document write document write .r write

document write document test .r write .r test .r ```{r setup, include=FALSE} knitr::opts_chunk\$set( echo = TRUE ) ``` Global setting of chank options
45. ### Write .Rmd .Rmd set document write document write .r write

document write document test .r write .r test .r Code Chunk 1 ```{r, chunk1} ``` Run this chunk: ⌘+Shift+↩
46. ### .Rmd set document write document write .r write document write

document test .r write .py test .py ```{r pyenv, include=FALSE} reticulate::use_python( python = ".../bin/python", required = TRUE ) ``` Write python in .Rmd

50. ### R Markdown ① Make a new .Rmd file ② Write

something (for human) using markdown & R ③ Knit it!!

52. ### Write .Rmd .Rmd set document write document write .r write

document write document test .r write .r test .r --- title: "Hoge" output: html_document: default --- YAML header (YAML Ain't a Markup Language.)
53. ### Chunk options ```{r chunk1, ...} ``` Language Name Options echo

eval include results fig.width / fig.height collapse warning message

55. ### Let us change our traditional attitude to the construction of

programs: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to humans what we want the computer to do. — Donald E. Knuth, Literate Programming, 1984 プログラム構築に関する伝統的な態度を切り替えてみましょう。 コンピュータに何をするべきかを指図するのが主な仕事だと考えるのではなく、 むしろコンピュータに何をして欲しいかを⼈間に説明することに集中しよう。 — ドナルド・E・クヌース, ⽂芸的プログラミング, 1984 Literate Programming