Skip to content

distinguishing input objects for a function

2 messages · ishi soichi, Duncan Murdoch

#
On 12-10-03 1:59 AM, ishi soichi wrote:
I don't understand the question.  You've passed the vector 1:3 as the 
num argument (by position).   Do you want to prevent someone from 
passing an array?
I don't understand what you want to achieve.
In most functions, R allows any type of argument in any position.  If 
your function only works for one type, usually an error will follow, but 
you can add your own tests for better error messages.  For example,

stopifnot(is.numeric(num))

will trigger an error if num is a non-numeric object.  See also stop() 
for an unconditional error (presumably controlled by an if()).

Duncan Murdoch