万一别人寻找这个问题...
另一种方式让所有的源代码使用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