Suppress reader parsing problems in r

I am currently reading a file using the readr package. The idea is to use read_delim to read in a row for a row to find the maximum columns in my unstructured data file. The code displays parsing problems. I know about this and will deal with the type of column after import. Is there a way to disable problems() since regular options(warn) doesn't work

 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 console output that I am trying to suppress is as follows:

 .See problems(...) for more details. Warning: 11 parsing failures. row col expected actual 1 1####4 valid date 1###8 
+7
r readr
source share
1 answer

In R, you can suppress three main annoying things when using packages:

  • messages suppressMessages(YOUR_FUNCTION)
  • suppressWarnings(YOUR_FUNCTION) warnings suppressWarnings(YOUR_FUNCTION)
  • suppressPackageStartupMessages(YOUR_FUNCTION) start messages

So, in your case, imho also allows the package developer to know so that he / she can, for example, add the verbose argument to the function.

+13
source share

All Articles