我正在尝试按照此pandoc示例将多个作者添加到yaml元数据块中的Rmarkdown文件.pdf将在RStudio(版本0.98.932)中生成,但没有作者信息.
---
title: 'This is the title: it contains a colon'
author:
- name: Author One
affiliation: University of Somewhere
- name: Author Two
affiliation: University of Nowhere
date: "`r format(Sys.time(), '%d %B %Y')`"
tags: [nothing, nothingness]
abstract: |
This is the abstract.
It consists of two paragraphs.
output: pdf_document
---
Run Code Online (Sandbox Code Playgroud)
我还想更多地定制标题并添加一个副标题.可能?
在下面的最小示例中,我尝试vars在回归公式中使用字符串的值.但是,我只能将变量名称字符串("v2 + v3 + v4")传递给公式,而不是该字符串的实际含义(例如,"v2"是dat $ v2).
我知道有更好的方法来运行回归(例如lm(v1 ~ v2 + v3 + v4, data=dat)).我的情况更复杂,我想弄清楚如何在公式中使用字符串.有什么想法吗?
更新以下代码
# minimal example
# create data frame
v1 <- rnorm(10)
v2 <- sample(c(0,1), 10, replace=TRUE)
v3 <- rnorm(10)
v4 <- rnorm(10)
dat <- cbind(v1, v2, v3, v4)
dat <- as.data.frame(dat)
# create objects of column names
c.2 <- colnames(dat)[2]
c.3 <- colnames(dat)[3]
c.4 <- colnames(dat)[4]
# shortcut to get to the type of object my full code produces
vars <- …Run Code Online (Sandbox Code Playgroud) 我正在使用带有R Markdown和knitr的xtable来生成我用\ input {}调用的.tex文件.效果很好,但我还没有弄清楚如何创建像这里显示的多列.有谁知道怎么做到这个?
到目前为止,我正在使用:
tbl <- xtable(data, align="l r r r r r")
colnames(tbl) <- c("Variable",
"Mean", "Std Dev",
"Mean", "Std Dev",
"Difference")
caption(tbl) <- c("Table Title")
print(tbl,
include.rownames=FALSE,
caption.placement="top",
booktabs=TRUE,
type="latex",
file="output.tex")
Run Code Online (Sandbox Code Playgroud)
我想在每个"Mean"和"Std Dev"("治疗"和"控制")上有一个不同的分组标题.
或者,是否有更好的方法使用R Markdown/knitr自动生成表格?我不想手动编辑表格,因为报告需要自动生成.
更新: @agstudy:我是乳胶新手,但我认为这是我希望用xtable(或类似xtable)自动生成的输出:
\begin{tabular}{lrrrrr}
\toprule
& \multicolumn{2}{c}{Treatment} & \multicolumn{2}{c}{Control} & \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5}
Variable & Mean & Std Dev & Mean & Std Dev & Difference \\
\midrule
var1 & 1 & 2 & 3 & 4 & 5 \\
\bottomrule …Run Code Online (Sandbox Code Playgroud) 我想在我的kable表中包装长文本.下面是一个表格的简单示例,其中列文本太长,需要为表格包装以适合页面.
---
title: "test"
output: pdf_document
---
```{r setup, include=FALSE}
library(knitr)
```
This is my test
```{r test, echo=FALSE}
test <- data.frame(v1=c("This is a long string. This is a long string. This is a long string. This is a long string. This is a long string.",
"This is a another long string. This is a another long string. This is a another long string. This is a another long string. This is a another long string."),
v2=c(1, 2))
kable(test)
```
Run Code Online (Sandbox Code Playgroud)

我想将数据框导出到Excel并根据特定规则突出显示单元格.我不认为对类似问题的答案是正确的.我认为这是可能的,我认为我接近使用包的CellStyle功能xlsx.
下面我概述了我尝试过的内容.大多数想法来自包帮助文件.当我尝试将我创建的样式应用于符合条件的单元格时,我会一路走到最后并得到错误.我收到错误:Error in .jcall(cell, "V", "setCellStyle", cellStyle$ref) : RcallMethod: invalid object parameter.
library(xlsx)
# create data
cols <- sample(c(1:5), 1) # number of columns to vary to mimic this unknown
label <- rep(paste0("label ", seq(from=1, to=10)))
mydata <- data.frame(label)
for (i in 1:cols) {
mydata[,i+1] <- sample(c(1:10), 10)
}
# exporting data.frame to excel is easy with xlsx package
sheetname <- "mysheet"
write.xlsx(mydata, "mydata.xlsx", sheetName=sheetname)
file <- "mydata.xlsx"
# but we want …Run Code Online (Sandbox Code Playgroud) 我正在尝试添加本地图像并将其调整为.RmdRStudio中的文件,该文件将生成pdf.我可以轻松添加文件

