簡體   English   中英

使用 rmarkdown::render() 將 R 腳本呈現為 pdf 文檔時如何抑制頁碼

[英]How to supress page numbers when rendering a R script into a pdf document using rmarkdown::render()

在我的團隊中,我們正在利用RMarkdown的潛力從腳本的評論中生成不同 R 腳本的文檔(參見此處的教程)。 雖然一切正常,但我們無法從我們生成的 pdf 文檔中抑制頁碼。

在 web for R markdown 文檔周圍找到的解決方案似乎都不適用於此特定方法。 他們要么拋出錯誤(例如Error in yaml::yaml.load(..., eval.expr = TRUE): Scanner error: mapping values are not allowed in this context at line xx, column yy )或者不改變output 隨便。

我們正在尋找一種方法來抑制實際使用此特定方法生成文檔的頁碼,或者尋找一種保留.tex文件以便我們自己進行修改的方法。 歡迎並非常感謝所有方法(如果我們真的錯過了古老社區帖子中的解決方案,我們會提前道歉)。

下面我為您提供了一個可重現的示例(請注意有關最后一步的信息以避免錯誤):

#' ---
#' title: "Dummy procedure to test R script rendering with Rmarkdown"
#' author: "Jean Doe"
#' date: "June 6, 2225"
#' output: pdf_document
#' ---
#'
#'
#' This is a dummy procedure to test the possibility of documenting scripts from comments.  
#' In order to do so, I'm going to provide a few R commands, then render it with `rmarkdown::render` function. Let's begin:
#'
#'
#'First I create my variables:
#+ setvar_chunk, eval = FALSE 
#variables
x <- seq(1,10,2)
y <- x^2

#'Then I have a data.frame
#+ df_chunk, eval = FALSE 
#data.frame
df <- data.frame(x,y)

#'Then I plot it but the plot is not going to appear in the *rmarkdown document* because i'm interesting in documenting my code not in creating a report. However, when I run my code, it actually does the job and plots y against x 
#+ plot_chunk, eval = FALSE 
#Plotting
plot (df)

#' My last step is to generate the documentation so when I change something I know that by just being descriptive and thorough in my comments I can actually generate my documentation at the same time I run my script. I can also "comment" this last part so i'm not constantly generating documentation when the script is meant to be run again and again.  
#' 
#' 
#' To avoid *errors* you need to save the script in your HDD, then substitute "FileToPath/File.R" with your path and file name
#+ eval = FALSE  
rmarkdown::render(input = "FileToPath/File.R", 
                  output_format = c("pdf_document"))

通過以下方式直接在您的序言中傳遞\pagenumbering{gobble} (指示不應打印數字的底層/過渡.tex文件):

---
#' title: "Dummy procedure to test R script rendering with Rmarkdown"
#' author: "Jean Doe"
#' date: "June 6, 2225"
#' output: pdf_document
#' header-includes:
#'    - \pagenumbering{gobble}
---

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM