当前位置: 动力学知识库 > 问答 > 编程问答 >

r - Creating a function with one argument of class string that includes a comma

问题描述:

Is there any way of writing a function that takes only one argument of class string which includes commas and prints it? Something like follows:

function(i am dumb, very dumb)

>"i am dumb, very dumb"

I have tried in many different ways, however every time the comma appears R treats it as a separate argument. Is there any way of getting around this?

Thank you

网友答案:

Hopefully, I am understanding correctly

t = function(...){
    input = list(...)
    strs = unlist(as.character(input))
    ans =  paste(
        as.character(strs),
        collapse = ", "
    )    
    return(ans)
}

t('i am dumb','very dumb')
#[1] "i am dumb, very dumb"
分享给朋友:
您可能感兴趣的文章:
随机阅读: