R: format the output of `warning()` for a list of options over more than one line

I'm writing error handling steps for an R function that fails to find the right match to a query, so presents users with a list of options. I have the output of potential matches in a list, and I'd like the warning to format this as a numbered list:

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

Unfortunately, warning and message seem to like removing linebreaks. For instance, if I have:

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

The command

warning(opts)

prints:

Warning message:
Tom BombadilTom OverhillJustanother Tom 

How do I get this into the format I'd like from above (ideally with numbers so I can capture the number choice from readLines)

Thanks!

Answers


What about this:

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"

Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.