禁止读者解析R中的问题 [英] Suppress reader parse problems in r

查看:136
本文介绍了禁止读者解析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:

  1. 消息suppressMessages(YOUR_FUNCTION)
  2. 警告suppressWarnings(YOUR_FUNCTION)
  3. 程序包启动消息suppressPackageStartupMessages(YOUR_FUNCTION)
  1. messages suppressMessages(YOUR_FUNCTION)
  2. warnings suppressWarnings(YOUR_FUNCTION)
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