萬一別人尋找這個問題...
另一種方式讓所有的源代碼使用RStudio是使用File/Compile Notebook
選擇一個好看的格式在Word文檔中,選擇MS Word作爲輸出格式。
使用此選項,將生成一個.docx
文檔,其中包含腳本的輸出以及原始源代碼。雖然,腳本將被執行。
如果你不想讓你的代碼被評估(你只需要一個簡單的複製粘貼),你可以在腳本的開頭添加#+eval=FALSE
,然後源代碼將被複制到Word文檔中評估。
該方法依賴於knitr。這是一個例子,如果有人想開始玩這個。
#' ---
#' title: "My homework"
#' author: John Doe
#' date: June 15, 2015
#' output: word_document
#' ---
# The header above sets some metadata used in the knitr output
# Conventional comments are formatted as regular comments
# Comments starting with "#+" control different knitr options.
#+echo=FALSE,message=FALSE,warning=FALSE
library(ggplot2)
#+echo=TRUE
#' Comments with a "+" sign are used to tell knitr what should be
#' done with the chunk of code:
#'
#' - echo: Show the original code or not
#' - eval: Run the original code or not
#' - message: Print messages
#' - warning: Print warnings
#' - error: Print errors
#' ...
#' Comments with an apostrophe "'" will be printed as regular text.
#' This is very useful to explain what you are actually doing!
# Regular comments can be used to document the code as usual
# Figures are printed:
ggplot(mpg, aes(x=cty, y=hwy)) + geom_point(aes(color=class))
#' Formatting **options** are possible.
#' Even [links](http://stackoverflow.com/questions/10128702/how-to-preserve-formatting-from-rstudio-when-copy-pasting-to-word)
#'
#' This will show all the packages and versions used to generate this document.
#' It can be used to make sure that your teacher has all he needs to run your script
#' if he/she wants to.
sessionInfo()
StackOverflow用於編程問題。複製和粘貼不是編程,所以你的問題是非常關鍵的。 – 2012-04-12 17:44:56
喬蘭,喬希,對不起,我在這裏脫離了話題...仍然習慣了我的環境。是的,我意識到這是一種瘋狂,但這正是她想要的。 如果普遍的共識是OT,我會立即刪除。 – dubhousing 2012-04-12 17:50:20
我們應該少一點教條。我認爲對於開始這項業務的人來說,這很接近編程。 – 2012-04-12 18:14:21