禁止读者解析R中的问题 [英] Suppress reader parse problems in r
问题描述
我当前正在使用包readr
读取文件.这个想法是使用read_delim
逐行读取以在我的非结构化数据文件中找到最大的列.该代码输出存在parsing
问题.我知道这些,并且将在导入后处理列类型.有没有办法关闭problems()
,因为通常options(warn)
无法正常工作
I am currently reading in a file using the package readr
. The idea is to use read_delim
to read in row for row to find the maximum columns in my unstructured data file. The code outputs that there are parsing
problems. I know of these and will deal with column type after import. Is there a way to turn off the problems()
as the usual options(warn)
is not working
i=1
max_col <- 0
options(warn = -1)
while(i != "stop")
{
n_col<- ncol(read_delim("file.txt", n_max = 1, skip = i, delim="\t"))
if(n_col > max_col) {
max_col <- n_col
print(max_col)
}
i <- i+1
if(n_col==0) i<-"stop"
}
options(warn = 0)
我要抑制的控制台输出如下:
The output to console that I am trying to suppress is the following:
.See problems(...) for more details.
Warning: 11 parsing failures.
row col expected actual
1 1####4 valid date 1###8
推荐答案
在R中,使用软件包时,您可以抑制三大烦人的事情:
In R you can suppress three main annoying things while using packages:
- 消息
suppressMessages(YOUR_FUNCTION)
- 警告
suppressWarnings(YOUR_FUNCTION)
- 程序包启动消息
suppressPackageStartupMessages(YOUR_FUNCTION)
- messages
suppressMessages(YOUR_FUNCTION)
- warnings
suppressWarnings(YOUR_FUNCTION)
- package startup messages
suppressPackageStartupMessages(YOUR_FUNCTION)
因此,在您的情况下,恕我直言还让软件包开发人员知道,以便他/她可以在函数中添加verbose
自变量.
So in your case imho also let the package developer knows so that he/she can for example add a verbose
argument in the function.
这篇关于禁止读者解析R中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!