这个简单,直接上P103例题
> mydate<- function(type= 'long') {
+ switch(type,
+ long= format(Sys.time(), "%A %B %d %Y"),
+ short= format(Sys.time(), "%m-%d-%y"),
+ cat(type, "is not a recognized type\n")
+ )
+ }
>
> mydate("long")
[1] "星期六 六月 26 2021"
> mydate("short")
[1] "06-26-21"
> mydate("今天是个好日子")
今天是个好日子 is not a recognized type