Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的警告功能_R - Fatal编程技术网

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

我在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_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"