3

我正在为无法找到与查询的正确匹配项的 R 函数编写错误处理步骤,因此为用户提供了选项列表。我在列表中有潜在匹配的输出,我希望警告将其格式化为编号列表:

'multiple matches for query "Tom", select which one you want:'
 [1] Tom Bombadil
 [2] Tom Overhill
 [3] Justanother Tom

不幸的是,警告和消息似乎喜欢删除换行符。例如,如果我有:

opts <- list("Tom Bombadil", "Tom Overhill", "Justanother Tom")

命令

warning(opts)

印刷:

Warning message:
Tom BombadilTom OverhillJustanother Tom 

我如何从上面把它变成我想要的格式(最好用数字,这样我就可以从中捕获数字选择readLines

谢谢!

4

1 回答 1

6

那这个呢:

select.list(c("Tom Bombadil", "Tom Overhill", "Justanother Tom"),
              title = "Multiple matches for query \"Tom\", 
                       select which one you want:")
Multiple matches for query "Tom", select which one you want: 

1: Tom Bombadil
2: Tom Overhill
3: Justanother Tom

Selection: 2
[1] "Tom Overhill"
于 2012-09-09T23:50:08.690 回答