沉默 type_convert

Silent type_convert

有没有一种方法可以使用 readr 包中的 type_convert 函数而不告诉您它在控制台中使用的列规范。

来自 ? 帮助文档中的示例:

> 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

我希望 Parsed with column specification 部分消失,所以它看起来像:

> 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

suppressMessages 结束 type_convert 调用:

str(suppressMessages(type_convert(df)))

有关 in-depth 的讨论,请参阅