我的代码中有输出多条消息的函数,但我无法将这些消息放在同一个输出块中,就像results='hold'
.
到目前为止,唯一能模拟我想要的选项是选项collapse=T
,但这将输出和代码粘在一起,这是我不想要的。
这段代码说明了这种情况:
---
title: "Example"
author: "Me"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
a <- function(){
print("hello")
print("world")
message("hello again")
message("world")
}
```
### default
```{r}
a()
```
### with `results='hold'`
```{r results='hold'}
a()
```
### with `collapse=T`
```{r collapse=T}
a()
```
Run Code Online (Sandbox Code Playgroud)
我还认为有趣的是如何在结果/打印之前输出消息results='hold'
。
我在这个问题上花了足够长的时间,以至于我想我会写一篇关于它的帖子。
利用devtools
开发的R程序包是真是一绝。我用通常的命令生成了我的新包:
usethis::create_package(proj_path)
Run Code Online (Sandbox Code Playgroud)
然后我开始处理内容。编辑DESCRIPTION
文件,在R/
文件夹中添加 R 代码并使用 Roxygen 进行记录。
一旦我放下了一些基本的东西,我想通过记录/构建包来检查我的工作,所以我跑了
devtools::document(proj_path)
Run Code Online (Sandbox Code Playgroud)
并得到以下错误
read.dcf(path_desc) 中的错误:以“这对应于 ...”开头的行格式不正确!
就是这样,没有关于导致错误的原因的信息。
我从来没有在我的文档中写过任何接近“这对应于”的东西。我发现的最接近这个错误的是github 上的这个问题,它有相同类型的Error in read.dcf(
想法,但这对我的情况没有帮助。
我正在尝试修复一个令人讨厌的大型程序的代码(我没有创建它)而且我一直在着名IndexOutOfBoundsException
.
我想提一下,我知道这个错误意味着什么,因为我已经广泛搜索了答案,但我根本不明白为什么我会得到它,所以这里......
这是错误:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at edu.harvard.i2b2.crc.loader.dao.ObservationFactDAO$ObservationFactInsert.insert(ObservationFactDAO.java:359)
at edu.harvard.i2b2.crc.loader.dao.ObservationFactInsertHandle.insertObservationFact(ObservationFactInsertHandle.java:25)
at edu.harvard.i2b2.crc.loader.ejb.ObservationFactXmlDbLoader.process(ObservationFactXmlDbLoader.java:84)
at edu.harvard.i2b2.crc.loader.xml.TypePullParser.doParsing(TypePullParser.java:73)...
Run Code Online (Sandbox Code Playgroud)
以下是ObservationFactDAO.java导致问题的部分(由错误引用):
protected void insert(ObservationType observationType) {
Object[] objs = new Object[] {
observationType.getEventId().getValue(),
observationType.getEventId().getSource(),
observationType.getConceptCd().getValue(),
(observationType.getPatientId() != null) ? observationType
.getPatientId().getValue() : null,
(observationType.getPatientId() != null) ? observationType
.getPatientId().getSource() : null,
(observationType.getObserverCd() != null) ? observationType
.getObserverCd().getValue() : null,
(observationType.getStartDate() != null) ? observationType
.getStartDate().toGregorianCalendar().getTime()
: null,
(observationType.getModifierCd() != null) ? observationType
.getModifierCd().getValue() : null,
(observationType.getInstanceNum() …
Run Code Online (Sandbox Code Playgroud) 我试图在一个for
循环中经历2个相同长度的数组,但我得到了一个
ValueError:要解压缩的值太多
以下是生成错误的代码:
test = [1, 0, 5, 2, 6, 3, 4]
names = ['patient_map_id', 'birth_date', 'age_in_years_num',
'sex_cd', 'vital_status', 'event_map_id', 'start_date']
for col_num, name in (test, names) :
#do stuff
Run Code Online (Sandbox Code Playgroud)
如果我没有弄错的话,应该有办法做到这一点,但我不知道错误来自哪里