使用R中的cat删除最后一个向量元素中的逗号

使用R中的cat删除最后一个向量元素中的逗号,r,cat,R,Cat,我在R中面临一个小问题,但我不知道如何解决它 我想使用cat在R控制台中使用cat中的sep参数打印消息。 这就是我尝试过的: words <- c("foo", "foo2", "foo3") cat("words not included:", "\n", words, sep = ",") #words not included:, #,foo,foo2,foo3 我想要的结果是: #words not included: #foo,foo2,foo3 只需将粘贴与折叠一

我在R中面临一个小问题,但我不知道如何解决它

我想使用cat在R控制台中使用
cat
中的
sep
参数打印消息。 这就是我尝试过的:

words <- c("foo", "foo2", "foo3")
cat("words not included:", "\n", words, sep = ",")
#words not included:,
#,foo,foo2,foo3
我想要的结果是:

#words not included:
    #foo,foo2,foo3

只需将
粘贴
折叠
一起使用即可:

words <- c("foo", "foo2", "foo3")
cat(paste("words not included:", "\n", paste(words, collapse=",")))

words not included: 
 foo,foo2,foo3
words您可以使用
toString()
而不是
cat()
中的
sep
参数

words <- c("foo", "foo2", "foo3")
cat(paste("words not included:", "\n", paste(words, collapse=",")))

words not included: 
 foo,foo2,foo3
cat("words not included:", "\n", toString(words),  "\n")

words not included: 
 foo, foo2, foo3