我正在分析一些数据,并想在R上做一个Simpsons悖论。我已经安装了 Simpsons 程序包并加载了库。这是一个基于包装文档的示例:
---
output: html_document
---
```{r}
library(Simpsons)
#generating data
Coffee1=rnorm(100,100,15)
Neuroticism1=(Coffee1*.8)+rnorm(100,15,8)
g1=cbind(Coffee1, Neuroticism1)
Coffee2=rnorm(100,170,15)
Neuroticism2=(300-(Coffee2*.8)+rnorm(100,15,8))
g2=cbind(Coffee2, Neuroticism2)
Coffee3=rnorm(100,140,15)
Neuroticism3=(200-(Coffee3*.8)+rnorm(100,15,8))
g3=cbind(Coffee3, Neuroticism3)
data2=data.frame(rbind(g1,g2,g3))
colnames(data2) <- c("Coffee","Neuroticism")
example <- Simpsons(Coffee,Neuroticism,data=data2)
plot(example)
```
这将返回一个包含3个簇的图(正是我所需要的)。但是,当我将Rmd文件编织为HTML时,会得到很多等号(======)
,其旁边有一个百分比,就像一个加载网格,我想从最终输出中删除它。
答案 0 :(得分:1)
您可以通过设置knitr chunk选项抑制R中的任何输出消息。如果我们希望隐藏除绘图以外的所有代码输出,可以使用following solution:
<h:form id="EmpWarrant_listForm">
<p:remoteCommand name="resetInputs" >
<p:resetInput target="EmpWarrant_editForm" />
</p:remoteCommand>
<p:panel header="#{bundle.EmpWarrant}">
<p:dataTable id="EmpWarrant_listForm_dataTable" value="#{empWarrantController.empWarrantList}" var="item"
selectionMode="single" selection="#{empWarrantController.selectedEmpWarrant}"
paginator="true" paginatorAlwaysVisible="false" paginatorPosition="bottom" rowKey="#{item.id}" rows="10" rowsPerPageTemplate="10,20,30,40,50">
<p:ajax event="rowSelect" update=":EmpWarrant_editForm EmpWarrant_listForm_btnsPanel" oncomplete="resetInputs()"/>
<p:ajax event="rowUnselect" update=":EmpWarrant_editForm EmpWarrant_listForm_btnsPanel" oncomplete="resetInputs()"/>
<p:column headerText="#{bundle.number}">
<h:outputText value="#{item.number}"/>
</p:column>
<p:column headerText="#{bundle.description}">
<h:outputText value="#{item.description}"/>
</p:column>
<p:column headerText="#{bundle.warrantDate}">
<h:outputText converter="JalaliDateConverter" value="#{item.warrantDate}"/>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
<h:form id="EmpWarrant_editForm">
<h:panelGroup id="EmpWarrant_editForm_display"
rendered="#{empWarrantController.selectedEmpWarrant != null}">
<div class="ui-g">
<div class="ui-g-12 ui-md-6 ui-lg-4">
<p:outputLabel
styleClass="#{!empWarrantController.empWarrantEditable} ? 'template-labels' : 'template-labels-dis'}"
value="#{bundle.number}" for="@next"/>
<p:inputText id="EmpWarrant_editForm_number"
value="#{empWarrantController.selectedEmpWarrant.number}" title="#{bundle.number}"
styleClass="#{!empWarrantController.empWarrantEditable ? 'text-disabled' : null} inputTxt-template template-fields"
disabled="#{!empWarrantController.empWarrantEditable}"/>
</div>
<div class="ui-g-12 ui-md-6 ui-lg-4">
<p:outputLabel
styleClass="#{!empWarrantController.empWarrantEditable} ? 'template-labels' : 'template-labels-dis'}"
value="#{bundle.description}" for="@next"/>
<p:inputText id="EmpWarrant_editForm_description"
value="#{empWarrantController.selectedEmpWarrant.description}"
title="#{bundle.description}"
styleClass="#{!empWarrantController.empWarrantEditable ? 'text-disabled' : null} inputTxt-template template-fields"
disabled="#{!empWarrantController.empWarrantEditable}"/>
</div>
</div>
<p:commandButton id="EmpWarrant_editForm_save"
actionListener="#{empWarrantController.save}"
value="#{bundle.Save}" update="EmpWarrant_editForm :EmpWarrant_listForm:EmpWarrant_listForm_dataTable"/>
<p:commandButton actionListener="#{empWarrantController.cancel}"
immediate="true"
value="#{bundle.Cancel}"
update="EmpWarrant_editForm :EmpWarrant_listForm:EmpWarrant_listForm_dataTable">
<p:resetInput target="EmpWarrant_editForm"/>
</p:commandButton>
</h:panelGroup>
</h:form>
我会注意到,这个软件包似乎比大多数软件包打印出更多的内容,因此选项的组合相当长。
一种更简单的方法可能是将图移到单独的块中,并在其之前运行所有分析。 extension UIViewController {
func add(_ child: UIViewController) {
addChild(child)
view.addSubview(child.view)
child.didMove(toParent: self)
}
func remove() {
guard parent != nil else {
return
}
willMove(toParent: nil)
removeFromParent()
view.removeFromSuperview()
}
}
参数可用于抑制所有输出,但这包括绘图,因此为什么必须使用两个块:
---
output: html_document
---
```{r echo=FALSE, results='hide', fig.keep='all', message = FALSE}
library(Simpsons)
#generating data
Coffee1=rnorm(100,100,15)
Neuroticism1=(Coffee1*.8)+rnorm(100,15,8)
g1=cbind(Coffee1, Neuroticism1)
Coffee2=rnorm(100,170,15)
Neuroticism2=(300-(Coffee2*.8)+rnorm(100,15,8))
g2=cbind(Coffee2, Neuroticism2)
Coffee3=rnorm(100,140,15)
Neuroticism3=(200-(Coffee3*.8)+rnorm(100,15,8))
g3=cbind(Coffee3, Neuroticism3)
data2=data.frame(rbind(g1,g2,g3))
colnames(data2) <- c("Coffee","Neuroticism")
example <- Simpsons(Coffee,Neuroticism,data=data2)
plot(example)
```
查看编织块options here的完整列表