R中的警告功能
我在R中有一个字符列表。我正在执行以下查询:R中的警告功能,r,R,我在R中有一个字符列表。我正在执行以下查询: > a <- c("sepal_length" ,"sepal_width", "petal_length" ,"petal_width" , "species") > a [1] "sepal_length" "sepal_width" "petal_length" "petal_width" [5] "species" > warning(a) Warning message: sepal_lengthse
> a <- c("sepal_length" ,"sepal_width", "petal_length" ,"petal_width" , "species")
> a
[1] "sepal_length" "sepal_width" "petal_length" "petal_width"
[5] "species"
> warning(a)
Warning message:
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
使用粘贴:
warning(paste0('"', paste(a, collapse = '" "'), '"'))
Warning message:
"sepal_length" "sepal_width" "petal_length" "petal_width" "species"
或者按照建议,使用
dQuote
。这使用了花哨的引号,中间没有空格:
warning(dQuote(a))
Warning message:
“sepal_length”“sepal_width”“petal_length”“petal_width”“species”
下面是一个使用
sprintf()
的解决方案:
a你在写奇怪的警告信息……哈哈。。实际上,整个警告信息是这样的。警告:列名改为“萼片长度”“萼片宽度”“花瓣长度”“花瓣宽度”“物种”。这是一个花哨的引语,但我不确定它在警告消息中是否重要
warning(dQuote(a))
Warning message:
“sepal_length”“sepal_width”“petal_length”“petal_width”“species”
a <- c("sepal_length" ,"sepal_width", "petal_length" ,"petal_width" , "species")
warning(sprintf('"%s" ', a))
# Warning message:
# "sepal_length" "sepal_width" "petal_length" "petal_width" "species"