简体   繁体   中英

Typing function arguments in R?

I wrote the following snippet of code:

b=function(x=numeric()){print(x)}

What does x=numeric() do?

b('i') and b(3) both produce the correct output.

Thanks!

You are specifying a default argument of numeric() , which I believe is just a numeric vector.

Thus, if you call the function with no arguments, that parameter will default to numeric() .

If your question is about how to force arguments to be a particular type (as your title implies), then you want to look at this question .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM