Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silent type_convert

Tags:

r

readr

Is there a way to use the type_convert function from the readr package without it telling you what column specification it's using in the console.

From the example in the ? help documentation:

> df <- data.frame(
+     x = as.character(runif(10)),
+     y = as.character(sample(10)),
+     stringsAsFactors = FALSE
+ )
> str(type_convert(df))
Parsed with column specification:
cols(
  x = col_double(),
  y = col_integer()
)
'data.frame':   10 obs. of  2 variables:
 $ x: num  0.10262 0.15581 0.00638 0.6815 0.98654 ...
 $ y: int  9 5 8 10 4 6 1 2 3 7

I would want the the Parsed with column specification part gone so it looks like:

> df <- data.frame(
+     x = as.character(runif(10)),
+     y = as.character(sample(10)),
+     stringsAsFactors = FALSE
+ )
> str(type_convert(df))
'data.frame':   10 obs. of  2 variables:
 $ x: num  0.10262 0.15581 0.00638 0.6815 0.98654 ...
 $ y: int  9 5 8 10 4 6 1 2 3 7
like image 394
Marijn Stevering Avatar asked Oct 23 '25 19:10

Marijn Stevering


1 Answers

Wrap the type_convert call with suppressMessages:

str(suppressMessages(type_convert(df)))

For an in-depth discussion see read_excel read in messages- Supress?

like image 86
Holger Brandl Avatar answered Oct 26 '25 09:10

Holger Brandl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!