但我还没弄明白如何控制图像的大小.我尝试了带宽度属性的HTML代码,但图像不会出现(我认为只有在输出到HTML时才有效).
<img src="path/file.png" width="200px" />
我无法理解这个想法:

有没有办法修改Rmarkdown脚本来修改只有RMarkdown和基础R的本地图像的大小?
有一个建议使用png和grid包,但我的问题仅限于基础R. 但是,对于其他用户,我认为这看起来是一个很好的解决方案.
我昨天升级到了OSX Yosemite.当我运行library(xlsx)时RStudio,程序崩溃,我收到消息:"要打开'RStudio',您需要安装旧的Java SE 6运行时." 我得到有关打开相同的结果和消息R当我运行library(xlsx)在R.
这是我的详细信息:
Mac Yosemite, Version 10.10.2
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Run Code Online (Sandbox Code Playgroud)
我有Java版本8更新31.我运行java -version并收到此消息:"没有Java运行时,请求安装." 所以我安装了Java SE Development Kit 8u31.现在:
java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
Run Code Online (Sandbox Code Playgroud)
这没有做到这一点,因为运行library(xlsx)仍然会崩溃程序并发出警告.我是否需要以某种方式回滚到Java SE 6运行时,还是有办法使用我安装的最新版本?
这个SO帖子似乎是相关的,但我不清楚安装Java 6的安装解决方案.答案链接到似乎过时的苹果支持页面.
我不熟悉Java,所以我可以使用一些建议.
我正在使用RStudio,R Markdown,Latex和Pandoc来清理数据,构造变量,运行我的分析并报告结果.我对可重复研究的概念不熟悉,但我很迷恋.很有道理.
动态表格和数字都没有问题.然而,动态文本让我很难过.我可以插入内联代码来说95%的统计数据都是错误的,但我不确定如何以可重现的方式改变我的语言.
例如,如果我有一个对象x = 0.66并且我想写"3个牙医中的2个使用Crest"怎么办?我可以查看x,0.66的当前值,并在文本中键入"2 out of 3",但这是不可重现的.假设我得到新数据并重新运行我的分析,x变为0.52.我的文字已经过时了.当然,我可以动态地报告52%的牙医更喜欢Crest,但是当一切报告为百分比时,报告会变得陈旧.
我的想法是,当我想要改变写作时,我可以创建我可以在文本中调用的函数.例如,"out.of"函数可以用于if else语句来生成文本:
ifelse(x < 0.09,"fewer than 1 out of 10",
ifelse(x >= 0.09) & x < 0.11,"roughly 1 out of 10",
ifelse(x >= 0.11 & x < 0.15,"slightly more than 1 out of 10",
ifelse(x >= 0.15 & x < 0.19,"nearly 2 out of 5",
ifelse(x >= 0.19 & x < 0.21,"roughly 2 out of 5",
...
ifelse(x >= 0.95 & x < 0.99,"nearly all",
ifelse(x >= 0.99,"all","fubar"))...)
Run Code Online (Sandbox Code Playgroud)
我还可以创建一个分数函数,它可以做十分之一,五分之二,三分之一......
我相信其他人已经解决了这个问题.任何线索?想法?
我正在尝试使用伟大的新包bookdown来使用RStudio中的RMarkdown创建一本gitbook风格的书.看到这里.
我的问题是关于创建自定义块.文档中有一个示例如何在CSS文件中定义块样式:
div.FOO {
font-weight: bold;
color: red;
}
Run Code Online (Sandbox Code Playgroud)
作者给出了一些块可能看起来像的例子.
AFAIK,没有关于如何使用图标定义此特定块的示例.我不太了解CSS,所以寻找我可以修改的东西.
我想使用像Leanpub这样的字体真棒图标来创建一些特殊的侧边栏.创建这样的东西的任何想法:
我想我需要复制fontawesome目录,指定包含的fontawesome css文件的路径(在某处,不确定在哪里),并<i>在我的div定义中使用标记,例如<i class="fa fa-comment"></i>.关于如何实现这一点并不明确......或者它是否可行.
我有这样的字符串:
string <- "1, 2, \"something, else\""
Run Code Online (Sandbox Code Playgroud)
我想使用tidyr::separate_rows()with sep==",",但字符串引用部分内的逗号让我困惑。我想删除某些内容和其他内容之间的逗号(但只有这个逗号)。
这是一个更复杂的玩具示例:
string <- c("1, 2, \"something, else\"", "3, 5, \"more, more, more\"", "6, \"commas, are fun\", \"no, they are not\"")
string
#[1] "1, 2, \"something, else\""
#[2] "3, 5, \"more, more, more\""
#[3] "6, \"commas, are fun\", \"no, they are not\""
Run Code Online (Sandbox Code Playgroud)
我想去掉嵌入引号内的所有逗号。期望的输出:
[1] "1, 2, \"something else\""
[2] "3, 5, \"more more more\""
[3] "6, \"commas are fun\", \"no they are not\""
Run Code Online (Sandbox Code Playgroud)