jwlearn
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: How to use R Markdown to make slides and write drafts? author: date: 2021-07-22 slug: categories: tags: - R - Markdwon --- [[hackmd-github-sync-badge]](https://hackmd.io/IHBEI5Y1RU6Q0DwndPRI9g) **你好,這是 JW-LEARN,一個專門記錄教育/心理測量相關知識的學習筆記。** 今天要分享的是用 R Markdown 實現一條龍做學術工作(資料分析、寫作初稿、簡報)的理想。其實這也不是一個新想法,老早以前就有很多人有這種想法了。例如:[Yongfu Liao](https://yongfu.name/)、[陳紹慶](https://scchen.com/zh/post/dynamic-writing/)、等等,我只是記錄一下我自己的方式,讓以後的自己方便使用。 ## 1) Why? 其實 R 在科學寫作跟發表這方面並不缺乏成熟的 pkg,(缺的可能是成熟的(正體)「中文」工具)。例如知名的**寫輪眼**跟**啪啪芽**: - [xaringan Presentations](https://bookdown.org/yihui/rmarkdown/xaringan.html) (Xie, 2021) - [papaja: Reproducible APA manuscripts with R Markdown](http://frederikaust.com/papaja_man/) (Frederik Aust & Marius Barth, 2021) 但我的理由是他們都還太複雜了一些,而且中文寫作上很難調整到可以完全仰賴 R(就算可以,到時候跟別人交流還是得輸出成 PDF 或 Word...)。 我希望有可以簡單到直接開來就可以用,可以輸出成 pdf(寫輪眼就是一款主打放棄 pdf 的工具)或 word(畢竟還要輸出來修改)。所以我還是選擇用 R beamer,雖然捨棄了即時預覽的酷炫功能(無限月讀)。也還是使用基本的 R Markdown,連 CTex Doc 都捨棄,因為從一個極簡主義的角度來想:我其實只需要 Markdwon, LaTex, BibTex 這些功能,其他的都還是要後續修改。所以產生了下面兩種作法。 ## 2) R Markdown for **beamer slides** - You can follow only the basic R presentation way. Do not need any other pkg, but tinytex. - use LaTex pkg: `{ctex}` and `{xeCJK}` for Chinese fonts. - `\setCJKmainfont` can set Chinese font (in the xeCJK or your local computer? )you want, e.g. `DFKai-SB` (標楷體)。 - `mainfont`: you can use CJK fonts or English fonts. Cuz I prefer **Kai+Calibri** setting, so I choose `Calibri` as the main font. - `theme`: you can visit the Beamer theme gallery [here](https://deic-web.uab.cat/~iblanes/beamer_gallery/index.html) to select your favorite theme. - `output`: it is important to apply the `xelatex` engine that your Chinese words can be displayed. On the other hand, if you have another R pkg such as `binb` (binb: Binb is not Beamer)(see the doc [here](https://www.rdocumentation.org/packages/binb/versions/0.0.6)), then the `xelatex` engine will be set default. - `font`: Cuz the RBeamer is dependent on LaTex engine, so only <mark>8pt, 9pt, 10pt, 11pt, 12pt, 14pt, 17pt, 20pt</mark> are available sizes. The default font size is 11pt, but using Chinese fonts, I suggest 12pt is a better choice. - `\alert{}` can turn a string's color to red. (Note: `black` or `\textbf{}` can not be available in Chinese words).`<mark> </mark>` can <mark>mark some words.</mark> - Level 3 heading: (`###`) will be a block. see below:(---) - **YAML 如下(a retro ver.):**(還有很多可以加的,<mark>See: [The YAML Fieldguide](https://cran.r-project.org/web/packages/ymlthis/vignettes/yaml-fieldguide.html)</mark> ) ``` --- title: "Groenen & Andries Van Der Ark (2006) and **Stout (2002)**" # subtitle: 今天吃什麼? author: "JW tsai" date: \today output: beamer_presentation: latex_engine: xelatex CJKmainfont: DFKai-SB mainfont: Calibri fontsize: 12pt theme: Madrid # colortheme: default urlcolor: blue linkcolor: purple # bibliography: myref.bib # csl: apa.csl --- ``` - 大都會版本的 **YAML 如下(a metropolis ver.):** 用到了 [**binb: Binb is not Beamer**](https://www.rdocumentation.org/packages/binb/versions/0.0.6) pkg。 - 這個版本的配色真的潮很多(相比之下 beamer 那些主題用色充滿古早味)。雖然也是極簡路線,但很符合我的審美。 ``` --- title: "Groenen & Andries Van Der Ark (2006) and **Stout (2002)**" author: "JW" date: \today output: binb::metropolis: latex_engine: xelatex CJKmainfont: DFKai-SB #mainfont: Calibri fontsize: 12pt urlcolor: blue linkcolor: purple --- ``` - 關於**寫輪眼**,其實我還是很想走到這一步的。但是我目前還沒掌握訂製好(包括字型、字號大小、配色、布局等等)的作法。等我確實掌握之後再追加上來。 ## 3) R Markdown for **academic writing** - 不用下載 `rticle`,不用受限於 `Ctex Doc` template 的設定,直接開一個 R Markdown 貼上 yaml 就可以跑。 - 匯出 .pdf 或 .docx 都可以。PDF 版才有完整格式,WORD 版只適合作後續修改的功能。 - 工作流程:<mark>用 R Markdown 寫第一稿,匯出成 MS Word 再進行修改。</mark>(考量到社會科學裡面還是用 MS Word 交流、投稿佔多數。) - `.bib` 檔操作: 1) 在 `.Rmd` 檔的同個資料夾裡面,開一個 `.bib` 的文字檔。(全程都可以在 Rstudio 完成。) 2) 在 Google Scholar 搜尋到文獻之後,點選 `Cite`,再選擇 `BibTex`,整段複製下來貼到 `.bib` 檔裡面就可以引用了! 3) `[@tsai2020]`/`[@chua2020, @tsai2020]`(有框)會顯示為 <mark>(Tsai, 2020)</mark>/ <mark>(Chua, 2020; Tsai, 2020)</mark>(句末引用),而 `@tsai2020`(無框)會顯示為 <mark>Tsai (2020)</mark> (句中引用)。 4) 完成初稿之後,再做細部調整(尤其中文部分)。 - [`apa.csl`](https://github.com/citation-style-language/styles/blob/master/apa.csl) 是 APA 7/e,英文部分應該可以信賴?但可能還是要注意「第一次要引用全部作者」的部分。 - 如果在意 `apa.csl` 的 doi 部分的話,可以換成 `apa-old-doi-prefix.csl`。 - **YAML 如下:** ``` --- title: "在 R Markdown 文件中使用中文" author: date: \today abstract: "My abstract" keywords: "My keywords" geometry: margin=1in papersize: a4 fontsize: 12pt indent: true linestretch: 1.5 output: pdf_document: latex_engine: xelatex fig_caption: yes number_sections: yes df_print: kable word_document: CJKmainfont: DFKai-SB mainfont: Calibri bibliography: myref.bib csl: apa.csl #apa-old-doi-prefix.csl --- ``` 初稿的參考架構如下(R markdown): ``` # Questions # Lit review # Niche (Theoritical model) # Design (Stats model) # Data # Data analysis # Answers # Defence (AD) # Reco & lim \newpage # Ref ``` - 其中,從提出問題(Questions)開始到找尋既有的先行研究(Lit review)這都沒問題。Niche 就是本研究(current study)提出的待驗證解決方案或切入理論,是過往研究裡面沒有的創新突破的作法。到這邊是一般 Intro 的部分。 - 接著是 Method,把原本的構想化為研究設計,進行資料搜集與分析。 - Answers = Results,結果的報表跟解讀,回答一開始提出的問題。 - Defence = Discussion,回顧整個研究並提出辯護。 - Reco and lim 建議與限制。 - `\newpage # Ref` 這是開新的一頁來放 Ref 的內容。自動生成。 --- ## 4) Reflection<- 引用一段 Xie 在 [xaringan Presentations](https://bookdown.org/yihui/rmarkdown/xaringan.html) 指導手冊裡面的話: > The main reason I stopped using LateX Beamer slides was because of its popularity: when you attend academic conference, you see Beamer slides everywhere. --- Xie 但我覺得在人文社會科學裡面,比較少有這種情況。(除了少數計量/計算領域的簡報會出現 beamer 風格以外,絕大部分都是 PPT 吧)。 ---

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully